Skip to content

Commit 9ff7b46

Browse files
committed
* 'master' of https://github.com/aimacode/aima-pseudocode: Update README.md Add prior-sample and rejection-sampling markdowns. Add Hybrid-Wumpus-Agent markdown
2 parents 6a2a9fd + 0ca74f2 commit 9ff7b46

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ The file [aima3e-algorithms.pdf](https://github.com/aimacode/pseudocode/blob/mas
170170
<td align="center"></td>
171171
<td><a href="md/WalkSAT.md">WALKSAT</a></td>
172172
</tr>
173+
<tr>
174+
<td align="center">&bull;</td>
175+
<td align="center"></td>
176+
<td><a href="md/Hybrid-Wumpus-Agent.md">HYBRID-WUMPUS-AGENT</a></td>
177+
</tr>
173178
<tr>
174179
<td align="center">&bull;</td>
175180
<td align="center"></td>
@@ -217,6 +222,16 @@ The file [aima3e-algorithms.pdf](https://github.com/aimacode/pseudocode/blob/mas
217222
<td align="center"></td>
218223
<td><a href="md/Elimination-Ask.md">ELIMINATION-ASK</a></td>
219224
</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>
220235
<tr>
221236
<td align="center">&bull;</td>
222237
<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/Hybrid-Wumpus-Agent.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# HYBRID-WUMPUS-AGENT
2+
3+
## AIMA3e
4+
__function__ HYBRID-WUMPUS-AGENT(_percept_) __returns__ an _action_
5+
&emsp;__inputs__: _percept_, a list, \[_stench_, _breeze_, _glitter_, _bump_, _scream_\]
6+
&emsp;__persistent__: _KB_, a knowledge base, initially the atemporal "wumpus physics"
7+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;_t_, a counter, initially 0, indicating time
8+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;_plan_, an action sequence, initially empty
9+
10+
&emsp;TELL(_KB_, MAKE-PERCEPT-SENTENCE(_percept_, _t_))
11+
&emsp;TELL the _KB_ the temporal "physics" sentences for time _t_
12+
&emsp;_safe_ &larr; {\[_x_, _y_\] : ASK(_KB_, _OK_<sup>_t_</sup><sub>_x_,_y_</sub>) = _true_}
13+
&emsp;__if__ ASK(_KB_, _Glitter_<sup>_t_</sup>) = _true_ __then__
14+
&emsp;&emsp;&emsp;_plan_ &larr; \[_Grab_\] + PLAN-ROUTE(_current_, {\[1,1\]}, _safe_) + \[_Climb_\]
15+
&emsp;__if__ _plan_ is empty __then__
16+
&emsp;&emsp;&emsp;_unvisited_ &larr; {\[_x_, _y_\] : ASK(_KB_, _L_<sup>_t'_</sup><sub>_x_,_y_</sub>) = _false_ for all _t'_ &le; _t_}
17+
&emsp;&emsp;&emsp;_plan_ &larr; PLAN-ROUTE(_current_, _unvisited_ &cap; _safe_, _safe_)
18+
&emsp;__if__ _plan_ is empty and ASK(_KB_, _HaveArrow_<sup>_t_</sup>) = _true_ __then__
19+
&emsp;&emsp;&emsp;_possible\_wumpus_ &larr; {\[_x_, _y_\] : ASK(_KB_, &not;_W_<sub>_x_,_y_</sub>) = _false_}
20+
&emsp;&emsp;&emsp;_plan_ &larr; PLAN-SHOT(_current_, _possible\_wumpus_, _safe_)
21+
&emsp;__if__ _plan_ is empty __then__ //no choice but to take a risk
22+
&emsp;&emsp;&emsp;_not\_unsafe_ &larr; {\[_x_, _y_\] : ASK(_KB_, &not;_OK_<sup>_t_</sup><sub>_x_,_y_</sub>) = _false_}
23+
&emsp;&emsp;&emsp;_plan_ &larr; PLAN-ROUTE(_current_, _unvisited_ &cap; _not\_unsafe_, _safe_)
24+
&emsp;__if__ _plan_ is empty __then__
25+
&emsp;&emsp;&emsp;_plan_ &larr; PLAN-ROUTE(_current_, {\[1,1\]}, _safe_) + \[_Climb_\]
26+
&emsp;_action_ &larr; POP(_plan_)
27+
&emsp;TELL(_KB_, MAKE-ACTION-SENTENCE(_action_, _t_))
28+
&emsp;_t_ &larr; _t_ + 1
29+
&emsp;__return__ _action_
30+
31+
---
32+
__function__ PLAN-ROUTE(_current_, _goals_, _allowed_) __returns__ an action sequence
33+
&emsp;__inputs__: _current_, the agent's current position
34+
&emsp;&emsp;&emsp;&emsp;&emsp;_goals_, a set of squares; try to plan a route to one of them
35+
&emsp;&emsp;&emsp;&emsp;&emsp;_allowed_, a set of squares that can form part of the route
36+
37+
&emsp;_problem_ &larr; ROUTE-PROBLEM(_current_, _goals_, _allowed_)
38+
&emsp;__return__ A\*\-GRAPH-SEARCH(_problem_)
39+
40+
__Figure__ ?? A hybrid agent program for the wumpus world. It uses a propositional knowledge base to infer the state of the world, and a combination of problem-solving search and domain-specific code to decide what actions to take.

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)