|
| 1 | +# LIKELIHOOD-WEIGHTING |
| 2 | + |
| 3 | +## AIMA3e |
| 4 | +__function__ LIKELIHOOD-WEIGHTING(_X_, __e__, _bn_, _N_) __returns__ an estimate of __P__(_X_ | __e__) |
| 5 | + __inputs__: _X_, the query variable |
| 6 | +     __e__, observed values for variables __E__ |
| 7 | +     _bn_, a Bayesian network specifying joint distribution __P__(_X<sub>1</sub>_, …, _X<sub>n</sub>_) |
| 8 | +     _N_, the total number of samples to be generated |
| 9 | + __local variables__: __W__, a vector of weighted counts for each value of _X_, initially zero |
| 10 | + |
| 11 | + __for__ _j_ = 1 to _N_ __do__ |
| 12 | +   __x__, _w_ ← WEIGHTED\-SAMPLE(_bn_, __e__) |
| 13 | +   __W__\[_x_\] ← __W__\[_x_\] + _w_ where _x_ is the value of _X_ in __x__ |
| 14 | + __return__ NORMALIZE(__W__) |
| 15 | + |
| 16 | +--- |
| 17 | +__function__ WEIGHTED\-SAMPLE(_bn_, __e__) __returns__ an event and a weight |
| 18 | + _w_ ← 1; __x__ ← an event with _n_ elements initialized from __e__ |
| 19 | + __foreach__ variable _X<sub>i</sub>_ __in__ _X<sub>1</sub>_, …, _X<sub>n</sub>_ __do__ |
| 20 | +   __if__ _X<sub>i</sub>_ is an evidence variable with value _x<sub>i</sub>_ in __e__ |
| 21 | +     __then__ _w_ ← _w_ × _P_(_X<sub>i</sub>_ = _x<sub>i</sub>_ | _parents_(_X<sub>i</sub>_)) |
| 22 | +     __else__ __x__\[i\] ← a random sample from __P__(_X<sub>i</sub>_ | _parents_(_X<sub>i</sub>_)) |
| 23 | + __return__ __x__, _w_ |
| 24 | + |
| 25 | +--- |
| 26 | +__Figure__ ?? The likelihood\-weighting algorithm for inference in Bayesian networks. In WEIGHTED\-SAMPLE, each nonevidence variable is sampled according to the conditional distribution given the values already sampled for the variable's parents, while a weight is accumulated based on the likelihood for each evidence variable. |
0 commit comments