-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'newquestion-bayescoins'
- Loading branch information
Showing
3 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
\begin{answer}{bayescoins} | ||
This is another question that tests your knowledge of Bayes' law. | ||
Let's define some notation to use. | ||
Define $H$ as the event that a coin comes up head, and $T$ that a coin comes up tails, and let $10H$ denote getting ten heads from ten coin flips. | ||
Let $C_{F}$ be the event where we select the fair coin from the bag, and $C_{R}$ the event that we select the rigged coin. | ||
This is one of the simplest questions about Bayes' law as there is not much to unpack. | ||
You want to know the probability of the rigged coin being selected, given you saw ten heads. | ||
By rote application of Bayes' law: | ||
\begin{align} | ||
\label{eq:1000coins:bayeslaw1} | ||
P( C_{R} \vert 10H) | ||
&= | ||
\frac{ | ||
P( 10H \vert C_{R} ) | ||
P( C_{R} ) | ||
}{ | ||
P( 10H \vert C_{R} ) | ||
P( C_{R} ) | ||
+ | ||
P( 10H \vert C_{F} ) | ||
P( C_{F} ) | ||
} | ||
\text{.} | ||
\end{align} | ||
Consider | ||
$P( 10H \vert C_{R} )$, the probability of getting ten heads in a row with the rigged coin. | ||
Since this will happen with certainty | ||
$P( 10H \vert C_{R} ) = 1$. | ||
For the fair coin each flip is independent, so you have | ||
$$P( 10H \vert C_{F} )=P( H \vert C_{F} )^{10}= ({1}/{2})^{10} = {1}/{1024}.$$ | ||
Since you picked te coin out of a bag of 1000 coins, the probability that you selected the rigged coin is | ||
$P(C_{R}) = 1/1000$ and the probability that the coin you selected is fair is | ||
$P(C_{F}) = 999/1000$. | ||
You can substitute these into \eqref{eq:1000coins:bayeslaw1} to get | ||
\begin{align*} | ||
P( C_{R} \vert 10H) | ||
&= | ||
\frac{ | ||
(1) | ||
\left( \frac{1}{1000} \right) | ||
}{ | ||
(1) | ||
\left( \frac{1}{1000} \right) | ||
+ | ||
\left(\frac{1}{1024}\right) | ||
\left(\frac{999}{1000}\right) | ||
} | ||
\\ | ||
&= | ||
\frac{ | ||
1 | ||
}{ | ||
1 | ||
+ | ||
\left(\frac{999}{1024}\right) | ||
} | ||
\\ | ||
&= | ||
\frac{ | ||
1 | ||
}{ | ||
\left(\frac{2023}{1024}\right) | ||
} | ||
\\ | ||
&= | ||
\frac{1024}{2023} | ||
\text{,} | ||
\end{align*} | ||
which is slightly more than $1/2$. | ||
|
||
This question is so well known that your interviewer likely won't even let you finish it. | ||
Once they see that you are on the right track they will move on to the next question. | ||
My interviewer didn't care about the answer, but he wanted me to describe \eqref{eq:1000coins:bayeslaw1} in detail. | ||
Since Bayes' law is just the application of conditional probability, you can derive it from first principles: | ||
\begin{align} | ||
\label{eq:1000coins:bayesexplain} | ||
P( C_{R} \vert 10H) | ||
&= | ||
\frac{ | ||
P( 10H , C_{R} ) | ||
}{ | ||
P( 10H ) | ||
} | ||
\end{align} | ||
and even a frequentist will agree. | ||
The nominator is the joint probability of ten heads and the rigged coin being selected, and it is easier to split this into another conditional probability: | ||
\begin{align*} | ||
P( 10H , C_{R} ) | ||
= | ||
P( 10H \vert C_{R} ) p( C_{R} ) | ||
\text{.} | ||
\end{align*} | ||
Technically, we can also say | ||
\begin{align*} | ||
P( 10H , C_{R} ) | ||
= | ||
P( C_{R} \vert 10H ) p( 10H ) | ||
\text{,} | ||
\end{align*} | ||
but this is not helpful, as it contains the quantity we are trying to solve for, $P( C_{R} \vert 10H )$, and will lead to circular reasoning. | ||
|
||
You can expand denominator in | ||
\eqref{eq:1000coins:bayesexplain} | ||
using the law of total probability to consider all the possible ways you can see ten heads. | ||
Since you only have two types of coins---either a fair coin or a rigged one---there are only two ways ten heads can happen: | ||
\begin{align*} | ||
P( 10H ) = | ||
P( 10H \vert C_{R} )p(C_{R}) | ||
+ | ||
P( 10H \vert C_{F} )p(C_{F}) | ||
\text{.} | ||
\end{align*} | ||
If the interviewer wants you to explain even further, you can note that this is derived form the marginal probability | ||
\begin{align*} | ||
P( 10H ) = | ||
P( 10H , C_{R} ) | ||
+ | ||
P( 10H , C_{F} ) | ||
\text{,} | ||
\end{align*} | ||
by applying the law of conditional probability to each of the terms. | ||
Putting all this together yields \eqref{eq:1000coins:bayeslaw1}. | ||
|
||
My interviewer used this Bayes' law question to test my handle on probability concepts. | ||
It is easy to confuse these basic concepts, which is another reason for doing proper interview preparation. | ||
Some interviewers ask this question and demand an ``intuitive'' solution that doesn't rely on algebraic manipulation. | ||
In this case, you could opt for a visual explanation of Bayes' Law as discussed in answer \ref{a:bayeslawdisease}. | ||
If that's not what your interviewer wants, use the following argument. | ||
You know the probability of choosing the rigged coin is $1/1000$. | ||
You also know the probability of getting ten heads from a fair coin is $1/2^{10} = 1/1024$. | ||
These two events are about equally likely, meaning the probability that we have the double headed coin is about a half. | ||
If you only had nine heads in a row, the fair coin would give a probability of $1/512 = 2/1024$. | ||
That means the outcome of nine heads is about twice as likely with the fair coin as the probability of selecting the rigged coin from the bag. | ||
So the odds of ${fair}{:}{rigged}$ are $2{:}1$, leading you to assign a probability of about $1/3$ to the rigged coin being selected. | ||
%TODO: could link this up to section on gambling mathematics | ||
\end{answer} | ||
|