Algorithms for Graphical Models (AGM)

Practical 08: Machine learning


  1. Data compression
  2. Scoring BNs
  3. Searching for good BNs

Data compression

Have a look at make_data.py. It reads in the ever-present Asia example, and generates data from it using forward sampling, saving the data to a file whose name is supplied on the command line. Run it to create some data.

This is a bulky representation since multiple occurrences of a given instantiation are written out in full each time. Alter make_data.py to make a new program called make_data2.py. This new program should produce output where each instantiation is written out once together with a count of how many times it was sampled. See data.txt for an example of the desired output.

Solution


Scoring BNs

Have a look at score_asia.py. Run it by supplying a CSV data file as a command line argument. (Use data.txt if you like.) Note that it uses a BN method called bdeu_score to score an entire BN, and also CPT method of the same name to score individual `families' (variable + its parents). The BDeu score is just the marginal log-likelihood with a choice of Dirichlet prior parameters which ensures likelihood equivalence.

Add to score_asia.py so that you get the score for the BNM model whose ADG is like that of Asia except that the arrow from Smoking to Cancer is missing.

Solution


Searching for good BNs

Write a program which finds the highest scoring ADG (Bayesian network model) for data.txt. Use BDeu scoring, and take advantage of the fact that this score is a sum of variable-specific scores. To make your life easier only consider:

  1. BNs consistent with the following topological ordering: Smoking,Cancer,Bronchitis,VisitAsia,Tuberculosis,TbOrCa,XRay,Dyspnea. For a BN to be consistent with this ordering a variable's parents have to come before it in the ordering.
  2. BNs where no variable has more than three parents.

You will find it useful to cannibalise bits of the previous programs.

Solution


Last modified: Fri Dec 7 09:31:41 GMT 2007

Valid XHTML 1.1!