Mini Project 3

Watchanan Chantapakul (wcgzm)


Questions

Write a program to evaluate the Bayesian belief network for fish in Example 3 of the textbook, using the same information on $P(a_j), P(b_j), P(x_l|a_i), P(x_l|b_j), P(c_k|x_l), and P(d_m|x_l)$.

Test your program on the cases given in that same Example in the textbook. Then, apply your program to the following cases – present the results in your report, and state any assumptions you make. You should also try/report other 'queries' (see examples in the figures below).

Hint: to solve this problem, you must remember what is $P(A, B | C)$ in terms of $P(A, B)$ and $P(C)$ – then, you must also remember how to find, say for the same example, $P(A,B)$ from $P(A,B,C)$ and $P(C)$ also from $P(A,B,C)$.

image.png

Figure from Pattern Classification Book by David G. Stork, Peter E. Hart, and Richard O. Duda

Belief Network Parameters

According to the figure above, we have to set up our Bayesian belief network:

Bayesian Belief Network

I implemented Bayesian belief network using graph data strcture. So there are two classes here:

  1. Node
  2. BeliefNet

Conditional Probability

$$ P(x|e) = \frac{P(x,e)}{P(e)} $$

where:

So, for instance, $$ P(a,b|c) = \frac{P(a,b,c)}{P(c)} $$ $$ P(x|c,b) = \frac{P(a,b,x,c,d)}{P(c,b)} $$

Joint Probability

We assume that all random variables are i.i.d. (independent and identically distributed). Simply put, they are statistical indepedent. Thus, we can calculate a joint probability with a product of all probabilities. If a variable is influenced by other variables, it is a conditional probability. Otherwise, it is just a simple probability.

For instance, based on the belief net, we get: $$ P(a,b,x,c,d) = P(a) \cdot P(b) \cdot P(x|a,b) \cdot P(c|x) \cdot P(d|x) $$

Marginal Probability

Let $\Theta$ be all variables in a belief net. So, $P(\Theta)$ is the full joint distribution over all the variables. We can compute a probability distribution of a specific variable $x$ by summing the full joint distribution over all variables other than $x$ as follows: $$ P(x) = \sum_{\Theta - \{x\}}P(\Theta) $$

For example, $$ P(a,b,x,c) = \sum_{d}P(a,b,x,c,d) $$ $$ P(a,b,x) = \sum_{c,d}P(a,b,x,c,d) $$ $$ P(a,b) = \sum_{x,c,d}P(a,b,x,c,d) $$ $$ P(a) = \sum_{b,x,c,d} P(a,b,x,c,d) $$

$$ P(d) = \sum_{a,b,x,c} P(a,b,x,c,d) $$

Now, create an instance of our Bayesian belief net.

Examples of how to use a Belief Net instance

We can achieve the same results as above by using a wrapper function named prob which acts as a gateway for other functions. It redirects its input to the corresponding function. If our query is for conditional probability, it will be forwarded to the cond_prob function. Otherwise, it will be sent to the marginal_prob function (It can serve for both joint probability and marginal probability).

Utility function for displaying an answer

It uses net.prob under the hood.

Cross-check with examples in the Mini-project 3's hints


(a) A light, thin fish is caught in the North Atlantic in the Summer. What is the probability it is a sea bass?

$$ P(x_2 | c_1, d_2, b_1, a_3) $$

(b) A thin, light fish is caught in the North Atlantic. What is the probability it is winter? spring? summer? autumn?

$$ P(a_i | d_2, c_1, b_1) $$

[Sanity check] all of these sum to 1:


(c) A medium, thin fish is caught in the Summer. What is the probability it came from the North Atlantic?

$$ P(b_1| c_2, d_2, a_3) $$