AI Project #2: Bayes Nets

Due: Monday February 1415, 2011, 11:59 PM

(Last Update Feb 14, 5:00 PM)

In this project, you will perform exact and approximate inference in Bayesian Networks.

All variables are assumed binary.

Calling Convention
You will need to produce a file inference.py that will compute conditional probabilities (either exactly, or approximately via sampling). It will be called like so:

python inference.py egnet.txt EXACT 1 1 0 0 2 1 3 0
The input arguments are:

File Format of Bayes Net
An example of the kind of tree you will need to read in is egnet.txt. Here is a visualization of this net. Thank you Haitao!

For sampling, you should generate 100,000 samples.

You will again submit your project using mycourses. You need to submit two files, inference.py, and writeup.txt, which is a plain text file documenting your code. Please submit the two files seperately (please do not put them into a .zip or .tar.gz file).

Your code will be tested using Python 2.6.

Your project grade will be assigned as follows:

Please contact Justin Domke with any clarifying questions. Answers will be posted here for all, so check for updates periodically.

Questions:
Q) Is it OK for my program to crash on bad input data?
A) Yes.

Q) What is the output format?
A) Just print out the specified conditional probability in text format.

Q) Can we assume that the parents of a variable always have lower numbers? (I.e. is it impossible for X5 to be a parent of X4?)
A) Yes.

Q) Can you please, please, please give us a couple test cases?
A) For you, anything!

$ python inference.py egnet.txt EXACT 1 1 0 0 2 1 3 0 
0.994974874372
$ python inference.py egnet.txt EXACT 0 0
0.5
$ python inference.py egnet.txt EXACT 1 1 0 1
0.5
$ python inference.py egnet.txt EXACT 0 0 2 1
0.4

Q) How much randomness should we expect in the sampling based inference?
A) It depends on the input query, but here is an example of calling the above function a few times.

$ python inference.py egnet.txt SAMPLING 1 1 0 0 2 1 3 0 
0.994463809719
$ python inference.py egnet.txt SAMPLING 1 1 0 0 2 1 3 0 
0.994411177645
$ python inference.py egnet.txt SAMPLING 1 1 0 0 2 1 3 0 
0.993524888709
$ python inference.py egnet.txt SAMPLING 1 1 0 0 2 1 3 0 
0.99411995296
$ python inference.py egnet.txt SAMPLING 1 1 0 0 2 1 3 0 
0.995306122449