Chapter 15: Probabilistic Programming — Exercises
Chapter 15: Probabilistic Programming¶
Russell & Norvig, Artificial Intelligence: A Modern Approach (4th ed.), end-of-chapter Exercise prompts — full text is included on this site (same material as the exercises/ch15/ sources in the aima monorepo).
Exercise 15.1¶
Show that any second-order Markov process can be rewritten as a first-order Markov process with an augmented set of state variables. Can this always be done parsimoniously, i.e., without increasing the number of parameters needed to specify the transition model?
Exercise 15.2¶
In this exercise, we examine what
happens to the probabilities in the umbrella world in the limit of long
time sequences.
Suppose we observe an unending sequence of days on which the umbrella appears. Show that, as the days go by, the probability of rain on the current day increases monotonically toward a fixed point. Calculate this fixed point.
Now consider forecasting further and further into the future, given just the first two umbrella observations. First, compute the probability for and plot the results. You should see that the probability converges towards a fixed point. Prove that the exact value of this fixed point is 0.5.
Exercise 15.3¶
This exercise develops a space-efficient variant of
the forward–backward algorithm described in
Figure forward
Suppose, for simplicity, that is odd, and let the halfway point be . Show that can be computed for given just the initial forward message , the backward message , and the evidence .
Show a similar result for the second half of the sequence.
Given the results of (a) and (b), a recursive divide-and-conquer algorithm can be constructed by first running forward along the sequence and then backward from the end, storing just the required messages at the middle and the ends. Then the algorithm is called on each half. Write out the algorithm in detail.
Compute the time and space complexity of the algorithm as a function of , the length of the sequence. How does this change if we divide the input into more than two pieces?
Exercise 15.4¶
On page flawed-viterbi-page, we outlined a flawed procedure for finding the most likely state sequence, given an observation sequence. The procedure involves finding the most likely state at each time step, using smoothing, and returning the sequence composed of these states. Show that, for some temporal probability models and observation sequences, this procedure returns an impossible state sequence (i.e., the posterior probability of the sequence is zero).
Exercise 15.5¶
Equation (matrix
Exercise 15.6¶
Consider the vacuum worlds of
Figure vacuum
Exercise 15.7¶
In Section hmm
Exercise 15.8¶
Consider a version of the vacuum robot
(page vacuum
Exercise 15.9¶
We have described three policies for the vacuum robot: (1) a uniform
random walk, (2) a bias for wandering southeast, as described in
Exercise hmm-robust-exercise, and (3) the policy
described in Exercise roomba
Exercise 15.10¶
This exercise is concerned with filtering in an environment with no landmarks. Consider a vacuum robot in an empty room, represented by an rectangular grid. The robot’s location is hidden; the only evidence available to the observer is a noisy location sensor that gives an approximation to the robot’s location. If the robot is at location then with probability .1 the sensor gives the correct location, with probability .05 each it reports one of the 8 locations immediately surrounding , with probability .025 each it reports one of the 16 locations that surround those 8, and with the remaining probability of .1 it reports “no reading.” The robot’s policy is to pick a direction and follow it with probability .8 on each step; the robot switches to a randomly selected new heading with probability .2 (or with probability 1 if it encounters a wall). Implement this as an HMM and do filtering to track the robot. How accurately can we track the robot’s path?
Exercise 15.11¶
This exercise is concerned with filtering in an environment with no landmarks. Consider a vacuum robot in an empty room, represented by an rectangular grid. The robot’s location is hidden; the only evidence available to the observer is a noisy location sensor that gives an approximation to the robot’s location. If the robot is at location then with probability .1 the sensor gives the correct location, with probability .05 each it reports one of the 8 locations immediately surrounding , with probability .025 each it reports one of the 16 locations that surround those 8, and with the remaining probability of .1 it reports “no reading.” The robot’s policy is to pick a direction and follow it with probability .7 on each step; the robot switches to a randomly selected new heading with probability .3 (or with probability 1 if it encounters a wall). Implement this as an HMM and do filtering to track the robot. How accurately can we track the robot’s path?
A Bayesian network representation of a switching Kalman filter. The switching variable $S_t$ is a discrete state variable whose value determines the transition model for the continuous state variables $\textbf{X}_t$. For any discrete state $\textit{i}$, the transition model $\textbf{P}(\textbf{X}_{t+1}|\textbf{X}_t,S_t= i)$ is a linear Gaussian model, just as in a regular Kalman filter. The transition model for the discrete state, $\textbf{P}(S_{t+1}|S_t)$, can be thought of as a matrix, as in a hidden Markov model.
Exercise 15.12¶
Often, we wish to monitor a continuous-state
system whose behavior switches unpredictably among a set of distinct
“modes.” For example, an aircraft trying to evade a missile can execute
a series of distinct maneuvers that the missile may attempt to track. A
Bayesian network representation of such a switching Kalman filter model is shown in
Figure switching-kf-figure.
Suppose that the discrete state has possible values and that the prior continuous state estimate is a multivariate Gaussian distribution. Show that the prediction is a mixture of Gaussians—that is, a weighted sum of Gaussians such that the weights sum to 1.
Show that if the current continuous state estimate is a mixture of Gaussians, then in the general case the updated state estimate will be a mixture of Gaussians.
What aspect of the temporal process do the weights in the Gaussian mixture represent?
The results in (a) and (b) show that the representation of the posterior grows without limit even for switching Kalman filters, which are among the simplest hybrid dynamic models.
Exercise 15.13¶
Complete the missing step in the derivation
of Equation (kalman
Exercise 15.14¶
Let us examine the behavior of the variance
update in Equation (kalman
Plot the value of as a function of , given various values for and .
Show that the update has a fixed point such that as , and calculate the value of .
Give a qualitative explanation for what happens as and as .
Exercise 15.15¶
A professor wants to know if students are getting
enough sleep. Each day, the professor observes whether the students
sleep in class, and whether they have red eyes. The professor has the
following domain theory:
The prior probability of getting enough sleep, with no observations, is 0.7.
The probability of getting enough sleep on night is 0.8 given that the student got enough sleep the previous night, and 0.3 if not.
The probability of having red eyes is 0.2 if the student got enough sleep, and 0.7 if not.
The probability of sleeping in class is 0.1 if the student got enough sleep, and 0.3 if not.
Formulate this information as a dynamic Bayesian network that the
professor could use to filter or predict from a sequence of
observations. Then reformulate it as a hidden Markov model that has only
a single observation variable. Give the complete probability tables for
the model.
Exercise 15.16¶
A professor wants to know if students are getting
enough sleep. Each day, the professor observes whether the students
sleep in class, and whether they have red eyes. The professor has the
following domain theory:
The prior probability of getting enough sleep, with no observations, is 0.7.
The probability of getting enough sleep on night is 0.8 given that the student got enough sleep the previous night, and 0.3 if not.
The probability of having red eyes is 0.2 if the student got enough sleep, and 0.7 if not.
The probability of sleeping in class is 0.1 if the student got enough sleep, and 0.3 if not.
Formulate this information as a dynamic Bayesian network that the
professor could use to filter or predict from a sequence of
observations. Then reformulate it as a hidden Markov model that has only
a single observation variable. Give the complete probability tables for
the model.
Exercise 15.17¶
For the DBN specified in Exercise sleep1-exercise and
for the evidence values
perform the following computations:
State estimation: Compute for each of .
Smoothing: Compute for each of .
Compare the filtered and smoothed probabilities for and .
Exercise 15.18¶
Suppose that a particular student shows up with red eyes and sleeps in class every day. Given the model described in Exercise sleep1-exercise, explain why the probability that the student had enough sleep the previous night converges to a fixed point rather than continuing to go down as we gather more days of evidence. What is the fixed point? Answer this both numerically (by computation) and analytically.
Exercise 15.19¶
This exercise analyzes in more detail the
persistent-failure model for the battery sensor in
Figure battery
Figure battery
-persistence -figure(b) stops at . Describe qualitatively what should happen as if the sensor continues to read 0. Suppose that the external temperature affects the battery sensor in such a way that transient failures become more likely as temperature increases. Show how to augment the DBN structure in Figure battery
-persistence -figure(a), and explain any required changes to the CPTs. Given the new network structure, can battery readings be used by the robot to infer the current temperature?
Exercise 15.20¶
Consider applying the variable elimination algorithm to the umbrella DBN unrolled for three slices, where the query is . Show that the space complexity of the algorithm—the size of the largest factor—is the same, regardless of whether the rain variables are eliminated in forward or backward order.