Skip to content

Commit cf19759

Browse files
committed
Add likelihood-weighting markdown.
1 parent 9f28ec7 commit cf19759

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ The file [aima3e-algorithms.pdf](https://github.com/aimacode/pseudocode/blob/mas
237237
<td align="center"></td>
238238
<td><a href="md/Rejection-Sampling.md">REJECTION-SAMPLING</a></td>
239239
</tr>
240+
<tr>
241+
<td align="center">&bull;</td>
242+
<td align="center"></td>
243+
<td><a href="md/Likelihood-Weighting.md">LIKELIHOOD-WEIGHTING</a></td>
244+
</tr>
240245
<tr>
241246
<td align="center">&bull;</td>
242247
<td align="center"></td>

md/Likelihood-Weighting.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# LIKELIHOOD-WEIGHTING
2+
3+
## AIMA3e
4+
__function__ LIKELIHOOD-WEIGHTING(_X_, __e__, _bn_, _N_) __returns__ an estimate of __P__(_X_ &vert; __e__)
5+
&emsp;__inputs__: _X_, the query variable
6+
&emsp;&emsp;&emsp;&emsp;&emsp;__e__, observed values for variables __E__
7+
&emsp;&emsp;&emsp;&emsp;&emsp;_bn_, a Bayesian network specifying joint distribution __P__(_X<sub>1</sub>_, &hellip;, _X<sub>n</sub>_)
8+
&emsp;&emsp;&emsp;&emsp;&emsp;_N_, the total number of samples to be generated
9+
&emsp;__local variables__: __W__, a vector of weighted counts for each value of _X_, initially zero
10+
11+
&emsp;__for__ _j_ = 1 to _N_ __do__
12+
&emsp;&emsp;&emsp;__x__, _w_ &larr; WEIGHTED\-SAMPLE(_bn_, __e__)
13+
&emsp;&emsp;&emsp;__W__\[_x_\] &larr; __W__\[_x_\] &plus; _w_ where _x_ is the value of _X_ in __x__
14+
&emsp;__return__ NORMALIZE(__W__)
15+
16+
---
17+
__function__ WEIGHTED\-SAMPLE(_bn_, __e__) __returns__ an event and a weight
18+
&emsp;_w_ &larr; 1; __x__ &larr; an event with _n_ elements initialized from __e__
19+
&emsp;__foreach__ variable _X<sub>i</sub>_ __in__ _X<sub>1</sub>_, &hellip;, _X<sub>n</sub>_ __do__
20+
&emsp;&emsp;&emsp;__if__ _X<sub>i</sub>_ is an evidence variable with value _x<sub>i</sub>_ in __e__
21+
&emsp;&emsp;&emsp;&emsp;&emsp;__then__ _w_ &larr; _w_ &times; _P_(_X<sub>i</sub>_ = _x<sub>i</sub>_ &vert; _parents_(_X<sub>i</sub>_))
22+
&emsp;&emsp;&emsp;&emsp;&emsp;__else__ __x__\[i\] &larr; a random sample from __P__(_X<sub>i</sub>_ &vert; _parents_(_X<sub>i</sub>_))
23+
&emsp;__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

Comments
 (0)