c)

Given that all three flips landed on heads, what is the probability that the coin was biased?

d)

Given that the first two flips were different, what is the probability that the third flip will be heads?

Exercise 2: Conditioning and Intervention

In the earlier Medical Diagnosis section we suggested understanding the patterns of symptoms for a particular disease by changing the prior probability of the disease such that it is always true (also called the do operator).

a)

For this example, does intervening on the program in this way (e.g. by setting the value of lungCancer) have the same effect as conditioning on the disease being true? What about the casual dependency makes this case?

b)

Why would intervening have a different effect than conditioning for more general hypotheticals? Construct an example where they differ. Then translate this into a WebPPL model and show that manipulating the prior gives different answers than manipulating the observation. Hint: think about the effect that intervening vs. conditioning on a variable that has a causal parent would have on that parent.

Exercise 3: Computing marginals

Use the rules for computing probabilities to compute the marginal distribution on return values from these programs by hand (use viz() to check your answers):

c)

Suppose you’ve seen Bob five times this week and each time, he was not smiling. But today, you see Bob and he is smiling.
Use this extendedSmilesModel model to compute the posterior belief that Bob wants something from you today.

Hint: How will you represent the same person (Bob) smiling multiple times?
What features of Bob will stay the same each time he smiles (or doesn’t) and what features will change?

In your answer, show the WebPPL inference and a histogram of the answers – in what ways do these answers make intuitive sense or fail to?

a)

I have a particularly bad model of the sprinkler in my garden.
It is supposed to water my grass every morning, but is turns on only half the time (at random, as far as I can tell).
Fortunately, I live in a city where it also rains 30% of days.

One day I check my lawn and see that it is wet, meaning that either it rained that morning or my sprinkler turned on (or both).

Answer the following questions, either using the Rules of Probability or by writing your own sprinkler model in webppl.

What is the probability that it rained?

What is the probability that my sprinkler turned on?

c)

My neighbour Kelsey, who has the same kind of sprinkler, tells me that her lawn was also wet that same morning.
What is the new posterior probability that it rained?

d)

To investigate further we poll a selection of our friends who live nearby, and ask if their grass was wet this morning.
Kevin and Manu and Josh, each with the same sprinkler, all agree that their lawns were wet too.
Using mem, write a model to reason about arbitrary numbers of people, and then use it to find the new probability that it rained.

Exercise 5: Casino game

Consider the following game.
A machine randomly gives Bob a letter of the word “game”; it gives a, e (the vowels) with probability 0.45 each and the remaining letters (the consonants g, m) with probability 0.05 each.
The probability that Bob wins depends on which letter he got.
Letting denote the letter and letting denote the numeric position of that letter in the word “game” (e.g., , and so on), the probability of winning is .

Suppose that we observe Bob winning but we don’t know what letter he got.
How can we use the observation that he won to update our beliefs about which letter he got?
Let’s express this formally.
Before we begin, a bit of terminology: the set of letters that Bob could have gotten, , is called the hypothesis space – it’s our set of hypotheses about the letter.

a)

In English, what does the posterior probability represent?

b)

Manually compute for each hypothesis.
Remember to normalize — make sure that summing all your values gives you 1.

g

0.05

a

0.45

m

0.05

e

0.45

d)

Now, we’re going to write this model in WebPPL using Infer. Here is some starter code for you:

Fill in the ...’s in the code to compute .
Include a screenshot of the resulting graph.
What letter has the highest posterior probability?
In English, what does it mean that this letter has the highest posterior?
It might be interesting to comment out the condition statement so you can compare visually the prior (no condition statement) to the posterior (with condition).

Make sure that your WebPPL answers and hand-computed answers agree – note that this demonstrates the equivalence between the program view of conditional probability and the distributional view.

e)

Which is higher, or ?
Answer this using the WebPPL code you wrote Hint: use the checkVowel function.