CS 188, Fall 2005, Introduction to Artificial Intelligence
Assignment 5 Part 2, due 11/28, total value 4.8% of grade

This assignment should be done in pairs. Don't leave it to the last minute! Consult early and often with me and/or your TA.

The CS188 AIMA code has been updated to include data structures and algorithms for DBNs; a number of minor changes have been made elsewhere. Be sure to use the latest version from ~cs188. As always, remember to compile the code after loading aima.lisp. Then do (aima-load 'probability). You will also need a copy of a5-extra.lisp.

WARNING: this is all new code; it may lack clarity and may contain bugs. Check the newsgroup frequently for updates.

The AIMA code includes a general facility for defining and using DBNs, which are actually represented as a form of BNs with extra slots to specify which nodes belong to which slices. Code defining DBNs and all the basic operations on them (including I/O) appears in

This file also includes code for converting a DBN into an unrolled BN. There is also an algorithm for filtering by unrolling; see

Fun with little DBNs

Question 1 (5 pts). A DBN can be constructed using the interactive function create-dbn. Use this function to build the umbrella network shown in Fig. 15.2. Notice that you do not supply the subscripts for variable names; these are generated automatically. (It will ask you for the parents of UMBRELLA_0; since we do not usually supply values for variables in slice 0 that do not have children in slice 1, it is OK to leave UMBRELLA_0 without parents, thereby disconnecting it from the network.) Save the resulting network to a file called "umbrella.dbn". Display the network using display-bayes-net and include the output in your submission.

Question 2 (5 pts). Use unroll-dbn to unroll this DBN up to t=2. Again, note that subscripted variables for all time slices are created automatically. Show the application of an exact BN inference algorithm to appropriate evidence vectors to compute the probability of

These should agree with the numbers given on the slides for Chapter 15.

Question E1 (5 pts extra credit). Write a function (unroll-smooth-by-name Xname e_0-to-k dbn), analogous to unroll-filter-by-name in dbn-inference.lisp. It should return a list of posterior distributions P(X_i|e_0-to-k) for i=0...k.

Fun with mazes

Question 3 (10 pts). In a5-extra.lisp there is code for dealing with mazes. A maze is an array in which each element is a list of the directions in which movement is *possible*. You can get a better idea of what a maze looks like by doing, e.g., (print-maze-posterior nil *maze10x10*) and ignoring the nils. Given a maze, we can define a DBN that describes movement and perception in that maze. The state variable is the agent's position (an xy pair). The agent's actions are observable and chosen uniformly at random from (up down left right). The "geography" of the maze is implicit in the CPT for position_{t+1} given position_t and action_t; for example, if there is a wall between (0 1) and (1 1), as in *maze2x2*, then moving right from (0 1) won't reach (1 1). Movement *occurs* according to the standard stochastic model [2e p 614]: with probability (1- p_fail) motion occurs in the intended direction, and with probability p_fail/2 motion occurs in each of the perpendicular directions; but in either case, if the actual motion goes into a wall, the agent stays put. (On p614, then, p_fail is 0.2.) The agent's perception is very limited, consisting only of the *number* of detected adjacent walls, where each actual adjacent wall is missed with probability p_miss. The function maze->dbn constructs a DBN from a given maze. Two parts are missing. They construct appropriate CPT entries for the percept and position variables:

Complete these functions. With the completed code, make a DBN for *maze2x2* and display it.

Question E2 (5 pts extra credit). Suppose that, in addition to the wall detection failure probability p_miss, there is a wall detection false alarm probability p_false. Derive and implement a formula for the percept distribution; check that it reproduces the original formula when p_false is zero.

Question 4 (5 pts). Unroll your 2x2 maze DBN for 10 time steps, and use unroll-filter-by-name to get the list of filtered distributions given the evidence vector *maze2x2-e10*. Display these by applying print-maze-posterior to each distribution. You should see that the position is quite accurately known by step 10.

Question 5 (5 pts). Can the position ever become known with certainty in this maze, for some percept/action sequence, given an initial uniform distribution? Explain; optionally, demonstrate if possible.

Fun with particles

Question 6 (20 pts). a5-extra.lisp also contains partially completed code for the particle filtering algorithm. This algorithm operates directly with the DBN without unrolling it. Each particle is a vector of values for the variables in slices 0 and 1, or, more generally, slices i-1 and i, where i is the current time step in the filtering process. The life cycle of each particle is as follows:

Two parts are missing. They construct appropriate CPT entries for the percept and position variables: Complete these functions and apply particle-filter-by-name to your 2x2 maze DBN for 10 time steps with 100 particles to get the list of filtered distributions given the evidence vector *maze2x2-e10*. Display these by applying print-maze-posterior to each distribution. You should see that the results are close to the exact values computed in Q.4.

Question 7 (5 pts). The last function in a5-extra.lisp is test-filter. Use it to plot the error as a function of time step for likelihood weighting and particle filtering, with 10, 100, and 1000 samples, averaged over 10 trials, applied to the 2x2 maze DBN with evidence given by *maze2x2-e10*. (You may wish to use q7.gnuplot via the command "gnuplot q7.gnuplot", in which case the file-prefixes supplied to test-filter should be "lw-maze2x2-10step-" and "pf-maze2x2-10step-" for likelihood weighting and particle filtering respectively; the output will be q7.ps.) Comment on the results.

Question E3 (10-15 pts extra credit). Devise and implement a function (N-random-from-discrete N d) that generates N samples from discrete distribution d in expected time O(N log N) (for 10 points) or O(N) (for 15 points, if you include a proof of the O(N) complexity). With your improvements, you should be able to repeat the experiments in Q.7 using the 10x10 maze up to 100 time steps. (You will need to generate some evidence; do this by unrolling the DBN, calling prior-sample in probability/algorithms/bn-approx-inference.lisp to generate a complete event, and then calling hide-vars in probability/domains/bayes-nets.lisp to hide the position variable.