CS430/530 Program 5 (Due November 1 2000)

In this assignment you will implement tell and ask for belief networks using the SPI algorithm developed at OSU by Professor D'Ambrosio and his former student Dr. Zhao-yu Li. I have already implemented the basic operations on probability tables, and I've provided a skeleton implementation for the operations on belief networks. You should download these from the file belief-net.lisp and modify the file to complete the assignment. To use this file, you should start up your lisp and load the aima.lisp file. This will load the necessary utilities. Then you can load your modified version of belief-net.lisp. Once you have your code working, you should compile it.

class belief-net. A belief network is essentially a list of conditional probability tables (known as ptables in the file). Here is the definition of belief-net:

(defstructure (belief-net (:constructor create-belief-net))
  (nodes nil)              ; a list of ptable's
  (known-variables nil)    ; variables whose values have been tell'ed
  (known-values nil)       ; alist of known variables and values
  (variables nil))         ; all variables in the network
The function make-belief-net will create a belief network. It takes as argument a list with the format shown in the following example:
(defparameter *test-net*
  '((cloudy
     ((cloudy)
      .5 ; f
      .5 ; t
      ))
    (sprinkler
     ((sprinkler cloudy)
      .5 ; f f
      .9 ; f t
      .5 ; t f
      .1 ; t t
      ))
    (rain
     ((rain cloudy)
      .8 ; f f
      .2 ; f t
      .2 ; t f
      .8 ; t t
      ))
    (wet-grass 
     ((wet-grass rain sprinkler)
      1.0  ; f f f
      0.1  ; f f t
      0.1  ; f t f
      0.01 ; f t t
      0.0  ; t f f
      0.9  ; t f t
      0.9  ; t t f
      0.99 ; t t t
      ))))
The format is (node1 node2 ... ).
Each node has the format (variable cpt-info)
The variable is a symbol giving the name of the node's variable.
The cpt-info is a list suitable for passing to make-ptable. It has the following format
(var-list p000 ... p111)
where var-list is a list of the variables that appear in this table and p000 ... p111 are the probability values that will appear in the table.

The order in which the nodes appear is very important because it determines the order in which the probability values are interpreted. Specifically, if the node for variable a is defined before the node for variable b, then in any ptable, the value of a will be varied faster than the value of b. For example, in the last table shown above, the variable sprinkler is varied the fastest (i.e., it is like the least-significant bit in the table), and the variable wet-grass is varied the slowest. I suggest that you list the nodes in "causal order" (e.g., sprinkler, rain, and wet-grass) and then, within each ptable, list the nodes in reverse causal order (e.g., wet-grass rain sprinkler).

Debugging. Your implementation should be able to reproduce the following trace:

;; create the network
> (setq *net* (make-belief-net *test-net*))
;; make a copy that we will destroy via tell and ask
> (setq *bn* (deep-copy-belief-net *net*))
> (ask *bn* 'rain)
(RAIN) Probability
0           0.5000
1           0.5000
> (tell *bn* 'wet-grass 1)
> (ask *bn* 'rain)
(RAIN) Probability
0           0.2921
1           0.7079
;; note that if we ask about something we have already told it, we
;; should get an answer back.
> (ask *bn* 'wet-grass)
1
> (tell *bn* 'cloudy 0)
> (ask *bn* 'rain)
(RAIN) Probability
0           0.6557
1           0.3443
> (tell *bn* 'sprinkler 0)
> (ask *bn* 'rain)
(RAIN) Probability
0           0.0000
1           1.0000
> 
To aid in your debugging, here is the joint distribution for the *test-net*:
(WET-GRASS RAIN SPRINKLER CLOUDY) Probability
0000        0.2000
0001        0.0900
0010        0.0200
0011        0.0010
0100        0.0050
0101        0.0360
0110        0.0005
0111        0.0004
1000        0.0000
1001        0.0000
1010        0.1800
1011        0.0090
1100        0.0450
1101        0.3240
1110        0.0495
1111        0.0396

Test problem. The file also contains a network for diagnosing problems with cars. The variable *car-net* describes the following belief network:

Note that in this network, a value of 0 is the "good" value, and a value of 1 indicates a problem. Your assignment is to compute the probability of each of the following causes after each observation. The possible causes are the following:

SparkPlugs Distributor FuelPump Leak2 Starter 
BatteryAge Alternator FanBelt Leak GasInTank
  1. Prior to any observations.
  2. After observing Starts is 1. (car won't start)
  3. After observing EngineCranks is 1. (engine won't crank)
  4. After observing GasGauge is 1. (gas gauge reads empty)
  5. After observing Radio is 1. (radio doesn't work)
  6. After observing FuelPump is 0. (fuel pump ok)