Estimating the Weights of Biased Coins
Suppose we flip a coin four times. If the coin lands on heads, we win a dollar. If the coin lands on tails, we lose a dollar. After four tosses of the coin, the best possible outcome is a winning total of four dollars. The worst possible outcome is a loss of four dollars. Let’s assume the coin is a biased coin. Furthermore, let’s also assume a different biased coin is used on each flip depending on the total amount won or lost since the beginning of the game. How can we determine the bias of each coin given a probability mass function of the expected outcome?
In this post, I want to explore a technique that can be used to answer this question. I am hoping this model can be expanded to give some better insights into observations made in my previous posts regarding the distribution of price fluctuations and the strange behavior of the Chinese yuan.
Markov Model
The aforementioned coin toss game can be modeled as a Markov chain. The game starts in the initial zero state. Each toss of the coin determines whether the system transitions to a higher state or a lower state. If the coin lands on heads, we move to a higher state. If the coin lands on tails, we move to a lower state. Each state determines the weight of the biased coin used in the next toss. Here is a graphical representation of the Markov model:
In this model, the coin in the zero state is always a fair coin. A fair coin will land on heads 50% of the time and tails 50% of the time. Additionally, this model is also symmetrical. The biased coins in the negative states are weighted inversely to the biased coins in the corresponding positive states. The diagram above can alternately be depicted as follows:
Note that the positive and negative fourth states can only be terminal states, so there is never a transition out of them. Also, keep in mind that the Markov model does not necessarily have to be symmetrical. I chose to make it symmetrical to reduce the number of variables and to simplify the model.
Monte Carlo Simulation
If we know the weights of the biased coins, we can use a Monte Carlo simulation to estimate the expected outcome of the coin toss game. Simply put, we can run a million simulated rounds of the coin toss game, with four flips in each round, and observe the distribution of possible outcomes. Suppose each coin is weighted fairly:
The values above can be presented visually on a chart like this:
In a Monte Carlo simulation, we use a random number generator to simulate the outcome of each coin toss. We record the terminal state after each round of four coin tosses. After running one million rounds of the coin toss game, the distribution of terminal states looks like this:
This gives us an estimate of the expected outcome after four tosses of the coin. Notice that only even terminal states are possible when there is an even number of coin tosses. Odd-numbered terminal states would only be possible if there were an odd number of tosses. It is also worth noting that the chart above closely approximates a binomial distribution. Here is a breakdown of the expectation for each individual coin toss sequence:
The values are all roughly the same, indicating that all possible coin toss sequences have about an equal probability of being observed in any given round of the coin toss game, assuming we’re always using fair coins. The Monte Carlo simulation is a brute force approach that yields fairly accurate results. We can arrive at more precise values by finding the results analytically.
Analytical Evaluation
With four tosses of the coin, there are sixteen possible coin toss sequences and five unique terminal states. The following table lists every possible coin toss sequence along with its terminal state and a formula for the probability of each combination:
Keep in mind that the model is symmetrical. We can use the following notation to represent the probability of landing on each of the five possible terminal states:
Since the model is symmetrical, the chance of ending up in any given positive terminal state is equal to the probability of ending up in the corresponding negative terminal state. The equations above can be rewritten as follows:
Plugging in the probability formula for each of the coin toss combinations, the equations above can be expressed like this:
By definition, since our model is a symmetrical one, we know that the coin used in the zero state is always a fair coin:
Substituting the value above for the weight of the coin at the zero state and then simplifying, we can arrive at the following set of equations:
This set of equations represents the relationship between the weights of the biased coins and the expected outcome of the coin toss game. If we know the weights of the coins, we can compute the probability mass function of the expected outcome after four tosses of the coin. To illustrate, let’s assume each coin is weighted fairly:
This is the same scenario we started with when doing the Monte Carlo simulation above, so we can expect to get the same or similar results. Plugging in the numbers, here are the computed results:
These results can be presented visually with the following chart:
These are the exact figures that were estimated by the Monte Carlo simulation demonstrated in the previous section. This is a binomial distribution. The computed expectation of each individual coin toss sequence is shown below:
This confirms the result estimated by the Monte Carlo simulation as well. When always using a fair coin, each of the sixteen combinations of coin toss sequences has an equal probability of being observed.
Many Possible Solutions
We know from the previous sections that if all the coins are fairly weighted, then the expected outcome after four coin tosses is a binomial distribution. But what if we start with a binomial distribution as the expected outcome and work backwards to find the weights of the coins? We already know that having fairly weighted coins is one possible solution. But can there be other possible solutions as well?
Let’s introduce the following notation. We have seen a graphical illustration of what a binomial distribution looks like in the previous section. Here is the symbolic form of the probability mass function for a binomial distribution:
For succinctness, I am using an alternate zero-based index to represent the terminal states. The following relationship holds:
Since there are only four coin tosses in the model we’re using here, we can substitute:
Now recall the following from the previous section:
We can substitute the alternate notation and rewrite it like this:
Plugging in the numbers and doing the math, we can compute the following values to represent the binomial distribution:
This represents the expected outcome after four coin tosses. Now we want to figure out what weights of the biased coins will give us this expectation. Based on the analysis in the previous section, we already know that playing the coin toss game with fairly weighted coins will give us our desired result:
However, this is not the only solution. As it turns out, there is an entire range of possible solutions that result in an expected outcome that takes the form of a binomial distribution. Consider the following equations derived in the previous section:
Any solution that fits these equations is a valid solution provided that the following constraints are met:
The constraints are necessary because a coin cannot land on heads less than 0% of the time, nor can it land on heads more than 100% of the time. Using the equations above, we can rearrange them and solve for the weights of the biased coins in the +2 and +3 states in terms of the weight of the coin in the +1 state:
Any value for the weight of the biased coin in the +1 state can be used provided that the aforementioned constraints are met for the weights of all coins. There is a range of possible values for the coin in the +1 state. This range has a lower and upper bound. We can determine the lower bound for the weight of the coin in the +1 state by setting the weight of the coin in the +2 state to the maximum value of one:
With the weights of the coin in the +2 state held constant at one, we can solve for the weights of the coins in the +1 and + 3 states:
Plugging the values into the equations:
Here are the weights of all the coins when the weight of the coin in the +1 state is at the lower bound of the range:
Using the above weights, we can evaluate the expected outcome of the coin toss game and show that it indeed does result in a binomial distribution:
This is the same expected outcome we would get if all the coins were fair coins. However, consider the expectation of each individual coin toss sequence:
Not all coin toss combinations are equal. Some have a higher probability of being observed than others when the biased coins are weighted unfairly. We can observe a similar phenomenon when the weights of the coins are at the opposite extreme of the range of possible values. Suppose the weight of the coin in the +3 state is set to the maximum value of one:
With this held constant, we can find the upper bound for the weight of the coin in the +1 state and the lowest value for the weight of the coin in the +2 state:
Plugging the values into the equations:
Here are the weights of all the coins when the weight of the coin in the +1 state is at the upper bound of the range:
Again, using the above weights, we can evaluate the expected outcome of the coin toss game and show that it indeed does result in a binomial distribution:
Like before, this is the same expected outcome we would get if all the coins were fair coins. But in this case, we get a different set of expectations for each coin toss sequence:
The examples illustrated in this section demonstrate two extremes of a range of possible values for the weights of biased coins. In both examples, these values yield an expected outcome in the shape of a binomial distribution when playing the coin toss game with four tosses. And this is the same outcome we can expect when playing the game with fair coins. Of course, there are many other possible values that will give us a binomial distribution as well.
Hill Climbing Algorithm
What if the expected outcome is not a binomial distribution? Suppose we observe many rounds of the coin toss game and determine the expected outcome is a triangle distribution instead. We know the coins are biased, but how can we estimate the weights of the biased coins? Consider the symbolic form of a triangle distribution:
Using the techniques described in the previous section, we can compute the following values for the triangle distribution:
We can also represent this visually with the following chart:
And using the techniques described in the previous section, we can also compute the lower and upper bounds of the range of possible values that will yield a triangle distribution. The values are illustrated below:
While the weights illustrated above are valid to produce a triangle distribution, they might not be the best estimates to model a real-world scenario. A coin that always lands on heads or always lands on tails, for example, might not be the most accurate model of reality. It might be better to come up with an intermediate solution that lies somewhere in between the two extremes.
Instead of trying to find an intermediate solution analytically, we can try to find one incrementally. We can start with an initial guess somewhere in the middle and then incrementally try to improve our initial estimate. We can repeat this process until we converge on a valid solution that fits the triangle distribution. This would effectively be a type of hill climbing algorithm.
Suppose we start with an initial guess of all fairly weighted coins. We can randomly pick one of the estimated weights, adjust it up or down by a small amount, and then measure whether or not the adjustment brings the computed outcome closer to that of a triangle distribution. If the adjustment is an improvement, then we accept it. If the adjustment is not an improvement, then we reject it and revert back to the previous value. We can repeat this process many times. Here is an illustration of this algorithm:
This algorithm iterates one million times, accepting or rejecting a proposed increment to one of the estimated weights. It’s basically a trial and error process. Applying this algorithm gives us the following estimates for the weights of the biased coins:
Playing the coin toss game with the above weights for the biased coins will yield an expected outcome that is very close to the triangle distribution. This is not an exact solution, but it is very close. This is also not the only solution. One of the idiosyncrasies of this approach is that the result can be different depending on what values are used for the initial guess. Remember, there is a range of possible solutions, all equally valid.
The following sections catalog the application of this estimation process to a few variations of a discrete double exponential distribution instead of a triangle distribution.
Exponential Distribution, Parameter = 0.5
Suppose we model the expected outcome as a discrete double exponential distribution such that the expectation of the game finishing on a given terminal state is 0.5 times that of the terminal state with the next highest expectation. Here is the probability mass function:
Here is a graphical representation of the probability mass function above:
The following charts are the lower and upper bounds of the range of possible values for weights that result in the expected outcome defined above:
Here are the estimated weights using the hill climbing algorithm:
The above values were estimated starting with an initial guess of fairly weighted coins and running the hill climbing algorithm through one million iterations.
Exponential Distribution, Parameter = 0.4
Suppose we model the expected outcome as a discrete double exponential distribution such that the expectation of the game finishing on a given terminal state is 0.4 times that of the terminal state with the next highest expectation. Here is the probability mass function:
Here is a graphical representation of the probability mass function above:
The following charts are the lower and upper bounds of the range of possible values for weights that result in the expected outcome defined above:
Here are the estimated weights using the hill climbing algorithm:
The above values were estimated starting with an initial guess of fairly weighted coins and running the hill climbing algorithm through one million iterations.
Exponential Distribution, Parameter = 0.3
Suppose we model the expected outcome as a discrete double exponential distribution such that the expectation of the game finishing on a given terminal state is 0.3 times that of the terminal state with the next highest expectation. Here is the probability mass function:
Here is a graphical representation of the probability mass function above:
The following charts are the lower and upper bounds of the range of possible values for weights that result in the expected outcome defined above:
Here are the estimated weights using the hill climbing algorithm:
The above values were estimated starting with an initial guess of fairly weighted coins and running the hill climbing algorithm through one million iterations.
Next Steps
I want to explore this estimation technique in more depth. I would like to see what the estimated weights look like when the coin toss game is played with many coin tosses per round instead of just four. Perhaps this will be the topic of a later post.
I would also like to come up with a more meaningful cost function for the hill climbing algorithm, one that would give preference to valid values closer to the middle of the range of possible values. With the implementation presented in this post, there is a plateau of valid values that can be estimated. The value that it converges to is highly dependent on the initial guess. Having a better cost function would allow the algorithm to converge to the same solution regardless of the starting point. I’m not sure yet how to do this.
Comments