Lab: Bayesian Network Inference
CSC261 - Artificial Intelligence - Weinman
- Summary:
- We explore the creation and use of belief propagation
in bayesian networks.
Preparation
- Create a directory and copy the starter files for this lab
-
$ mkdir bayesnet
$ cp ~weinman/courses/CSC261/code/bayesnet/*.scm bayesnet/
$ cd bayesnet
- Create a new Scheme file bayesnet-prep.scm in your bayesnet
directory and open it in your Scheme environment.
Exercises
A: Network Topology
- Load the example network and other files into your environment
-
;; Load methods for creating/manipulating Bayesian networks
(load "bayesnet.scm")
;; Load starter methods for inferences in Bayesian networks
(load "belief-propagation.scm")
;; Load simple example network
(load "example.scm")
- The definition of example-topology specified the parents
for the Bayes net example-network. Using the procedure (bayes-net-parents bayes-net node),
verify the parents of nodes B, C, and D. (Recall that a node
is referred to by an integer.)
- The procedure (bayes-net-children bayes-net node)
also allows us to find the children of a node. Verify that
this procedure gives the children of nodes A, B, and C.
- At some point node B may want to send an individual message to
node C. To do this, it would need to collect messages from all
its other children. Write an expressiong using the procedure
(delete num lst) along with procedure
bayes-net-children to find the list of all B's children
besides C.
B: Basic Messages
- Define an simple example of an observation where node C is observed
to be true and node A is observed to be false.
-
(define example-evidence _________________)
- Determine (or confirm) how many values the node A can take on by
using the procedure (bayes-net-node-size bayes-net node).
- Suppose we are sending a message from the children of node A. Because
it is observed, there are no complex calculations to instead, we simple
create what's called a "point distribution"-that is, a message
with a one at the observed value and zero everywhere else.
The procedure (point-distribution index len)
creates a message of length len with a 1
at index and 0 at every other position. Using
bayes-net-node-size, point-distribution, and Scheme's
assoc procedures with the example-evidence, write
an expression that creates the necessary message for observed value
of A.
-
(define message-from-A-observed __________)
- Another case we will need to handle is gathering messages from the
children of node D. Because D has no children, the message would
be a normalized uniform message. The procedure (normalize numbers)
takes a list of numbers and returns a new list that sums to one and
(ones len) creates a list of ones
of the given length. Using the procedures bayes-net-node-size,
ones, and normalize, create the normalized uniform
message for node D.
-
(define message-from-D-children ____________)
C: Message Products
Node B needs to send a message to node C, which is the pi message
from B to C.
- To calculate that message, we first need the pi message from B's
parents. Use the procedure (mesg-from-parents bayes-net node evidence)
to get this message.
-
(define message-from-B-parents ______________)
- The message from B to C is the product of the message from B's
parents and the messages from B's other children. Use the procedure
(mesg-to-parent bayes-net child parent evidence)
to calculate the message from D to B.
-
(define message-from-D-to-B __________________)
- The procedure (pointwise-product list-of-lists)
takes a list of lists of numbers and returns a list whose first entry
is the product of the first entries of all the lists, the second entry
is the product of the second entries of all the lists, etc. Use pointwise-product
to calculate the total message from B to C.
- [Optional] What if B had other children besides C and D?
The product would need to be over not only the message from B's
parents, but over messages from D as well as the other children
(excluding C). Use map and delete along with
pointwise-product and mesg-to-parent to write an
expression that would correctly calculate the message from B to
C in the event that B did have additional children.
Lab Assignment
Between this lab and snippets in the assignment document, you now
have nearly all the pieces necessary to implement your own network
and complete the belief propagation algorithm implementation.
Open belief-propagation.scm and study the documentation for
compute-belief, mesg-from-children, and mesg-to-child.
When these are clear, proceed to begin the lab's assignment.
Copyright © 2011 Jerod
Weinman.
This work is licensed under a Creative
Commons Attribution-Noncommercial-Share Alike 3.0 United States License.