Exercises: Chapter 4
Exercise 4.1: Causal and Statistical Dependency
For each of the following programs:
- Draw the dependency diagram as a Bayes Net. If you don’t have software on your computer for doing this, Google Docs has a decent interface for creating drawings.
- Use informal evaluation order reasoning and the intervention method to determine causal dependency between
AandB. - Use conditioning to determine whether
AandBare statistically dependent.
Question 4.1.1
var A = flip()
var B = flip()
var C = flip(A && B ? .8 : .5)Question 4.1.2
var A = flip()
var B = flip(A ? .9 : .2)
var C = flip(B ? .7 : .1)Question 4.1.3
var a = flip()
var b = flip(a ? .9 : .2)
var c = flip(a ? .7 : .1)Question 4.1.4
var A = flip(.6);
var C = flip(.1);
var Z = flip() ? A : C;
var B = Z ? 'foo' : 'bar';Question 4.1.5
var examFairPrior = Bernoulli({p: .8})
var doesHomeworkPrior = Bernoulli({p: .8})
var examFair = mem(
function(exam) {
return sample(examFairPrior)
}
)
var doesHomework = mem(
function(student) {
return sample(doesHomeworkPrior)
}
)
var pass = function(student, exam) {
return flip(
examFair(exam)
? (doesHomework(student) ? .9 : .5)
: (doesHomework(student) ? .2 : .1)
)
}
var A = pass('alice', 'historyExam');
var B = pass('bob', 'historyExam');Exercise 4.2: Probabilistic Programs Without Corresponding Graphical Models
As the end of the chapter mentions, some probabilistic programs do not have corresponding graphical models. This includes programs with recursion. The example below is an example of a recursive probabilistic program:
// Compute total rainfall over the
// course of a storm
var totalRain = function() {
// Amount of rainfall today
var dailyRainfall = sample(
Gaussian({
mu: 5,
sigma: 1
})
)
// If it rained a lot today,
// the storm is likely to continue
if (
(dailyRainfall > 6 && flip(0.8))
|| flip(0.3)
) {
return dailyRainfall + totalRain()
} else {
return dailyRainfall
}
}
viz(
Infer({
model: totalRain,
method: "forward"
})
)Question 4.2.1
Write another recursive probabilistic program to model some real-world phenomenon below:
// Your code here