Solving the two envelopes problem with python and petersburg

In a couple of previous posts (here, here, and here) we’ve explored how petersburg represents uncertain decisions as a directed acyclic graph with weighted random decisions for which edge to take out of a given node.  It turns out this is very similar to Bayesian networks, which will be the subject of post in the coming weeks, but for today, we are going to examine a classical decision theory problem with petersburg and it’s primary object: the directed acyclic graph (DAG).

The Two Envelopes Problem

The two envelopes problem (or exchange paradox) is a classical problem in decision theory.  It goes:

Of two indistinguishable envelopes, each containing money, one contains twice as much as the other.The subject may pick one envelope and keep the money it contains.Having chosen an envelope at will, but before inspecting it, the subject gets the chance to take the other envelope instead.What is the optimal rational strategy for maximizing the amount of money to be gained?

This seems like a trivial problem, but it’s called a paradox for a reason.  A common line of reasoning, via wikipedia in this case, is:

  1. I denote by A the amount in my selected envelope.
  2. The probability that A is the smaller amount is 1/2, and that it is the larger amount is also 1/2.
  3. The other envelope may contain either 2A or A/2.
  4. If A is the smaller amount, then the other envelope contains 2A.
  5. If A is the larger amount, then the other envelope contains A/2.
  6. Thus the other envelope contains 2A with probability 1/2 and A/2 with probability 1/2.
  7. So the expected value of the money in the other envelope is:
    {1 over 2} (2A) + {1 over 2} left({A over 2}right) = {5 over 4}A
  8. This is greater than A, so I gain on average by swapping.
  9. After the switch, I can denote that content by B and reason in exactly the same manner as above.
  10. I will conclude that the most rational thing to do is to swap back again.
  11. To be rational, I will thus end up swapping envelopes indefinitely.
  12. As it seems more rational to open just any envelope than to swap indefinitely, we have a contradiction.

Clearly, this doesn’t make sense, the rational strategy can’t be to keep switching forever.  There are a number of different resolutions to this problem that use different techniques to show that in fact, the switching does not increase your expected payoff, but let’s try modeling this problem as a DAG and simulate it in petersburg to see if this construct is any simpler or more enlightening.

Petersburg DAG

The first step in creating a petersburg DAG is to draw a starting node with edges to each option available.  After that the structure of the outcomes for each option can be drawn out as separate subgraphs.  We call this the verbose graph, because it is simple to draw and interpret, but often has many redundant nodes.  For the two envelopes problem, we have two options: use the switching strategy, or don’t.

Screen Shot 2016-01-23 at 1.52.23 PM

Here, in the switching strategy subgraph, if envelope A is drawn, then it is immediately switched to envelope B, while in the keep strategy subgraph, there is no switch.  In this case, the payoff of node A or B in the final nodes would correspond to the dollar amount in the respective envelopes, and there are no edge costs.  M and N are used to represent the edge weights for the initial drawing, if each envelope is equally likely to be drawn, then the edge weights are equal to each other (M=N).

As you can see, there are many redundant nodes in this graph, so we simplify it down to a reduced graph:

Screen Shot 2016-01-23 at 1.52.33 PM

This, even without simulation makes it abundantly clear that if M and N are equal, then the two strategies are equal.  But let’s simulate it anyway with petersburg. In the simulation, we will run games with M=N=1, A=$50, B=$100 until the outcome converges.

two_envelope_convergance

So there you have it, not only is the expected outcome of each strategy is equal, the potential for ruin and the potential for windfall are the same as well. The reduced petersburg DAG can help to quickly make these kinds of conclusions apparent, often in a more intuitive way than traditional Bayesian probability calculations (though that is what’s happening under the hood regardless).  Because of this they can be a very useful tool for quick sketching of complicated relationships.  In future posts, we will explore some more of these classical cases, and some more real-world applications.

The code to run this simulation and the generate the plot can be found in the petersburg repository here.

The post Solving the two envelopes problem with python and petersburg appeared first on Will’s Noise.