The canonical example is modeling a front lawn, whose grass may be wet because it rained or because the sprinkler was on. Since our knowledge is not perfect, we allow for 10% chance that the grass may be wet for some other reason. Also, if the rain was light, the grass might have dried up by the time we observe it; a sprinkler may too leave the grass dry if, say, water pressure was low. We admit these possibilities, assigning them probabilities 10% and 20%, respectively. Suppose we observe the grass is wet. What are the chances it rained?

The following is the model written as an OCaml program:

let grass_model () = (* unit -> bool *) let rain = flip 0.3 and sprinkler = flip 0.5 in let grass_is_wet = (flip 0.9 && rain) || (flip 0.8 && sprinkler) || flip 0.1 in if not grass_is_wet then fail (); rain

rain

sprinkler

[(0.3, true); (0.7, false)]

rain

[(0.5, true); (0.5, false)]

sprinkler

grass_is_wet

fail ()

grass_model

unit->bool

rain

sprinkler

grass_is_wet

flip

fail

run_model grass_model;; - : bool distrib = [(0.322, false); (0.2838, true)]

7/15