程序代写 Prior sampling

Prior sampling
Let’s use stochastic sampling instead!
⃝c -Trenn, King’s College London 2

Prior sampling
How would you estimate P pc, ␣s, r, wq?
⃝c -Trenn, King’s College London 3

Take a step back
How would you estimate P pdie shows 7q?
⃝c -Trenn, King’s College London 4

Stochastic simulation
How would you estimate P pdie shows 7q?
Simple: you take n random samples from the network
Let Xi be the binary r.v. that is 1 if the event sampled in the ith run is 7 Simply output
řn Xi Pˆ p 7 q “ i “ 1
n Law of large numbers says that limnÑ8 Pˆ “ P .
⃝c -Trenn, King’s College London 5

Stochastic simulation
Back to our Bayesian network with cloudy, sprinkler, rain, and wet grass.
How would you estimate P pc, ␣s, r, wq?
⃝c -Trenn, King’s College London 6

Stochastic simulation
Back to our Bayesian network with cloudy, sprinkler, rain, and wet grass.
How would you estimate P pc, ␣s, r, wq?
Simple you just take say n random samples from the network
Let Xi be the binary r.v. that is 1 if the event sampled in the ith run is c, ␣s, r, w Simply output
Xi
n Law of large numbers says that limnÑ8 Pˆ “ P .
⃝c -Trenn, King’s College London
7
řn Pˆpc, ␣s, r, wq “ i“1

Prior sampling. Let’s generate a random sample!
⃝c -Trenn, King’s College London 8

Prior sampling.
List of randomly generated numbers: 0.4, 0.2, 0.71, 0.2 for this run. We have 0.4 small than PpCq, so Cloudy “ true
⃝c -Trenn, King’s College London 9

Prior sampling
⃝c -Trenn, King’s College London 10

Prior sampling
List of randomly generated numbers: 0.4, 0.2, 0.71, 0.2 for this run We have 0.2 ě PpS | Cq and hence, Sprinkler “ false.
⃝c -Trenn, King’s College London 11

Prior sampling
List of randomly generated numbers: 0.4, 0.2, 0.71, 0.2 for this run. We have 0.71 ă PpR | Cq and hence, Rain “ true
⃝c -Trenn, King’s College London 12

Prior sampling
⃝c -Trenn, King’s College London 13

Prior sampling
List of randomly generated numbers: 0.4, 0.2, 0.71, 0.2 for this run. We have 0.2 ă PpW | S,Rq and hence, WetGrass “ true
⃝c -Trenn, King’s College London 14

Prior sampling
So, this time we get the event
rCloudy “ true,Sprinkler “ false,Rain “ true,WetGrass “ trues Will write this:
rtrue, f alse, true, trues
⃝c -Trenn, King’s College London
15

Prior sampling
If we repeat the process many times, we can count the number of times rtrue, f alse, true, trues is the result.
The proportion of this to the total number of runs is:
Ppc,␣s,r,wq The more runs, the more accurate the probability.
Similarly for other joint probabilities.
⃝c -Trenn, King’s College London 16

Prior sampling
function PRIOR-SAMPLE(bn) returns an event sampled from bn inputs: bn, a belief network specifying joint distribution
PpX1,…,Xnq
x Ð an event with n elements fori “ 1tondo
xi Ð a random sample from PpXi | parentspXiqq given the values of ParentspXiq in x
return x
⃝c -Trenn, King’s College London 17

Prior sampling limitation
How would you get the following marginal distribution?
PpX |eq
⃝c -Trenn, King’s College London
18