← Back to list

Constructing a Bayesian Belief Network — Who Wins This Game?

This exercise comes from a very recent (2025) online textbook on Bayesian Reasoning and Machine Learning by David Barber.

Pascal Bercker · 2026-03-17 13:46 · 7 claps · 3.9 min read
#probability #bayesian-networks #netica #bayesian-inference #bayesian-statistics
Open on Medium ↗
Wiki topics: OPS · LLMOps & Inference ML · Machine Learning EDU · Education & Learning 📐 · Mathematics 💪 · Fitness & Wellness

Constructing a Bayesian Belief Network — Who Wins This Game?

This exercise comes from a very recent (2025) online textbook on Bayesian Reasoning and Machine Learning by David Barber.

This seems like a daunting exercise but easily done with Netica!

This seems like a daunting exercise but easily done with Netica!

While Barber works with MATLAB & a Python Bayesian library, I will show how to easily solve this exercise with Netica, a Bayesian Network software.

We need four numeric skill variables for A, B, C, and D, enumerated (1…10). We can use 9 boolean variables, one for each win or loss between each player. The skill variables have a uniform distribution and are (initially) each independent. They are equally likely to win or lose. Let’s start with this initial representation.

The ultimate variable of interest will be who_wins_DA1, the game between player A and D

The ultimate variable of interest will be who_wins_DA1, the game between player A and D

Each who_wins indicator variable relates to the players involved. For example, Who_wins_AB1 is for whoever wins between A and B in the first game.

Nine indicator nodes for each game between the players

Nine indicator nodes for each game between the players

Two of the nine tables:

These are to be filled according to the equation below, where winning or losing is a function of their skill

These are to be filled according to the equation below, where winning or losing is a function of their skill

The probability that A beats player B as a function of their skill

The probability that A beats player B as a function of their skill

We encode this equation as a probability this way:

P (who_wins_AB1 | A, B) = 

  who_wins_AB1 == a ? 1 / ( 1 + exp (B - A) ) : 
                      (1 -  1 / ( 1 + exp (B - A) ) )

P (who_wins_AB2 | A, B) = 

  who_wins_AB2 == a ? 1 / ( 1 + exp (B - A) ) :
                      (1 -  1 / ( 1 + exp (B - A) ) )

// We do likewise for the other 7 who_wins node

Once compiled, we have the updated table. Notice that if they are equally skilled (both 2, or both 6, etc.), they are equally likely to win or lose. When the skill difference is maximal (1 vs. 10), the more highly skilled is almost certain to win, at well over 99%.

Whoever is more skilled is more likely to win the game

Whoever is more skilled is more likely to win the game

All we need to do now is to indicate who won each of the nine matches. Watch what happens as we instantiate each who_wins node (in green). In particular, watch how the various skill nodes get updated to reflect what we learn as a function of what is observed.

Watch how skills are updated for each player and how we can predict who wins between A and D

Watch how skills are updated for each player and how we can predict who wins between A and D

We can now answer all four questions from the final result:

Question 4 answer: Skill (A) = 7.87, skill (B) = 6.85, skill(C) = 5.98, skill(D) = 3.05

Question 4 answer: Skill (A) = 7.87, skill (B) = 6.85, skill(C) = 5.98, skill(D) = 3.05

In view of his low skill level, player D is very likely to lose to player A, since A has a better than 95% chance of winning (question 3).

Prior to doing anything, the player's skills are independent of each other. We can demonstrate this visually by instantiating each skill and

Note carefully that skills are a priori independent, meaning that instantiating any skill makes no difference to any other skill (but notice that who wins, of course, depends on skill level)

Note carefully that skills are a priori independent, meaning that instantiating any skill makes no difference to any other skill (but notice that who wins, of course, depends on skill level)

But we can demonstrate the answer to Question 2 is no; the skill levels are a posteriori no longer independent, given the win/loss record, because they are conditioned by each win record. We can visually see this below:

Notice that if we instantiate any skill, other skills respond accordingly because they are no longer independent

Notice that if we instantiate any skill, other skills respond accordingly because they are no longer independent

For the sake of completeness, we should show that, instead of using Boolean indicator nodes for each round, we can use a count node for each match consisting of two or three rounds (since A plays C three times).

Using a count node instead of boolean indicator node

Using a count node instead of boolean indicator node

We then use the binomial distribution (k, n, p) where ‘k’ is the number of wins out of ’n’ trials, where the probability ‘p’ of success for A winning was given by: 1 / (1 + exp (B — A) ).

P (who_wins_AB | A, B) = 

   BinomialDist (who_wins_AB, 2, 1 / (1 + exp (B - A) ) ) 

P (who_wins_AC | A, C) = 

   BinomialDist (who_wins_AC, 3, 1 / ( 1 + exp (C - A) ) )

P (who_wins_AD | A, D) = 

   BinomialDist ( who_wins_AD, 1, 1 / (1 + exp ( A - D) ) )

P (who_wins_BC | B, C) = 

   BinomialDist (who_wins_BC, 2, 1 / (1 + exp (C - B)) )

P (who_wins_DC | D, C) = 

   BinomialDist (who_wins_DC, 2, 1 / ( 1 + exp ( C - D) ) )

And now we instantiate the number of games won or lost by each player and see how the skill levels are updated accordingly.

Just as before, player D has just 4.50% chance of winning against player A

Just as before, player D has just 4.50% chance of winning against player A

You can download the .dne file to run in Netica here:

https://github.com/Pascal-bayesian/bingame-bayesian-network

SOURCES & REFERENCES

David Barber: Brml — Home Page browse

https://github.com/snowdj/CS228_PGM/blob/master/books/Bayesian%20Reasoning%20and%20Machine%20Learning%20by%20David%20Barber.pdf

[embed]Norsys - Netica Application Netica is a powerful, easy-to-use, complete program for working with belief networks and influence diagrams. It has an…www.norsys.com


메타데이터
post_id
b99772f8be36
slug
constructing-a-bayesian-belief-network-who-wins-this-game-b99772f8be36
url
https://medium.com/@pbercker/constructing-a-bayesian-belief-network-who-wins-this-game-b99772f8be36
canonical_url
https://medium.com/@pbercker/constructing-a-bayesian-belief-network-who-wins-this-game-b99772f8be36
author_url
https://medium.com/@pbercker
status
ok
fetched_at
2026-07-13 06:23:13