Created
May 22, 2024 21:13
-
-
Save hughdbrown/0d63bf1cb23b256169e4ab97f06b7819 to your computer and use it in GitHub Desktop.
Why the solution given by the FDP Institute for the first question in the 2023 exam is incorrect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# This is a simulation of the results for the first problem given here: | |
# https://fdpinstitute.org/resources/FDP%203.0/2024-Q2/Limited%20Sample%20MC%20Questions%20Q2-2024.pdf | |
# | |
# The expected answer given by the FDP Institute is 0.84. This is incorrect, as this simulation shows. | |
# The problem is that FDP has used the Bayesian formula incorrectly. Instead of using a weighted average | |
# of outcomes as the prior probability, FDP uses only the P(potted|~Simon) as the prior. | |
from collections import Counter | |
from random import random | |
# which table depends on a random variable exceeding this threshold | |
TABLE_THRESHOLD = (1 - 0.75) | |
# table[0] is the usual table, table[1] is Simon's table | |
SHOT_THRESHOLDS = (1 - 0.80, 1 - 0.90) | |
SIMON, NOT_SIMON = (1, 0) | |
POTTED, NOT_POTTED = (1, 0) | |
def main(reps=1000*1000): | |
results = Counter() | |
for _ in range(reps): | |
table = random() | |
shot = random() | |
which_table = int(table > TABLE_THRESHOLD) | |
# Whether the shot is "potted" or not depends on | |
# random value and which table it is done on. | |
potted = int(shot > SHOT_THRESHOLDS[which_table]) | |
key = (which_table, potted) | |
results[key] += 1 | |
print(f"table = SIMON, shot = POTTED: {results[(SIMON, POTTED)] / float(reps): .3f}") | |
print(f"table = SIMON, shot = NOT_POTTED: {results[(SIMON, NOT_POTTED)] / float(reps): .3f}") | |
print(f"table = NOT_SIMON, shot = POTTED: {results[(NOT_SIMON, POTTED)] / float(reps): .3f}") | |
print(f"table = NOT_SIMON, shot = NOT_POTTED: {results[(NOT_SIMON, NOT_POTTED)] / float(reps): .3f}") | |
simon_and_potted = results[(SIMON, POTTED)] | |
all_potted_shots = results[(SIMON, POTTED)] + results[(NOT_SIMON, POTTED)] | |
print(f"\nProbability table was Simon's given shot was potted: {simon_and_potted / all_potted_shots: .3f}") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment