Adam Oudad

Adam Oudad

(Machine) Learning log.

8 minutes read

If you set up a lottery game, and your game happens to have some flaws, it is a bad idea to let mathematicians participate. They would just ruin the game1!

But there is no superpower needed, it is just statistics. Moreover, with computing, we can simulate and understand better games involving randomness.

In this article, we will see if we can find some mathematician's hacks to a popular TV game requiring psychology and some calculations.

Simple rules, deep question

The Monty Hall problem is named after a TV show which started in 1984, hosted by Monty Hall. The rules of the game are the following.

You are presented to three doors. Only one door leads to a prize, thus winning the game, while the other two leads to nothing, thus losing the game. In the original version, the prize is a car, and the losing doors lead to a goat.

You are the participant and try to guess the winning door. There are three doors, so we can deduce that on our first choice, our chances of winning are 1/3.

But instead of revealing the door leading to the prize, and regardless of whether you guessed right or not, the presenter who knows what is behind each door, reveals one losing door, among the ones you did not choose, and asks you if you would like to change to the other remaining door, or to stick to your first choice, before finally revealing your outcome.

Should you stay faithful to your first guess, or should you decide to change for the other door?

Three doors, one prize

As we have seen above in its original formulation, the Monty Hall problem has three doors, or three available choices, for one prize. To test the two strategies of sticking to the first choice, and changing to the other door, I simulated them on a thousand trials, by writing the following program in Python language.

import random
random.seed(0) # This seed will reproduce the same results presented in this article.
trials = 1000
stick_strategy_wins = 0
change_strategy_wins = 0
WIN = 1
LOSE = 0
for _ in range(trials):
    doors = [WIN, LOSE, LOSE]
    random.shuffle(doors)
    # First choice by the participant
    first_choice = doors.pop(random.choice(doors))
    # Reveal a losing door
    doors.remove(LOSE)
    if first_choice == WIN:
        # Stick strategy wins
        stick_strategy_wins += 1
    else:
        # Remaining door is the winning one, so the change strategy wins.
        assert doors == [WIN]
        change_strategy_wins += 1

return f"{stick_strategy_wins=} ({stick_strategy_wins/trials:.2%}), {change_strategy_wins=} ({change_strategy_wins/trials:.2%}), for {trials=}"
stick_strategy_wins=333 (33.30%), change_strategy_wins=667 (66.70%), for trials=1000

From this quick simulation, it turns out the change strategy gives two times more chances for winning the prize! This is a counter-intuitive strategy has been shown to be psychologically more difficult to consider, although it clearly provides an edge in the game.

If we take a closer look at the win rates, we see that the stick strategy roughly wins a third of the trials, while the change strategy roughly takes the other two thirds. It is trivial to see that the probability of winning on our first choice, without further prior knowledge than "only one door leads to the prize" bestow a win rate of 1/3 upon us.

But here is the mind twist, if we were to have been able to choose the two other doors at once, we would have won 2/3 of the time, because it would have been equivalent to winning the rest of the time when we would have lost by sticking to our first choice. Due to the game's rules, it is not possible to chose such a set of two doors. But thanks to the revelation of the losing door after our first choice, choosing the other one equates to the same!

Four doors, one prize, two revelations

Now that we've wrapped our mind around the normal case, it is interesting to test the effectiveness of the change strategy in other conditions. So let's add one more door!

I have seen several contents available out there discussing the case of four doors, by defining the rules with the following.

  1. The participant chooses one door out of four doors.
  2. The presenter reveals two losing doors among the other doors.
  3. The participant is given the choice to stick to his first choice, or to switch to the other remaining door.

Switching, equates to choosing the set of three other doors we did not choose on our first choice, and taking advantage of the revelation of the two doors, this time. Due to this greater advantage, we get 3/4 win rate if we change to the other door, and 1/4 win rate if we stick to our first choice.

In my sense, this ruleset is not so interesting, as the optimal strategy remains identical and easy to guess given our knowledge from the game with three doors. Fortunately, another way to view the Monty Hall problem with four doors exist.

Four doors, one prize, … and only one revelation!

Here is the new set of rules.

  1. The participant chooses one door, out of four doors.
  2. The presenter reveals only one losing door, out of the three other doors.
  3. The participant is given the choice to stick to his first choice, or to switch to one of the two other remaining doors.

In this set of rules, the strategy of sticking to the first choice is 1/4, because it means ignoring the knowledge provided by the revelation of the two doors and randomly choosing one door among four. However, the change strategy becomes a random choice between two doors! So, is it still the optimal?

Let's define the following.

\(\mathcal{D}\)
the set of doors at the beginning of the game.
\(c_1\)
the first door chosen randomly in \(\mathcal{D}\).
\(t\)
the door with the prize.
\(r\)
the door revealed after \(c_{1}\), in \( \mathcal{D} \setminus \{c_{1}, t\} \). The revealed door is neither the door selected by the participant, nor the door with the prize.

With the Bayes theorem, we can calculate the win rate of the change strategy. \[ P(c_{2} = t) = P(c_{1} \neq t) \cdot P(c_{2} = t | c_{1} \neq t) + P(c_{1} = t) \cdot P(c_{2} = t | c_{1} = t) \] In this equation, we decomposed the probability of winning with the change strategy onto the conditional events of wining or losing with the other strategy, which is to stick to our first choice.

Wining by sticking to our first choice has probability \(P(c_{1} = t) = \frac{1}{4}\), while losing gives \(P(c_{1} \neq t) = \frac{3}{4}\). Knowing that we won with this first choice strategy, our probability of winning by changing our first choice is \(P(c_{2} = t | c_{1} = t) = 0\), because both strategies simply cannot win on the same game. Finally, if we knew that the first choice strategy was a losing strategy, we would just have to opt for the change strategy, and choose between two equally probable doors, that is the probability of winning \(P(c_{2} = t | c_{1} \neq t) = \frac{1}{2}\).

We can thus calculate our odds for winning with the change strategy, in the case of four doors and only one revelation. \[ P(c_{2} = t) = \frac{3}{4} \cdot \frac{1}{2} + \frac{1}{4} \cdot 0 = \frac{3}{8} \]

As expected, the edge provided by the change strategy here is thinner, but \(\frac{3}{8} > \frac{1}{4}\) means that would we still win more often with the change strategy!

Simulation

Let's, again, simulate it with a Python program.

import random
random.seed(0) # This seed will reproduce the same results presented in this article.
trials = 1000
stick_strategy_wins = 0
change_strategy_wins = 0
both_strategies_lose = 0
WIN = 1
LOSE = 0
for _ in range(trials):
    doors = [WIN, LOSE, LOSE, LOSE]
    random.shuffle(doors)
    # First choice by the contestant
    first_choice = doors.pop(random.choice(doors))
    # Reveal a losing door
    doors.remove(LOSE)
    if first_choice == WIN:
        # Stick strategy wins
        stick_strategy_wins += 1
    else:
        # Remaining door is the winning one, so the change strategy wins.
        second_choice = random.choice(doors)
        if second_choice == WIN:
            change_strategy_wins += 1
        else:
            both_strategies_lose += 1
                

return f"{stick_strategy_wins=} ({stick_strategy_wins/trials:.2%}), {change_strategy_wins=} ({change_strategy_wins/trials:.2%}), {both_strategies_lose=} ({both_strategies_lose/trials:.2%}), for {trials=}"
stick_strategy_wins=241 (24.10%), change_strategy_wins=384 (38.40%), both_strategies_lose=375 (37.50%), for trials=1000

The stick strategy obtains \(24.10\%\) of win rate, which is roughly a quarter of the trials. The change strategy obtains \(38.40\%\), which is a win rate of roughly \(\frac{3}{8}\) of all the trials. This corroborates our findings! :)

Conclusion

As you reach the conclusion of this article, you may want to know the win rate in case for any number of doors, when just one door is revealed. Let's call \(n\) the number of doors. The first choice strategy will give a win rate of \(\frac{1}{n}\), while the change strategy will give us a win rate of \(\frac{n-1}{n(n-2)}\). Do you agree?

Because \(\frac{n-1}{n-2} \gt 1\), we still verify the optimality of the change strategy.

From a simple set of rules, we saw how hard it is to derive an optimal strategy from just intuition, so let's not be fooled by the apparent simplicity of problems and games!

But what if we were given some prior knowledge on the probability of each door leading to the prize? Maybe for another time… or read2 if you are in a hurry! ;)

Footnotes

comments powered by Disqus

Recent posts

See more

Categories

About

This website is a weblog were I write about computer science, machine learning, language learning.