Probability Problems and Simulation

There are a number of classic probability problems that challenge the intuition, both for students and for teachers. I have found that one way to overcome this intuition block is to write a quick simulation. A good example is the classic evil probability problem of the Monty Hall. The derivation of the solution is straightforward, but it is easy to convince yourself of the wrong answer. A quick simulation, like the one below, makes it clear: 1/3 of the time the host gets a choice with which door to open, and 2/3 of the time the host has no choice – with the other door having the prize. I find a numerical simulation helps to bolster my confidence in a mathematical analysis, especially when it is particularly unintuitive.

from random import randint
import random
turn=0
win=0
human=False

while turn<50:

prize=randint(1,3)
door_choices=[1,2,3]

if human:
your_first_answer=input('Which door %s? ' % str(door_choices))
else: # automatic
your_first_answer=random.choice(door_choices)

if prize==your_first_answer: # happens 1/3 of the time
door_choices.remove(your_first_answer) # get the other two
door_choices=sorted([your_first_answer,
random.choice(door_choices)])
else:
door_choices=sorted([prize,your_first_answer])

if human:
your_second_answer=input('Which door %s? ' % str(door_choices))
else: # automatic

# always switch
if door_choices[0]==your_first_answer:
your_second_answer=door_choices[1]
else:
your_second_answer=door_choices[0]

if your_second_answer==prize:
print "You win!"
win+=1
else:
print "You Lose!"

turn+=1


print "Winning percentage: ",float(win)/turn*100
Advertisements

About brianblais

I am a professor of Science and Technology at Bryant University in Smithfield, RI, and a research professor in the Institute for Brain and Neural Systems, Brown University. My research is in computational neuroscience and statistics. I teach physics, meteorology, astonomy, theoretical neuroscience, systems dynamics, artificial intelligence and robotics. My book, "Theory of Cortical Plasticity" (World Scientific, 2004), details a theory of learning and memory in the cortex, and presents the consequences and predictions of the theory. I am an avid python enthusiast, and a Bayesian (a la E. T. Jaynes), and love music.
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Probability Problems and Simulation

  1. Jeff J says:

    A twist on this problem, that I have never seen used to demonstrate your correct answer, is to use 3 wallets instead of 3 doors. Each has a different amount of cash in it, but each is worth something. (As opposed to the classic problem, where two doors are essentially worthless.)

    If we assume that, of the two wallets you didn't pick, Monty Hall always reveals what is in the wallet with the least amount of cash, then it becomes more intuitive that switching wallets will make your prize go up in value in two of the three possibilities. And further, that going up always means getting the largest prize. From there, it is easy to see that the same applies with the cars and goats.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s