Skip to content

Commit e1cc0cc

Browse files
committed
Add prior-sample and rejection-sampling markdowns.
Additional, minor layout tidy up in elimination-ask.
1 parent 9041168 commit e1cc0cc

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ The file [aima3e-algorithms.pdf](https://github.com/aimacode/pseudocode/blob/mas
222222
<td align="center"></td>
223223
<td><a href="md/Elimination-Ask.md">ELIMINATION-ASK</a></td>
224224
</tr>
225+
<tr>
226+
<td align="center">&bull;</td>
227+
<td align="center"></td>
228+
<td><a href="md/Prior-Sample.md">PRIOR-SAMPLE</a></td>
229+
</tr>
230+
<tr>
231+
<td align="center">&bull;</td>
232+
<td align="center"></td>
233+
<td><a href=md/Rejection-Sampling.md"">REJECTION-SAMPLING</a></td>
234+
</tr>
225235
<tr>
226236
<td align="center">&bull;</td>
227237
<td align="center"></td>

md/Elimination-Ask.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ __function__ ELIMINATION-ASK(_X_, __e__, _bn_) __returns__ a distribution over _
1010
&emsp;__for each__ _var_ __in__ ORDER(_bn_.VARS) __do__
1111
&emsp;&emsp;&emsp;_factors_ &larr; \[MAKE\-FACTOR(_var_, __e__) &vert; _factors_\]
1212
&emsp;&emsp;&emsp;__if__ _var_ is a hidden variable __then__ _factors_ &larr; SUM\-OUT(_var_, _factors_)
13-
__return__ NORMALIZE(POINTWISE\-PRODUCT(_factors_))
13+
&emsp;__return__ NORMALIZE(POINTWISE\-PRODUCT(_factors_))
1414

1515
---
1616
__Figure__ ?? The variable elimination algorithm for inference in Bayesian networks.

md/Prior-Sample.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# PRIOR-SAMPLE
2+
3+
## AIMA3e
4+
__function__ PRIOR-SAMPLE(_bn_) __returns__ an event sampled from the prior specified by _bn_
5+
&emsp;__inputs__: _bn_, a Bayesian network specifying joint distribution __P__(_X<sub>1</sub>_, &hellip;, _X<sub>n</sub>_)
6+
7+
&emsp;__x__ &larr; an event with _n_ elements
8+
&emsp;__foreach__ varaible _X<sub>i</sub>_ __in__ _X<sub>1</sub>_, &hellip;, _X<sub>n</sub>_ __do__
9+
&emsp;&emsp;&emsp;_x_\[_i_\] &larr; a random sample from __P__(_X<sub>i</sub>_ &vert; _parents_(_X<sub>i</sub>_))
10+
&emsp;__return x__
11+
12+
---
13+
__Figure__ ?? A sampling algorithm that generates events from a Bayesian network. Each variable is sampled according to the conditional distribution given the values already sampled for the variable's parents.

md/Rejection-Sampling.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# REJECTION-SAMPLING
2+
3+
## AIMA3e
4+
__function__ REJECTION-SAMPLING(_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
8+
&emsp;&emsp;&emsp;&emsp;&emsp;_N_, the total number of samples to be generated
9+
&emsp;__local variables__: __N__, a vector of counts for each value of _X_, initially zero
10+
11+
&emsp;__for__ _j_ = 1 to _N_ __do__
12+
&emsp;&emsp;&emsp;__x__ &larr; PRIOR\-SAMPLE(_bn_)
13+
&emsp;&emsp;&emsp;__if x__ is consistent with __e then__
14+
&emsp;&emsp;&emsp;&emsp;&emsp;__N__\[_x_\] &larr; __N__\[_x_\] &plus; 1 where _x_ is the value of _X_ in __x__
15+
&emsp;__return__ NORMALIZE(__N__)
16+
17+
---
18+
__Figure__ ?? The rejection\-sampling algorithm for answering queries given evidence in a Bayesian network.

0 commit comments

Comments
 (0)