HW6: Approximate Inference in Bayes Nets

Due 11:59pm, Tuesday, April 10, 2012

  1. In this homework, you will implement Gibbs sampling to perform approximate inference on Bayes Nets. Carefully read Bishop 8.1 and 8.2 (on Bayes Nets) and Bishop 11.2 and 11.3 (on MCMC and Gibbs sampling). You might prefer these notes on MCMC which are less dense than Bishop.
  2. Go to the Bayes Net Toolbox (BNT) website. Download and unzip the installation file. Add all subfolders of the installation directory to the path in Matlab. You can set the path via File->Set path->"Add with subfolders" (at least in Matlab 7.1).
  3. Download this starter code to get the code you will be building on. The file hw6.m is the main driver and is the file you should look at first. This code builds a network and shows how to use some other functions. You must not use any functionality in the BNT beyond the functions called in the starter code that is provided!
  4. Implement Gibbs sampling as described on Bishop p. 543, modified to compute P(z_i | e), where z_i is an assignment to a single variable, and e is an assignment to some set of variables. An assignment is a mapping from variables to values. Note that the algorithm in the book samples from the joint distribution. Instead, to sample from the conditional distribution P(z_i | e), do the following: Change the initialization (line 1 of the algorithm) so that it initializes the variables in e to have the values in e. Also, in step 2 of the algorithm, do not resample values for the variables in e -- leave them alone. This can be seen as "clamping" the variables in the evidence set e. You can choose how many samples to use and the length of the burnin period.

    Part of the algorithm involves computing the probability distribution of a variable given an assignment of values to the set of all the other variables, P(z_i | {z_\i}). This probability can be computed using the equation on p. 382, replacing the integration with summation since we are dealing with discrete random variables. Below the equation, they discuss a more efficient way of doing this that involves the concept of a Markov Blanket, but you can ignore that for the homework and just do it the "brute force" way, by directly implementing the equation.

  5. Test the algorithm by generating 20 random conditional probability queries, and then compute the probability using exact inference (using the provided exactInf.m) and approximate inference (your own Gibbs sampler). Then make a bar chart showing the difference between probabilities generated by exact and approximate inference over the 20 problems. Code to do this is at the end of hw6.m.
  6. Write and submit a report that includes any details of your implementation that weren't specified in the report, and the bar chart. The difference between exact and approximate inference should be very small (around 0.02) for most problems. If your results aren't that good, then explain how you attempted to debug your code. This report should be very brief -- consider this homework a breather. The command to submit will be something like: turnin --submit lewfish hw6.