Sitemap
Pascal Bercker

Pascal Bercker

Philosophy | philosophy of science | logic | Bayesian networks and logic puzzles | keen on the use of Bayesian networks to solve Smullyan-type logic puzzles

An Exercise In Conditional Probability — From 1000 Exercises In Probability

4 min readMar 22, 2026
Press enter or click to view image in full size
There are 5 parts to this exercise
Press enter or click to view image in full size
Image by Gemini Pro

This is not particularly difficult, but it’s important to pay attention to the sequence of events to get the model right. Let’s first get the structure of the network and then worry about equations for the probabilities.

Here is one possible structure to capture the general causal flow of things and answer the five parts of the problem. The first coin is randomly picked and will be flipped twice (flip1 and flip2) and then discarded. A new coin will be randomly picked from the remaining four and flipped once.

Press enter or click to view image in full size
The general causal structure for the sequence of events (initialized with uniform distributions)

We are given that two are double-headed, one is double-tailed, and two are normal. We can initialize the hypothesis node manually as unnormalized count data or with an equation (and let Netica normalize automatically):

We can manually enter the raw number count for each coin type

Or with an equation:

P (first_coin | ) =  

first_coin == HH ? 2 : // two double headed
first_coin == TT ? 1 : // 1 double tailed
first_coin == HT ? 2 : 0 // 2 normal coins

// select0 (first_coin, 2, 1, 2)

Next is the Conditional Probability table (CPT) for the two flips (of the same but unknown coin). Again,n we can do this manually or with an equation:

Flipping Heads or Tails depend on the (first) coin type chosen (randomly)

The equations are slightly more involved ( The select0 is an alternate form, using the state index) :

P (flip1 | first_coin) = 

first_coin == HH ? (flip1 == H ? 1 : 0) :
first_coin == TT ? (flip1 == T ? 1 : 0) :
first_coin == HT ? (flip1 == H ? 1/2 : 1/2) : 0

// flip1 == H ?
// select0 (first_coin, 1, 0 , 1/2) :
// select0 (first_coin, 0, 1, 1/2)

P (flip2 | first_coin) =

first_coin == HH ? (flip2 == H ? 1 : 0) :
first_coin == TT ? (flip2 == T ? 1 : 0) :
first_coin == HT ? (flip2 == H ? 1/2 : 1/2) : 0

We can manually enter the new count for the new coin since only 4 coins remain, given that the first coin is discarded. What remains is a function of what the first discarded coin was. Once again, we can enter the unnormalized coin count and let Netica automatically normalize (dividing by 4).

Note that 4 coins remain since the first coin was discarded

If not manually entered, then we do so with a clever equation:

P (new_coin | first_coin) = 

( select0 (new_coin, 2, 1, 2) // original counts: HH, TT, HT
- (new_coin == first_coin ? 1 : 0) ) // subtract discarded coin

Claude AI gave me this clever equation ( which turns out to be a manifestation of the Kronecker delta), which was more elegant than my original clunker (this works fine, but it’s brute force)!

Brute force table lookup!

Once the equations are compiled, we have this updated network. We can answer the first question immediately by looking at flip1:

Press enter or click to view image in full size
The probability of heads on the first flip is 60%

Now we are ready to enter further observations to see how the network is further updated. Watch carefully and see the sequence of updates (the green numbers correspond to the question being answered):

Press enter or click to view image in full size
We enter each observation as required by the questions. Notice how each node is updated

Notice that once we enter the observation for flip1, we get an updated posterior for HH, which in turn informs the new expectation that the second toss (flip2) will be heads. And when observed to be heads again, the probability for HH for a new coin correspondingly goes down, as does the probability that a newly selected coin will turn up heads (at 52.5%, down from 60%).

Get Pascal Bercker’s stories in your inbox

Join Medium for free to get updates from this writer.

Each number corresponds to the five questions and their answers below:

Answers for the five questions

BOOK SOLUTION

Press enter or click to view image in full size

--

--

Pascal Bercker
Pascal Bercker

Written by Pascal Bercker

Philosophy | philosophy of science | logic | Bayesian networks and logic puzzles | keen on the use of Bayesian networks to solve Smullyan-type logic puzzles