A year spent in artificial intelligence is enough to make one believe in God. — A. Perlis, “Epigrams on Programming”, SIGPLAN Notices, 1982.

In these lab exercises, you work with Bayesian networks.

Bayes Networks Review

This exercise reviews the burglary example from the AIMA text (Figure 14.2).

Exercise 5.1

Do the following exercises based on AIMA’s burglary example.

  1. Pull network.py and add enumeration_ask computations for the following examples:

    1. P(Alarm | burglary ∧ ¬earthquake)
    2. P(John | burglary ∧ ¬earthquake)
    3. P(Burglary | alarm)
    4. P(Burglary | john ∧ mary)

    The numbers should make some sense given the network. Because some of the computations can get complicated, e.g., the last one, you can skip the hand-coding on these. See the text, Section 14.4.1 for a full derivation of the last one.

Store your code in lab_1.py.

Conditional Independence

The following exercises demonstrate conditional independence using Bayesian networks that have varied topologies. The first exercise concerns a two-test cancer example.1

Exercise 5.2

The Bayesian network shown on the right represents a cancer domain in which two different cancer tests can be run and in which the tests are considered to be conditionally independent of one another.

Implement this network and use it to compute the following probabilities:

  1. P(Cancer | positive results on both tests)
  2. P(Cancer | a positive result on test 1, but a negative result on test 2)

Do the results make sense? How much effect does one failed test have on the probability of having cancer?

Explain your answers and work them out by hand.

Store your annotated code in lab_2.py.

The second example concerns a two-cause happiness example.2 Here, the causes are conditionally independent as well, but their probabilities can influence one another during inference. Thrun calls this phenomenon explaining away.

Exercise 5.3

The Bayesian network shown on the right represents a happiness domain in which either the sun or a raise in pay can increase the happiness of an agent.

  1. Implement this network shown and use it to compute the following probabilities:

    1. P(Raise | sunny)
    2. P(Raise | happy ∧ sunny)

    Explain these answers and work them out by hand.

  2. Use your implementation to compute the following probabilities:

    1. P(Raise | happy)
    2. P(Raise | happy ∧ ¬sunny)

    Do these results make sense to you? Why or why not? We leave working these problems out by hand as an optional exercise.

Store your annotated code in lab_3.py.

Approximate Inference Algorithms for Bayesian Networks

The exact inference algorithms used above tend to be intractable in real problems, so approximation algorithms are necessary. The AIMA probability library provides approximation algorithms to use in place of enumeration_ask().

Exercise 5.4

Notice the alternate computations of P(Burglary | john ∧ mary) (see 5.1 above) in the sample code, which use rejection sampling (see Figure 14.14), likelihood estimate (see Figure 14.15), and Gibbs sampling (see Figure 14.16). Do the results match those of the exact inference algorithms? Why or why not?

Add your answers for these tests to lab_1.py created above.

Checking in

We will grade your work according to the following criteria:

1 This example is taken from Thrun’s two-test cancer example.
2 This example is taken from Thrun’s confounding clause example.

See the policies page for lab due-dates and times.