├── LICENSE.md ├── README.md ├── aima3e-algorithms.pdf ├── algorithms.pdf └── md ├── AC-3.md ├── AdaBoost.md ├── Adam-Optimizer.md ├── Air-Cargo-Transport-Problem.md ├── Alpha-Beta-Search.md ├── And-Or-Graph-Search.md ├── Angelic-Search.md ├── Append.md ├── Back-Prop-Learning-with-regularization.md ├── Back-Prop-Learning.md ├── Backtracking-Search.md ├── Blocks-World.md ├── Breadth-First-Search.md ├── CYK-Parse.md ├── Cross-Validation-Wrapper.md ├── Current-Best-Learning.md ├── DPLL-Satisfiable.md ├── DT-Agent.md ├── Decision-List-Learning.md ├── Decision-Tree-Learning.md ├── Depth-Limited-Search.md ├── Doubles-Tennis-Problem.md ├── Elimination-Ask.md ├── Enumeration-Ask.md ├── FOL-BC-Ask.md ├── FOL-FC-Ask.md ├── Fixed-Lag-Smoothing.md ├── Foil.md ├── Forward-Backward.md ├── Genetic-Algorithm.md ├── Gibbs-Ask.md ├── GraphPlan.md ├── Have-Cake-And-Eat-Cake-Too.md ├── Hierarchical-Search.md ├── Hill-Climbing.md ├── Hits.md ├── Hybrid-Wumpus-Agent.md ├── Information-Gathering-Agent.md ├── Iterative-Deepening-Search.md ├── Job-Shop-Scheduling-Problem.md ├── KB-Agent.md ├── LRTAStar-Agent.md ├── Likelihood-Weighting.md ├── Min-Conflicts.md ├── Minimal-Consistent-Det.md ├── Minimax-Decision.md ├── Model-Based-Reflex-Agent.md ├── Model-Selection.md ├── Monte-Carlo-Localization.md ├── Monte-Carlo-Tree-Search.md ├── Online-DFS-Agent.md ├── PL-FC-Entails.md ├── PL-Resolution.md ├── POMDP-Value-Iteration.md ├── Particle-Filtering.md ├── Passive-ADP-Agent.md ├── Passive-TD-Agent.md ├── Policy-Iteration.md ├── Powers-Of-2.md ├── Prior-Sample.md ├── Q-Learning-Agent.md ├── Random-Forest.md ├── Recursive-Best-First-Search.md ├── Refinement-High-Level-Actions.md ├── Reflex-Vacuum-Agent.md ├── Rejection-Sampling.md ├── SATPlan.md ├── Sentence-Tree.md ├── Simple-Problem-Solving-Agent.md ├── Simple-Reflex-Agent.md ├── Simulated-Annealing.md ├── Spare-Tire-Problem.md ├── Successors.md ├── TT-Entails.md ├── Table-Driven-Agent.md ├── Tree-CSP-Solver.md ├── Tree-Search-and-Graph-Search.md ├── Uniform-Cost-Search.md ├── Unify.md ├── Value-Iteration.md ├── Version-Space-Learning.md └── WalkSAT.md /LICENSE.md: -------------------------------------------------------------------------------- 1 | ![license](https://i.creativecommons.org/l/by/4.0/88x31.png) 2 | This work is licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/). 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pseudocode 2 | Pseudocode descriptions of the algorithms from [Russell](http://www.cs.berkeley.edu/~russell/) and [Norvig's](http://www.norvig.com/) [Artificial Intelligence - A Modern Approach](http://aima.cs.berkeley.edu/). 3 | 4 | The algorithms as they appear in the book are available in pdf format: 5 | - [**algorithms.pdf**](https://github.com/aimacode/pseudocode/blob/master/aima4e-algorithms.pdf) 6 | 7 | The files listed below give the same algorithms, but in markdown format. **We need help checking that the 4th edition versions are correct.** We are in the process of updating from the old [3rd edition](https://github.com/aimacode/pseudocode/blob/master/aima3e-algorithms.pdf) algorithms. (_Note:_ when editing pseudocode in a `md/*.md` file, put **two spaces at the end of a line**; this keeps the line separate from the following line.) 8 | 9 | 10 | | 3rd ed. | 4th ed. | Pseudo-code Algorithm| 11 | |:------:|:------:|:---------------------| 12 | | 2.3 | 2.7 | [TABLE-DRIVEN-AGENT](md/Table-Driven-Agent.md) | 13 | | 2.4 | 2.8 | [REFLEX-VACUUM-AGENT](md/Reflex-Vacuum-Agent.md) | 14 | | 2.6 | 2.10 | [SIMPLE-REFLEX-AGENT](md/Simple-Reflex-Agent.md) | 15 | | 2.8 | 2.12 | [MODEL-BASED-REFLEX-AGENT](md/Model-Based-Reflex-Agent.md) | 16 | | 3.1 | x | [SIMPLE-PROBLEM-SOLVING-AGENT](md/Simple-Problem-Solving-Agent.md) | 17 | | 3.7 | 3.7 | [BEST-FIRST-SEARCH](md/Tree-Search-and-Graph-Search.md) | 18 | | 3.11 |3.9 | [BREADTH-FIRST-SEARCH](md/Breadth-First-Search.md) | 19 | | 3.17 | 3.12 | [ITERATIVE-DEEPENING-SEARCH](md/Iterative-Deepening-Search.md) | 20 | | x | 3.14 | [BIBF-SEARCH]() (Bidirectional Best-First) | 21 | | 3.13 | x| [UNIFORM-COST-SEARCH](md/Uniform-Cost-Search.md) | 22 | | 3.16 | x| [DEPTH-LIMITED-SEARCH](md/Depth-Limited-Search.md) | 23 | | 3.24 | 3.22 | [RECURSIVE-BEST-FIRST-SEARCH](md/Recursive-Best-First-Search.md) | 24 | | 4.2 | 4.2 | [HILL-CLIMBING](md/Hill-Climbing.md) | 25 | | 4.5 | 4.4 | [SIMULATED-ANNEALING](md/Simulated-Annealing.md) | 26 | | 4.8 | 4.7 | [GENETIC-ALGORITHM](md/Genetic-Algorithm.md) | 27 | | 4.11 |4.10 | [AND-OR-GRAPH-SEARCH](md/And-Or-Graph-Search.md) | 28 | | 4.21 |4.20 | [ONLINE-DFS-AGENT](md/Online-DFS-Agent.md) | 29 | | 4.24 | 4.23 | [LRTA*-AGENT](md/LRTAStar-Agent.md) | 30 | | 5.3 | 5.3 | [MINIMAX-SEARCH](md/Minimax-Decision.md) (was MINIMAX-DECISION in 3e) | 31 | | 5.7 | 5.7 | [ALPHA-BETA-SEARCH](md/Alpha-Beta-Search.md) | 32 | | x | 5.11 | [MONTE-CARLO-TREE-SEARCH](md/Monte-Carlo-Tree-Search.md) 33 | | 6.3 | 6.3 | [AC-3](md/AC-3.md) | 34 | | 6.5 | 6.5 | [BACKTRACKING-SEARCH](md/Backtracking-Search.md) | 35 | | 6.8 | 6.9 | [MIN-CONFLICTS](md/Min-Conflicts.md) | 36 | | 6.11 | 6.11 | [TREE-CSP-SOLVER](md/Tree-CSP-Solver.md) | 37 | | 7.1| 7.1 | [KB-AGENT](md/KB-Agent.md) | 38 | | 7.8 | 7.10 | [TT-ENTAILS](md/TT-Entails.md) | 39 | | 7.9 | 7.13 | [PL-RESOLUTION](md/PL-Resolution.md) | 40 | | 7.12 |7.15 | [PL-FC-ENTAILS?](md/PL-FC-Entails.md) | 41 | | 7.14 | 7.17 | [DPLL-SATISFIABLE?](md/DPLL-Satisfiable.md) | 42 | | 7.15 | 7.18 | [WALKSAT](md/WalkSAT.md) | 43 | | 7.17 | 7.20 | [HYBRID-WUMPUS-AGENT](md/Hybrid-Wumpus-Agent.md) | 44 | | 7.19 | 7.22 | [SATPLAN](md/SATPlan.md) | 45 | | 9.1 | 9.1 | [UNIFY](md/Unify.md) | 46 | | 9.3 | 9.3 | [FOL-FC-ASK](md/FOL-FC-Ask.md) | 47 | | 9.6 | 9.6 | [FOL-BC-ASK](md/FOL-BC-Ask.md) | 48 | | 9.8 | 9.8 | [APPEND](md/Append.md) | 49 | | 10.1 |11.1 | [AIR-CARGO-TRANSPORT-PROBLEM](md/Air-Cargo-Transport-Problem.md) | 50 | | 10.2 |11.2 | [SPARE-TIRE-PROBLEM](md/Spare-Tire-Problem.md) | 51 | | 10.3 |11.4 | [BLOCKS-WORLD](md/Blocks-World.md) | 52 | | 10.7 |x | [HAVE-CAKE-AND-EAT-CAKE-TOO-PROBLEM](md/Have-Cake-And-Eat-Cake-Too.md) | 53 | | 10.9 | x | [GRAPHPLAN](md/GraphPlan.md) | 54 | | 11.4 |11.7 | [REFINEMENT-HIGH-LEVEL-ACTIONS](md/Refinement-High-Level-Actions.md) 55 | | 11.5 | 11.8 | [HIERARCHICAL-SEARCH](md/Hierarchical-Search.md) | 56 | | 11.8 |11.11 | [ANGELIC-SEARCH](md/Angelic-Search.md) | 57 | | 11.1 |11.13 | [JOB-SHOP-SCHEDULING-PROBLEM](md/Job-Shop-Scheduling-Problem.md) 58 | | 13.1 | 12.1 | [DT-AGENT](md/DT-Agent.md) | 59 | | 14.9 |13.11 | [ENUMERATION-ASK](md/Enumeration-Ask.md) | 60 | | 14.10 | 13.13 | [ELIMINATION-ASK](md/Elimination-Ask.md) | 61 | | 14.12 |13.16 | [PRIOR-SAMPLE](md/Prior-Sample.md) | 62 | | 14.13|13.17 | [REJECTION-SAMPLING](md/Rejection-Sampling.md) | 63 | | 14.14 |13.18 | [LIKELIHOOD-WEIGHTING](md/Likelihood-Weighting.md) | 64 | | 14.15 | 13.20 | [GIBBS-ASK](md/Gibbs-Ask.md) | 65 | | 15.4 | 14.4 | [FORWARD-BACKWARD](md/Forward-Backward.md) | 66 | | 15.6 | 14.6 | [FIXED-LAG-SMOOTHING](md/Fixed-Lag-Smoothing.md) | 67 | | 15.17 | 14.17 | [PARTICLE-FILTERING](md/Particle-Filtering.md) | 68 | | x |15.5 | [OUPM](md/oupm.md) (for citation extraction) | 69 | | x | 15.6 | [NET-VISA](md/net-visa.md) | 70 | | x | 15.9 | [RADAR](md/radar.md) (OUPM for radar tracking)| 71 | | x | 15.11| [GENERATE-IMAGE](md/generate-image.md)| 72 | | x |15.15| [GENERATE-MARKOV-LETTERS](md/generate-markov-letters.md)| 73 | | 16.9 | 16.9 | [INFORMATION-GATHERING-AGENT](md/Information-Gathering-Agent.md) | 74 | | 17.4 | 17.6 | [VALUE-ITERATION](md/Value-Iteration.md) | 75 | | 17.7 | 17.9 | [POLICY-ITERATION](md/Policy-Iteration.md) | 76 | | 17.9 |17.16 | [POMDP-VALUE-ITERATION](md/POMDP-Value-Iteration.md) | 77 | | 11.10 | 18.1| [DOUBLES-TENNIS-PROBLEM](md/Doubles-Tennis-Problem.md) | 78 | | 18.4 | 19.5 | [LEARN-DECISION-TREE](md/Decision-Tree-Learning.md) | 79 | | 18.7 | 19.8 | [CROSS-VALIDATION-WRAPPER](md/Cross-Validation-Wrapper.md) | 80 | | 18.10 | 19.11 | [DECISION-LIST-LEARNING](md/Decision-List-Learning.md) | 81 | | 18.33 | 19.25 | [ADABOOST](md/AdaBoost.md) | 82 | | 19.2 | x| [CURRENT-BEST-LEARNING](md/Current-Best-Learning.md) | 83 | | 19.3 | x| [VERSION-SPACE-LEARNING](md/Version-Space-Learning.md) | 84 | | 19.8 | x| [MINIMAL-CONSISTENT-DET](md/Minimal-Consistent-Det.md) | 85 | | 19.12 | x | [FOIL](md/Foil.md) | 86 | | 21.2 | 22.2 | [PASSIVE-ADP-AGENT](md/Passive-ADP-Agent.md) | 87 | | 21.4 | 22.4 | [PASSIVE-TD-AGENT](md/Passive-TD-Agent.md) | 88 | | 21.8 | 22.8 | [Q-LEARNING-AGENT](md/Q-Learning-Agent.md) | 89 | | 22.1 | x | [HITS](md/Hits.md) | 90 | | 23.4 |23.5 | [CYK-PARSE](md/CYK-Parse.md) | 91 | | 23.5 | 23.8| [SENTENCE-TREE](md/Sentence-Tree.md) | 92 | | 25.9 | 26.6 | [MONTE-CARLO-LOCALIZATION](md/Monte-Carlo-Localization.md) | 93 | | 29.1 | x | [POWERS-OF-2](md/Powers-Of-2.md) | 94 | -------------------------------------------------------------------------------- /aima3e-algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimacode/aima-pseudocode/d2d5da0477d646bd25c1850ba9a95047cd6de464/aima3e-algorithms.pdf -------------------------------------------------------------------------------- /algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aimacode/aima-pseudocode/d2d5da0477d646bd25c1850ba9a95047cd6de464/algorithms.pdf -------------------------------------------------------------------------------- /md/AC-3.md: -------------------------------------------------------------------------------- 1 | # AC-3 2 | 3 | ## AIMA3e 4 | __function__ AC-3(_csp_) __returns__ false if an inconsistency is found and true otherwise 5 |  __inputs__: _csp_, a binary CSP with components (_X_, _D_, _C_) 6 |  __local variables__: _queue_, a queue of arcs, initially all the arcs in _csp_ 7 | 8 |  __while__ _queue_ is not empty __do__ 9 |    (_Xi_, _Xj_) ← REMOVE\-FIRST(_queue_) 10 |    __if__ REVISE(_csp_, _Xi_, _Xj_) __then__ 11 |      __if__ size of _Di_ = 0 __then return__ _false_ 12 |      __for each__ _Xk_ in _Xi_.NEIGHBORS − \{_Xj_\} __do__ 13 |       add(_Xk_, _Xi_) to _queue_ 14 |  __return__ _true_ 15 | 16 | --- 17 | __function__ REVISE(_csp_, _Xi_, _Xj_) __returns__ true iff we revise the domain of _Xi_ 18 |  _revised_ ← _false_ 19 |  __for each__ _x_ __in__ _Di_ __do__ 20 |    __if__ no value _y_ in _Dj_ allows (_x_, _y_) to satisfy the constraint between _Xi_ and _Xj_ __then__ 21 |     delete _x_ from _Di_ 22 |     _revised_ ← _true_ 23 |  __return__ _revised_ 24 | 25 | --- 26 | __Figure__ ?? The arc\-consistency algorithm AC\-3. After applying AC\-3, either every arc is arc\-consistent, or some variable has an empty domain, indicating that the CSP cannot be solved. The name "AC\-3" was used by the algorithm's inventor (Mackworth, 1977) because it's the third version developed in the paper. 27 | -------------------------------------------------------------------------------- /md/AdaBoost.md: -------------------------------------------------------------------------------- 1 | # ADABOOST 2 | 3 | ## AIMA3e 4 | __function__ ADABOOST(_examples_, _L_, _K_) __returns__ a weighted\-majority hypothesis 5 |  __inputs__: _examples_, set of _N_ labeled examples (_x1_, _y1_),…,(_xN_,_yN_) 6 |     _L_, a learning algorithm 7 |     _K_, the number of hypotheses in the ensemble 8 |  __local variables__: __w__, a vector of _N_ example weights, initially 1 ⁄ _N_ 9 |         __h__, a vector of _K_ hypotheses 10 |         __z__, a vector of _K_ hypothesis weights 11 | 12 |  __for__ _k_ = 1 __to__ _K_ __do__ 13 |    __h__\[_k_\] ← _L_(_examples_, __w__) 14 |    _error_ ← 0 15 |    __for__ _j_ = 1 __to__ _N_ __do__ 16 |      __if__ __h__\[_k_\](_xj_) ≠ _yj_ __then__ _error_ ← _error_ + __w__\[_j_\] 17 |    __for__ _j_ = 1 __to__ _N_ __do__ 18 |      __if__ __h__\[_k_\](_xj_) = _yj_ __then__ __w__\[_j_\] ← __w__\[_j_\] · _error_ ⁄ (1 − _error_) 19 |    __w__ ← NORMALIZE(__w__) 20 |    __Z__\[_k_\] ← log(1 − _error_) ⁄ _error_ 21 |   __return__ WEIGHTED\-MAJORITY(__h__, __z__) 22 | 23 | --- 24 | __Figure ??__ The ADABOOST variant of the boosting method for ensemble learning. The algorithm generates hypothesis by successively reweighting the training examples. The function WEIGHTED\-MAJORITY generates a hypothesis that returns the output value with the highest vote from the hypotheses in __h__, with votes weighted by __z__. 25 | -------------------------------------------------------------------------------- /md/Adam-Optimizer.md: -------------------------------------------------------------------------------- 1 | # ADAM-OPTIMIZER 2 | 3 | ## AIMA4e 4 | 5 | __function__ ADAM-OPTIMIZER(_f_,_L_,***θ***,_ρ_,_α_,_δ_) __returns__ updated ***θ*** 6 |     /\* _Defualts:_ _ρ1_ = 0.9; _ρ2_ = 0.999;_α_ = 0.001;_δ_ = 10-8 \*/ 7 |  ***s*** ← __0__ 8 |  ***r*** ← __0__ 9 |   t ← 0 10 |    __while__ ***θ*** has not converged 11 |       ***x***, ***y*** ← a minibatch of _m_ examples from training set 12 |       ***g*** ← /\* compute gradient \*/ 13 |      _t_ ← _t_ + 1 14 |      ***s*** ← _ρ1_***s*** + (1 − _ρ1_)***g*** /\* _Update biased first moment estimate_ \*/ 15 |      ***r*** ← _ρ2_***r*** + (1 − _ρ2_)***g******g*** /\*_Update biased second moment estimate_ \*/ 16 |       /\* _Correct bias in first moment_ \*/ 17 |       /\* _Correct bias in second moment_ \*/ 18 |       /\* _Compute update (operations applied element-wise)_ \*/ 19 |       /\* _Apply update_ \*/ 20 | 21 | 22 | -------------------------------------------------------------------------------- /md/Air-Cargo-Transport-Problem.md: -------------------------------------------------------------------------------- 1 | # AIR-CARGO-TRANSPORT-PROBLEM 2 | 3 | ## AIMA3e 4 | _Init_(_At_(_C1_, _SFO_) ∧ _At_(_C2_, _JFK_) ∧ _At_(_P1_, _SFO_) ∧ _At_(_P2_, _JFK_) 5 |   ∧ _Cargo_(_C1_) ∧ _Cargo_(_C2_) ∧ _Plane_(_P1_) ∧ _Plane_(_P2_) 6 |   ∧ _Airport_(_JFK_) ∧ _Airport_(_SFO_)) 7 | _Goal_(_At_(_C1_, _JFK_) ∧ _At_(_C2_, _SFO_)) 8 | _Action_(_Load_(_c_, _p_, _a_), 9 |  PRECOND: _At_(_c_, _a_) ∧ _At_(_p_, _a_) ∧ _Cargo_(_c_) ∧ _Plane_(_p_) ∧ _Airport_(_a_) 10 |  EFFECT: ¬ _At_(_c_, _a_) ∧ _In_(_c_, _p_)) 11 | _Action_(_Unload_(_c_, _p_, _a_), 12 |  PRECOND: _In_(_c_, _p_) ∧ _At_(_p_, _a_) ∧ _Cargo_(_c_) ∧ _Plane_(_p_) ∧ _Airport_(_a_) 13 |  EFFECT: _At_(_c_, _a_) ∧ ¬ _In_(_c_, _p_)) 14 | _Action_(_Fly_(_p_, _from_, _to_), 15 |  PRECOND: _At_(_p_, _from_) ∧ _Plane_(_p_) ∧ _Airport_(_from_) ∧ _Airport_(_to_) 16 |  EFFECT: ¬ _At_(_p_, _from_) ∧ _At_(_p_, _to_)) 17 | 18 | --- 19 | __Figure ??__ A PDDL description of an air cargo transportation planning problem. 20 | -------------------------------------------------------------------------------- /md/Alpha-Beta-Search.md: -------------------------------------------------------------------------------- 1 | # ALPHA-BETA-SEARCH 2 | 3 | ## AIMA3e 4 | __function__ ALPHA-BETA-SEARCH(_state_) __returns__ an action 5 |  _v_ ← MAX\-VALUE(_state_, −∞, +∞) 6 |  __return__ the _action_ in ACTIONS(_state_) with value _v_ 7 | 8 | --- 9 | __function__ MAX\-VALUE(_state_, _α_, _β_) __returns__ _a utility value_ 10 |  __if__ TERMINAL\-TEST(_state_) __then return__ UTILITY(_state_) 11 |  _v_ ← −∞ 12 |  __for each__ _a_ __in__ ACTIONS(_state_) __do__ 13 |    _v_ ← MAX(_v_, MIN\-VALUE(RESULT(_state_, _a_), _α_, _β_)) 14 |    __if__ _v_ ≥ _β_ __then return__ _v_ 15 |    _α_ ← MAX(_α_, _v_) 16 |  __return__ _v_ 17 | 18 | --- 19 | __function__ MIN\-VALUE(_state_, _α_, _β_) __returns__ _a utility value_ 20 |  __if__ TERMINAL\-TEST(_state_) __then return__ UTILITY(_state_) 21 |  _v_ ← +∞ 22 |  __for each__ _a_ __in__ ACTIONS(_state_) __do__ 23 |    _v_ ← MIN(_v_, MAX\-VALUE(RESULT(_state_, _a_), _α_, _β_)) 24 |    __if__ _v_ ≤ _α_ __then return__ _v_ 25 |    _β_ ← MIN(_β_, _v_) 26 |  __return__ _v_ 27 | 28 | 29 | --- 30 | __Figure__ ?? The alpha\-beta search algorithm. Notice that these routines are the same as the MINIMAX functions in Figure ??, except for the two lines in each of MIN\-VALUE and MAX\-VALUE that maintain _α_ and _β_ (and the bookkeeping to pass these parameters along). 31 | -------------------------------------------------------------------------------- /md/And-Or-Graph-Search.md: -------------------------------------------------------------------------------- 1 | # AND-OR-GRAPH-SEARCH 2 | 3 | ## AIMA3e 4 | __function__ AND-OR-GRAPH-SEARCH(_problem_) __returns__ _a conditional plan_, or _failure_ 5 |  OR\-SEARCH(_problem_.INITIAL\-STATE, _problem_, \[\]) 6 | 7 | --- 8 | __function__ OR\-SEARCH(_state_, _problem_, _path_) __returns__ _a conditional plan_, or _failure_ 9 |  __if__ _problem_.GOAL\-TEST(_state_) __then return__ the empty plan 10 |  __if__ _state_ is on _path_ __then return__ _failure_ 11 |  __for each__ _action_ __in__ _problem_.ACTIONS(_state_) __do__ 12 |    _plan_ ← AND\-SEARCH(RESULTS(_state_,_action_), _problem_, \[_state_ | _path_\]) 13 |    __if__ _plan_ ≠ _failure_ __then return__ \[_action_ | _plan_\] 14 |  __return__ _failure_ 15 | 16 | --- 17 | __function__ AND\-SEARCH(_states_, _problem_, _path_) __returns__ _a conditional plan_, or _failure_ 18 |  __for each__ _si_ __in__ _states_ __do__ 19 |    _plani_ ← OR\-SEARCH(_si_, _problem_, _path_) 20 |    __if__ _plani_ = _failure_ __then return__ _failure_ 21 |  __return__ \[__if__ _s1_ __then__ _plan1_ __else if__ _s2_ __then__ _plan2_ __else__ ... __if__ _sn-1_ __then__ _plann-1_ __else__ _plann_\] 22 | 23 | --- 24 | 25 | __Figure__ ?? An algorithm for searching AND\-OR graphs generated by nondeterministic environments. It returns a conditional plan that reaches a goal state in all circumstances. (The notations \[_x_ | _l_\] refers to the list formed by adding object _x_ to the front of list _l_). 26 | -------------------------------------------------------------------------------- /md/Angelic-Search.md: -------------------------------------------------------------------------------- 1 | # ANGELIC-SEARCH 2 | 3 | ## AIMA3e 4 | __function__ ANGELIC-SEARCH(_problem_, _hierarchy_, _initialPlan_) __returns__ solution or _fail_ 5 |  _frontier_ ← a FIFO queue with _initialPlan_ as the only element 6 |  __loop do__ 7 |    __if__ EMPTY?(_frontier_) __then return__ _fail_ 8 |    _plan_ ← POP(_frontier_) /\* chooses the shallowest node in _frontier_ \*/ 9 |    __if__ REACH+(_problem_.INITIAL\-STATE, _plan_) intersects _problem_.GOAL __then__ 10 |      __if__ _plan_ is primitive __then return__ _plan_ /\* REACH+ is exact for primitive plans \*/ 11 |      _guaranteed_ ← REACH(_problem_.INITIAL\-STATE, _plan_) ∩ _problem_.GOAL 12 |      __if__ _guaranteed_ ≠ \{\} and MAKING\-PROGRESS(_plan_, _initialPlan_) __then__ 13 |        _finalState_ ← any element of _guaranteed_ 14 |        __return__ DECOMPOSE(_hierarchy_, _problem_.INITIAL\-STATE, _plan_, _finalState_) 15 |      _hla_ ← some HLA in _plan_ 16 |      _prefix_,_suffix_ ← the action subsequences before and after _hla_ in _plan_ 17 |      __for each__ _sequence_ __in__ REFINEMENTS(_hla_, _outcome_, _hierarchy_) __do__ 18 |        _frontier_ ← INSERT(APPEND(_prefix_, _sequence_, _suffix_), _frontier_) 19 | 20 | --- 21 | __function__ DECOMPOSE(_hierarchy_, _s0_, _plan_, _sf_) __returns__ a solution 22 |  _solution_ ← an empty plan 23 |  __while__ _plan_ is not empty __do__ 24 |    _action_ ← REMOVE\-LAST(_plan_) 25 |    _si_ ← a state in REACH(_s0_, _plan_) such that _sf_ ∈ REACH(_si_, _action_) 26 |    _problem_ ← a problem with INITIAL\-STATE = _si_ and GOAL = _sf_ 27 |    _solution_ ← APPEND(ANGELIC-SEARCH(_problem_, _hierarchy_, _action_), _solution_) 28 |    _sf_ ← _si_ 29 |  __return__ _solution_ 30 | 31 | --- 32 | __Figure__ ?? A hierarchical planning algorithm that uses angelic semantics to identify and commit to high\-level plans that work while avoiding high\-level plans that don't. The predicate MAKING\-PROGRESS checks to make sure that we aren't stuck in an infinite regression of refinements. At top level, call ANGELIC-SEARCH with \[_Act_\] as the _initialPlan_. 33 | -------------------------------------------------------------------------------- /md/Append.md: -------------------------------------------------------------------------------- 1 | # APPEND 2 | 3 | ## AIMA3e 4 | __procedure__ APPEND(_ax_, _y_, _az_, _continuation_) 5 | 6 |  _trail_ ← GLOBAL-TRAIL-POINTER() 7 |  __if__ _ax_ = \[ \] and UNIFY(_y_, _az_) __then__ CALL(_continuation_) 8 |  RESET-TRAIL(_trail_) 9 |  _a_, _x_, _z_ ← NEW-VARIABLE(), NEW-VARIABLE(), NEW-VARIABLE() 10 |  __if__ UNIFY(_ax_, \[_a_ | _x_\]) and UNIFY(_az_, \[_a_ | _z_\]) __then__ APPEND(_x_, _y_, _z_, _continuation_) 11 | 12 | --- 13 | __Figure__ ?? Pseudocode representing the result of compiling the Append predicate. The function NEW-VARIABLE returns a new variable, distinct from all other variables used so far. The procedure CALL(_continuation_) continues execution with the specified continuation. 14 | -------------------------------------------------------------------------------- /md/Back-Prop-Learning-with-regularization.md: -------------------------------------------------------------------------------- 1 | # BACK-PROP-LEARNING-WITH-REGULARIZATION 2 | 3 | ## AIMA3e 4 | __function__ BACK-PROP-LEARNING-WITH-REGULARIZATION(_examples_, _network_) __returns__ a neural network 5 |  __inputs__ _examples_, a set of examples, each with input vector __x__ and output vector __y__ 6 |     _network_, a multilayer network with _L_ layers, weights _wi,j_, activation function _g_, regularization parameter λ 7 |  __local variables__: Δ, a vector of errors, indexed by network node 8 | 9 | /* Φ is a function of the weights. It depends on the type of regularization, e.g., for _L2_ regularization, Φ=Σ_j_ ||_wi,j_||_2_ */ 10 | 11 |  __repeat__ 12 |    __for each__ weight _wi,j_ in _network_ __do__ 13 |      _wi,j_ ← a small random number 14 |    __for each__ example (__x__, __y__) __in__ _examples_ __do__ 15 |      /\* _Propagate the inputs forward to compute the outputs_ \*/ 16 |      __for each__ node _i_ in the input layer __do__ 17 |        _ai_ ← _xi_ 18 |      __for__ _l_ = 2 __to__ _L_ __do__ 19 |        __for each__ node _j_ in layer _l_ __do__ 20 |          _inj_ ← Σ_i_ _wi,j_ _ai_ 21 |          _aj_ ← _g_(_inj_) 22 |      /\* _Propagate deltas backward from output layer to input layer_ \*/ 23 |      __for each__ node _j_ in the output layer __do__ 24 |        Δ\[_j_\] ← _g_′(_inj_) × (_yi_ − _aj_) 25 |      __for__ _l_ = _L_ − 1 __to__ 1 __do__ 26 |        __for each__ node _i_ in layer _l_ __do__ 27 |          Δ\[_i_\] ← _g_′(_ini_) Σ_j_ _wi,j_ Δ\[_j_\] + λ Φ(_wi,j_) 28 |      /\* _Update every weight in network using deltas_ \*/ 29 |      __for each__ weight _wi,j_ in _network_ __do__ 30 | 31 |        _wi,j_ ← _wi,j_ + _α_ × _ai_ × Δ\[_j_\] 32 |  __until__ some stopping criterion is satisfied 33 |  __return__ _network_ 34 | 35 | --- 36 | __Figure ??__ The back\-propagation algorithm for learning in multilayer networks. 37 | -------------------------------------------------------------------------------- /md/Back-Prop-Learning.md: -------------------------------------------------------------------------------- 1 | # BACK-PROP-LEARNING 2 | 3 | ## AIMA3e 4 | __function__ BACK-PROP-LEARNING(_examples_, _network_) __returns__ a neural network 5 |  __inputs__ _examples_, a set of examples, each with input vector __x__ and output vector __y__ 6 |     _network_, a multilayer network with _L_ layers, weights _wi,j_, activation function _g_ 7 |  __local variables__: Δ, a vector of errors, indexed by network node 8 | 9 |  __repeat__ 10 |    __for each__ weight _wi,j_ in _network_ __do__ 11 |      _wi,j_ ← a small random number 12 |    __for each__ example (__x__, __y__) __in__ _examples_ __do__ 13 |      /\* _Propagate the inputs forward to compute the outputs_ \*/ 14 |      __for each__ node _i_ in the input layer __do__ 15 |        _ai_ ← _xi_ 16 |      __for__ _l_ = 2 __to__ _L_ __do__ 17 |        __for each__ node _j_ in layer _l_ __do__ 18 |          _inj_ ← Σ_i_ _wi,j_ _ai_ 19 |          _aj_ ← _g_(_inj_) 20 |      /\* _Propagate deltas backward from output layer to input layer_ \*/ 21 |      __for each__ node _j_ in the output layer __do__ 22 |        Δ\[_j_\] ← _g_′(_inj_) × (_yi_ − _aj_) 23 |      __for__ _l_ = _L_ − 1 __to__ 1 __do__ 24 |        __for each__ node _i_ in layer _l_ __do__ 25 |          Δ\[_i_\] ← _g_′(_ini_) Σ_j_ _wi,j_ Δ\[_j_\] 26 |      /\* _Update every weight in network using deltas_ \*/ 27 |      __for each__ weight _wi,j_ in _network_ __do__ 28 |        _wi,j_ ← _wi,j_ + _α_ × _ai_ × Δ\[_j_\] 29 |  __until__ some stopping criterion is satisfied 30 |  __return__ _network_ 31 | 32 | --- 33 | __Figure ??__ The back\-propagation algorithm for learning in multilayer networks. 34 | -------------------------------------------------------------------------------- /md/Backtracking-Search.md: -------------------------------------------------------------------------------- 1 | # BACKTRACKING-SEARCH 2 | 3 | ## AIMA3e 4 | __function__ BACKTRACKING-SEARCH(_csp_) __returns__ a solution, or failure 5 |  __return__ BACKTRACK(\{\}, _csp_) 6 | 7 | __function__ BACKTRACK(_assignment_, _csp_) __returns__ a solution, or failure 8 |  __if__ _assignment_ is complete __then return__ _assignment_ 9 |  _var_ ← SELECT\-UNASSIGNED-VARIABLE(_csp_) 10 |  __for each__ _value_ __in__ ORDER\-DOMAIN\-VALUES(_var_, _assignment_, _csp_) __do__ 11 |    __if__ _value_ is consistent with _assignment_ __then__ 12 |      add \{_var_ = _value_\} to _assignment_ 13 |      _inferences_ ← INFERENCE(_csp_, _var_, _value_) 14 |      __if__ _inferences_ ≠ _failure_ __then__ 15 |       add _inferences_ to _assignment_ 16 |       _result_ ← BACKTRACK(_assignment_, _csp_) 17 |       __if__ _result_ ≠ _failure_ __then__ 18 |        __return__ _result_ 19 |      remove \{_var_ = _value_\} and _inferences_ from _assignment_ 20 |  __return__ _failure_ 21 | 22 | --- 23 | __Figure__ ?? A simple backtracking algorithm for constraint satisfaction problems. The algorithm is modeled on the recursive depth\-first search of Chapter ??. By varying the functions SELECT\-UNASSIGNED\-VARIABLE and ORDER\-DOMAIN\-VALUES, we can implement the general\-purpose heuristics discussed in the text. The function INFERENCE can optionally be used to impose arc\-,path\-, or _k_\-consistency, as desired. If a value choice leads to failure (noticed either by INFERENCE or by BACKTRACK), then value assignments (including those made by INFERENCE) are removed from the current assignment and a new value is tried. 24 | -------------------------------------------------------------------------------- /md/Blocks-World.md: -------------------------------------------------------------------------------- 1 | # BLOCKS-WORLD 2 | 3 | ## AIMA3e 4 | _Init_(_On_(_A_, _Table_) ∧ _On_(_B_, _Table_) ∧ _On_(_C_, _A_) 5 |   ∧ _Block_(_A_) ∧ _Block_(_B_) ∧ _Block_(_C_) ∧ _Clear_(_B_) ∧ _Clear_(_C_)) 6 | _Goal_(_On_(_A_, _B_) ∧ _On_(_B_, _C_)) 7 | _Action_(_Move_(_b_, _x_, _y_), 8 |  PRECOND: _On_(_b_, _x_) ∧ _Clear_(_b_) ∧ _Clear_(_y_) ∧ _Block_(_b_) ∧ _Block_(_y_) ∧ 9 |      (_b_ ≠ _x_) ∧ (_b_ ≠ _y_) ∧ (_x_ ≠ _y_), 10 |  EFFECT: _On_(_b_, _y_) ∧ _Clear_(_x_) ∧ ¬ _On_(_b_, _x_) ∧ ¬ _Clear_(_y_)) 11 | _Action_(_MoveToTable_(_b_, _x_), 12 |  PRECOND: _On_(_b_, _x_) ∧ _Clear_(_b_) ∧ _Block_(_b_) ∧ (_b_ ≠ _x_), 13 |  EFFECT: _On_(_b_, _Table_) ∧ _Clear_(_x_) ∧ ¬ _On_(_b_, _x_)) 14 | 15 | --- 16 | __Figure ??__ A planning problem in the blocks world: building a three-block tower. One solution is the sequence [_MoveToTable_(_C_, _A_), _Move_(_B_, _Table_, _C_), _Move_(_A_, _Table_, _B_)]. 17 | -------------------------------------------------------------------------------- /md/Breadth-First-Search.md: -------------------------------------------------------------------------------- 1 | # BREADTH-FIRST-SEARCH 2 | 3 | ## AIMA4e 4 | 5 | __function__ BREADTH-FIRST-SEARCH(_problem_) __returns__ a solution, or failure 6 |  __if__ problem's initial state is a goal __then return__ empty path to initial state 7 |  _frontier_ ← a FIFO queue initially containing one path, for the _problem_'s initial state 8 |  _reached_ ← a set of states; initially empty 9 |  _solution_ ← failure 10 |  __while__ _frontier_ is not empty __do__ 11 |    _parent_ ← the first node in _frontier_ 12 |    __for__ _child_ __in__ successors(_parent_) __do__ 13 |      _s_ ← _child_.state 14 |      __if__ _s_ is a goal __then__ 15 |        __return__ _child_ 16 |      __if__ _s_ is not in _reached_ __then__ 17 |        add _s_ to _reached_ 18 |        add _child_ to the end of _frontier_ 19 |  __return__ _solution_ 20 | 21 | --- 22 | __Figure 3.9__ Breadth-first search algorithm. 23 | 24 | 25 | ## AIMA3e 26 | __function__ BREADTH-FIRST-SEARCH(_problem_) __returns__ a solution, or failure 27 |  _node_ ← a node with STATE = _problem_.INITIAL\-STATE, PATH\-COST = 0 28 |  __if__ _problem_.GOAL\-TEST(_node_.STATE) __then return__ SOLUTION(_node_) 29 |  _frontier_ ← a FIFO queue with _node_ as the only element 30 |  _explored_ ← an empty set 31 |  __loop do__ 32 |    __if__ EMPTY?(_frontier_) __then return__ failure 33 |    _node_ ← POP(_frontier_) /\* chooses the shallowest node in _frontier_ \*/ 34 |    add _node_.STATE to _explored_ 35 |    __for each__ _action_ __in__ _problem_.ACTIONS(_node_.STATE) __do__ 36 |       _child_ ← CHILD\-NODE(_problem_,_node_,_action_) 37 |       __if__ _child_.STATE is not in _explored_ or _frontier_ __then__ 38 |          __if__ _problem_.GOAL\-TEST(_child_.STATE) __then return__ SOLUTION(_child_) 39 |          _frontier_ ← INSERT(_child_,_frontier_) 40 | 41 | --- 42 | __Figure__ ?? Breadth\-first search on a graph. 43 | -------------------------------------------------------------------------------- /md/CYK-Parse.md: -------------------------------------------------------------------------------- 1 | # CYK-PARSE 2 | 3 | ## AIMA3e 4 | __function__ CYK-Parse(_words_, _grammar_) __returns__ _P_, a table of probabilities 5 |  _N_ ← Length(_words_) 6 |  _M_ ← the number of nonterminal symbols in _grammar_ 7 |  _P_ ← an array of size [_M_, _N_, _N_], initially all 0 8 |  /\* insert lexical rules for each word \*/ 9 |  __for__ _i_ = 1 __to__ _N_ __do__ 10 |   __for__ __each__ rule of form (_X_ → _wordsi_[_P_]) __do__ 11 |    _P_[_X_, _i_, 1] ← p 12 |  /\* Combine first and second parts of right-hand sides of rules, from short to long \*/ 13 |  __for__ _length_ = 2 __to__ _N_ __do__ 14 |   __for__ _start_ = 1 __to__ _N_ - _length_ + 1 __do__ 15 |    __for__ _len1_ = 1 __to__ _length_ - 1 __do__ 16 |     _len2_ ← _length_ - _len1_ 17 |     __for each__ rule of the form (_X_ → _Y_ _Z_ [_p_]) __do__ 18 |      _P_[_X_, _start_, _length_] ← Max(_P_[_X_, _start_, _length_], _P_[_Y_, _start_, _len1_] x _P_[_Z_, _start_ + _len1_, _len2_] x _p_) 19 |  __return__ _P_ 20 | 21 | --- 22 | __Figure ??__ The CYK algorithm for parsing. Given a sequence of words, it finds the most probable derivation for the whole sequence and for each subsequence. It returns the whole table, _P_, in which and entry _P_[_X_, _start_, _len_] is the probability of the most probable _X_ of length _len_ starting at position _start_. If there is no _X_ of that size at that location, the probability is 0. 23 | -------------------------------------------------------------------------------- /md/Cross-Validation-Wrapper.md: -------------------------------------------------------------------------------- 1 | # CROSS-VALIDATION-WRAPPER 2 | 3 | ## AIMA3e 4 | __function__ CROSS-VALIDATION-WRAPPER(_Learner_, _k_, _examples_) __returns__ a hypothesis 5 |  __local variables__: _errT_, an array, indexed by _size_, storing training\-set error rates 6 |         _errV_, an array, indexed by _size_, storing validation\-set error rates 7 |  __for__ _size_ = 1 __to__ ∞ __do__ 8 |    _errT_\[_size_\], _errV_\[_size_\] ← CROSS\-VALIDATION(_Learner_, _size_, _k_, _examples_) 9 |    __if__ _errT_ has converged __then do__ 10 |      _best\_size_ ← the value of _size_ with minimum _errV_\[_size_\] 11 |      __return__ _Learner_(_best\_size_, _examples_) 12 | 13 | --- 14 | __function__ CROSS\-VALIDATION(_Learner_, _size_, _k_, _examples_) __returns__ two values: 15 |  _fold\_errT_ ← 0; _fold\_errV_ ← 0 16 |  __for__ _fold_ = 1 __to__ _k_ __do__ 17 |    _training\_set_, _validation\_set_ ← PARTITION(_examples_, _fold_, _k_) 18 |    _h_ ← _Learner_(_size_, _training\_set_) 19 |    _fold\_errT_ ← _fold\_errT_ + ERROR\-RATE(_h_, _training\_set_) 20 |    _fold\_errV_ ← _fold\_errV_ + ERROR\-RATE(_h_, _validation\_set_) 21 |  __return__ _fold\_errT_ ⁄ _k_, _fold\_errV_ ⁄ _k_ 22 | 23 | --- 24 | 25 | Figure?? An algorithm to select the model that has the lowest error rate on validation data by building models of increasing complexity, and choosing the one with best empirical error rate on validation data. Here _errT_ means error rate on the training data, and _errV_ means error rate on the validation data. _Learner_(_size_, _exmaples_) returns a hypothesis whose complexity is set by the parameter _size_, and which is trained on the _examples_. PARTITION(_examples_, _fold_, _k_) splits _examples_ into two subsets: a validation set of size _N_ ⁄ _k_ and a training set with all the other examples. The split is different for each value of _fold_. 26 | 27 | --- 28 | 29 | In the fourth edition, cross vaidation wrapper has been renamed to Model-Selection. 30 | -------------------------------------------------------------------------------- /md/Current-Best-Learning.md: -------------------------------------------------------------------------------- 1 | # CURRENT-BEST-LEARNING 2 | 3 | ## AIMA3e 4 | __function__ Current-Best-Learning(_examples_, _h_) __returns__ a hypothesis or fail 5 |  __if__ _examples_ is empty __then__ 6 |    __return__ _h_ 7 |  _e_ ← First(_examples_) 8 |  __if__ _e_ is consistent with _h_ __then__ 9 |    __return__ Current-Best-Learning(Rest(_examples_), _h_) 10 |  __else if__ _e_ is a false positive for _h_ __then__ 11 |    __for each__ _h'_ __in__ specializations of _h_ consistent with _examples_ seen so far __do__ 12 |      _h''_ ← Current-Best-Learning(Rest(_examples_), _h'_) 13 |      __if__ _h''_ ≠ _fail_ __then return__ _h''_ 14 |  __else if__ _e_ is a false negative for _h_ __then__ 15 |    __for each__ _h'_ __in__ generalizations of _h_ consistent with _examples_ seen so far __do__ 16 |      _h''_ ← Current-Best-Learning(Rest(_examples_), _h'_) 17 |      __if__ _h''_ ≠ _fail_ __then return__ _h''_ 18 |  __return__ _fail_ 19 | 20 | --- 21 | __Figure ??__ The current-best-hypothesis learning algorithm. It searches for a consistent hypothesis that fits all the examples and backtracks when no consistent specialization/generalization can be found. To start the algorithm, any hypothesis can be passed in; it will be specialized or generalized as needed. 22 | -------------------------------------------------------------------------------- /md/DPLL-Satisfiable.md: -------------------------------------------------------------------------------- 1 | # DPLL-SATISFIABLE? 2 | 3 | ## AIMA3e 4 | __function__ DPLL-SATISFIABLE?(_s_) __returns__ _true_ or _false_ 5 |  __inputs__: _s_, a sentence in propositional logic. 6 | 7 |  _clauses_ ← the set of clauses in the CNF representation of _s_ 8 |  _symbols_ ← a list of the proposition symbols in _s_ 9 |  __return__ DPLL(_clauses_, _symbols_, { }) 10 | 11 | --- 12 | __function__ DPLL(_clauses_, _symbols_, _model_) __returns__ _true_ or _false_ 13 | 14 |  __if__ every clause in _clauses_ is true in _model_ __then return__ _true_ 15 |  __if__ some clause in _clauses_ is false in _model_ __then return__ _false_ 16 |  _P_, _value_ ← FIND\-PURE\-SYMBOL(_symbols_, _clauses_, _model_) 17 |  __if__ _P_ is non-null __then return__ DPLL(_clauses_, _symbols_ - _P_, _model_ ∪ {_P_ = _value_}) 18 |  _P_, _value_ ← FIND\-UNIT\-CLAUSE(_clauses_, _model_) 19 |  __if__ _P_ is non-null __then return__ DPLL(_clauses_, _symbols_ - _P_, _model_ ∪ {_P_ = _value_}) 20 |  _P_ ← FIRST(_symbols_); _rest_ ← REST(_symbols_) 21 |  __return__ DPLL(_clauses_, _rest_, _model_ ∪ {_P_ = _true_}) __or__ 22 |     DPLL(_clauses_, _rest_, _model_ ∪ {_P_ = _false_}) 23 | 24 | --- 25 | __Figure__ ?? The DPLL algorithm for checking satisfiability of a sentence in propositional logic. The ideas behind FIND\-PURE\-SYMBOL and FIND\-UNIT\-CLAUSE are described in the text; each returns a symbol (or null) and the truth value to assign to that symbol. Like TT\-ENTAILS?, DPLL operates over partial models. 26 | -------------------------------------------------------------------------------- /md/DT-Agent.md: -------------------------------------------------------------------------------- 1 | # DT-AGENT 2 | 3 | ## AIMA3e 4 | __function__ DT-AGENT(_percept_) __returns__ an _action_ 5 |  __persistent__: _belief\_state_, probabilistic beliefs about the current state of the world 6 |       _action_, the agent's action 7 | 8 |  update _belief\_state_ based on _action_ and _percept_ 9 |  calculate outcome probabilities for actions, 10 |    given action descriptions and current _belief\_state_ 11 |  select _action_ with highest expected utility 12 |    given probabilities of outcomes and utility information 13 |  __return__ _action_ 14 | 15 | --- 16 | __Figure__ ?? A decision\-theoretic agent that selects rational actions. 17 | -------------------------------------------------------------------------------- /md/Decision-List-Learning.md: -------------------------------------------------------------------------------- 1 | # DECISION-LIST-LEARNING 2 | 3 | ## AIMA3e 4 | __function__ DECISION-LIST-LEARNING(_examples_) __returns__ a decision list, or _failure_ 5 |  __if__ _examples_ is empty __then return__ the trivial decision list _No_ 6 |  _t_ ← a test that matches a nonempty subset _examplest_ of _examples_ 7 |    such that the members of _examplest_ are all positive or all negative 8 |  __if__ there is no such _t_ __then return__ _failure_ 9 |  __if__ the examples in _examplest_ are positive __then__ _o_ ← _Yes_ __else__ _o_ ← _No_ 10 |  __return__ a decision list with initial test _t_ and outcome _o_ and remaining tests given by 11 |     DECISION-LIST-LEARNING(_examples_ − _examplest_) 12 | 13 | --- 14 | __Figure ??__ An algorithm for learning decision lists. 15 | -------------------------------------------------------------------------------- /md/Decision-Tree-Learning.md: -------------------------------------------------------------------------------- 1 | # DECISION-TREE-LEARNING 2 | 3 | ## AIMA3e 4 | __function__ DECISION-TREE-LEARNING(_examples_, _attributes_, _parent\_examples_) __returns__ a tree 5 |  __if__ _examples_ is empty __then return__ PLURALITY\-VALUE(_parent\_examples_) 6 |  __else if__ all _examples_ have the same classification __then return__ the classification 7 |  __else if__ _attributes_ is empty __then return__ PLURALITY\-VALUE(_examples_) 8 |  __else__ 9 |    _A_ ← argmax_a_ ∈ _attributes_ IMPORTANCE(_a_, _examples_) 10 |    _tree_ ← a new decision tree with root test _A_ 11 |    __for each__ value _vk_ of _A_ __do__ 12 |      _exs_ ← \{ _e_ : _e_ ∈ _examples_ __and__ _e_._A_ = _vk_ \} 13 |      _subtree_ ← DECISION-TREE-LEARNING(_exs_, _attributes_ − _A_, _examples_) 14 |      add a branch to _tree_ with label \(_A_ = _vk_\) and subtree _subtree_ 15 |    __return__ _tree_ 16 | 17 | --- 18 | __Figure ??__ The decision\-tree learning algorithm. The function IMPORTANCE is described in Section __??__. The function PLURALITY\-VALUE selects the most common output value among a set of examples, breaking ties randomly. 19 | -------------------------------------------------------------------------------- /md/Depth-Limited-Search.md: -------------------------------------------------------------------------------- 1 | # DEPTH-LIMITED-SEARCH 2 | 3 | ## AIMA4e 4 | 5 | __function__ DEPTH-LIMITED-SEARCH(_problem_, _l_) __returns__ a solution, or failure, or cutoff 6 |  _frontier_ ← a FIFO queue initially containing one path, for the _problem_'s initial state 7 |  _solution_ ← failure 8 |  __while__ _frontier_ is not empty __do__ 9 |    _parent_ ← pop(_frontier_) 10 |    __if__ depth(_parent_) > l __then__ 11 |      _solution_ ← cutoff 12 |    __else__ 13 |      __for__ _child_ __in__ successors(_parent_) __do__ 14 |        __if__ _child_ is a goal __then__ 15 |          __return__ _child_ 16 |        add _child_ to __frontier__ 17 |  __return__ _solution_ 18 | 19 | --- 20 | __Figure 3.14__ An implementation of depth-limited tree search. The algorithm has two dif- 21 | ferent ways to signal failure to find a solution: it returns failure when it has exhausted all 22 | paths and proved there is no solution at any depth, and returns cutoff to mean there might be 23 | a solution at a deeper depth than l. Note that this algorithm does not keep track of reached 24 | states, and thus might visit the same state multiple times on different paths. 25 | 26 | ## AIMA3e 27 | __function__ DEPTH-LIMITED-SEARCH(_problem_,_limit_) __returns__ a solution, or failure/cutoff 28 |  __return__ RECURSIVE\-DLS(MAKE\-NODE(_problem_.INITIAL\-STATE),_problem_,_limit_) 29 | 30 | __function__ RECURSIVE\-DLS(_node_,_problem_,_limit_) __returns__ a solution, or failure/cutoff 31 |  __if__ _problem_.GOAL-TEST(_node_.STATE) __then return__ SOLUTION(_node_) 32 |  __else if__ _limit_ = 0 __then return__ _cutoff_ 33 |  __else__ 34 |    _cutoff\_occurred?_ ← false 35 |    __for each__ _action_ __in__ _problem_.ACTIONS(_node_.STATE) __do__ 36 |       _child_ ← CHILD\-NODE(_problem_,_node_,_action_) 37 |       _result_ ← RECURSIVE\-DLS(_child_,_problem_,_limit_\-1) 38 |       __if__ _result_ = _cutoff_ __then__ _cutoff\_occurred?_ ← true 39 |       __else if__ _result_ ≠ _failure_ __then return__ _result_ 40 |    __if__ _cutoff\_occurred?_ __then return__ _cutoff_ __else return__ _failure_ 41 | 42 | --- 43 | __Figure__ ?? A recursive implementation of depth\-limited tree search. 44 | -------------------------------------------------------------------------------- /md/Doubles-Tennis-Problem.md: -------------------------------------------------------------------------------- 1 | # DOUBLES-TENNIS-PROBLEM 2 | 3 | ## AIMA3e 4 | _Actors(A, B)_ 5 | _Init(At (A, LeftBaseline) ∧ At(B, RightNet ) ∧_ 6 |  _Approaching (Ball, RightBaseline)) ∧ Partner (A, B) ∧ Partner (B, A)_ 7 | _Goal (Returned (Ball) ∧ (At(a, RightNet ) ∨ At (a, LeftNet ))_ 8 | _Action(Hit(actor , Ball),_ 9 |  PRECOND: _Approaching (Ball, loc) ∧ At(actor , loc)_ 10 |  EFFECT: _Returned (Ball))_ 11 | _Action(Go(actor , to),_ 12 |  PRECOND: _At (actor , loc) ∧ to ≠ loc,_ 13 |  EFFECT: _At (actor , to) ∧ ¬ At (actor , loc))_ 14 | 15 | --- 16 | __Figure ??__ The doubles tennis problem. Two actors _A_ and _B_ are playing together and can be in 17 | one of four locations: _LeftBaseline_, _RightBaseline_, _LeftNet_ , and _RightNet_ . The ball can be returned 18 | only if a player is in the right place. Note that each action must include the actor as an argument. 19 | -------------------------------------------------------------------------------- /md/Elimination-Ask.md: -------------------------------------------------------------------------------- 1 | # ELIMINATION-ASK 2 | 3 | ## AIMA3e 4 | __function__ ELIMINATION-ASK(_X_, __e__, _bn_) __returns__ a distribution over _X_ 5 |  __inputs__: _X_, the query variable 6 |      __e__, observed values for variables __E__ 7 |      _bn_, a Bayesian network specifying joint distribution __P__(_X1_, …, _Xn_) 8 | 9 |  _factors_ ← \[\] 10 |  __for each__ _var_ __in__ ORDER(_bn_.VARS) __do__ 11 |    _factors_ ← \[MAKE\-FACTOR(_var_, __e__) | _factors_\] 12 |    __if__ _var_ is a hidden variable __then__ _factors_ ← SUM\-OUT(_var_, _factors_) 13 |  __return__ NORMALIZE(POINTWISE\-PRODUCT(_factors_)) 14 | 15 | --- 16 | __Figure__ ?? The variable elimination algorithm for inference in Bayesian networks. 17 | -------------------------------------------------------------------------------- /md/Enumeration-Ask.md: -------------------------------------------------------------------------------- 1 | # ENUMERATION-ASK 2 | 3 | ## AIMA3e 4 | __function__ ENUMERATION-ASK(_X_, __e__, _bn_) __returns__ a distribution over _X_ 5 |  __inputs__: _X_, the query variable 6 |      __e__, observed values for variables __E__ 7 |      _bn_, a Bayes net with variables \{_X_\} ⋃ __E__ ⋃ __Y__ /\* __Y__ = hidden variables \*/ 8 | 9 |  __Q__(_X_) ← a distribution over _X_, initially empty 10 |  __for each__ value _xi_ of _X_ __do__ 11 |    __Q__(_xi_) ← ENUMERATE\-ALL(_bn_.VARS, __e___x__i_) 12 |      where __e___x__i_ is __e__ extended with _X_ = _xi_ 13 |  __return__ NORMALIZE(__Q__(_X_)) 14 | 15 | --- 16 | __function__ ENUMERATE\-ALL(_vars_, __e__) __returns__ a real number 17 |  __if__ EMPTY?(_vars_) __then return__ 1.0 18 |  _Y_ ← FIRST(_vars_) 19 |  __if__ _Y_ has value _y_ in __e__ 20 |    __then return__ _P_(_y_ | _parents_(_Y_)) × ENUMERATE\-ALL(REST(_vars_), __e__) 21 |    __else return__ ∑_y_ _P_(_y_ | _parents_(_Y_)) × ENUMERATE\-ALL(REST(_vars_), __e___y_) 22 |      where __e___y_ is __e__ extended with _Y_ = _y_ 23 | 24 | --- 25 | __Figure__ ?? The enumeration algorithm for answering queries on Bayesian networks. 26 | -------------------------------------------------------------------------------- /md/FOL-BC-Ask.md: -------------------------------------------------------------------------------- 1 | # FOL-BC-ASK 2 | 3 | ## AIMA3e 4 | __function__ FOL-BC-ASK(_KB_, _query_) __returns__ a generator of substitutions 5 |  __return__ FOL-BC-OR(_KB_, _query_, { }) 6 | 7 | __generator__ FOL-BC-OR(_KB_, _goal_, _θ_) __yields__ a substitution 8 |  __for each__ rule (_lhs_ ⇒ _rhs_) __in__ FETCH-RULES-FOR-GOAL(_KB_, _goal_) __do__ 9 |    (_lhs_, _rhs_) ← STANDARDIZE-VARIABLES((_lhs_, _rhs_)) 10 |    __for each__ _θ_' __in__ FOL-BC-AND(_KB_, _lhs_, UNIFY(_rhs_, _goal_, _θ_)) __do__ 11 |      __yield__ _θ_' 12 | 13 | __generator__ FOL-BC-AND(_KB_, _goals_, _θ_) __yields__ a substitution 14 |  __if__ _θ_ = _failure_ __then return__ 15 |  __else if__ LENGTH(_goals_) = 0 __then yield__ _θ_ 16 |  __else do__ 17 |    _first_, _rest_ ← FIRST(_goals_), REST(_goals_) 18 |    __for each__ _θ_' in FOL-BC-OR(_KB_, SUBST(_θ_, _first_), _θ_) __do__ 19 |      __for each__ _θ_'' in FOL-BC-AND(_KB_, _rest_, _θ_') __do__ 20 |        __yield__ _θ_'' 21 | 22 | --- 23 | __Figure__ ?? A simple backward-chaining algorithm for first-order knowledge bases. 24 | -------------------------------------------------------------------------------- /md/FOL-FC-Ask.md: -------------------------------------------------------------------------------- 1 | # FOL-FC-ASK 2 | 3 | ## AIMA3e 4 | __function__ FOL-FC-ASK(_KB_, _α_) __returns__ a substitution or _false_ 5 |  __inputs__: _KB_, the knowledge base, a set of first order definite clauses 6 |      _α_, the query, an atomic sentence 7 |  __local variables__: _new_, the new sentences inferred on each iteration 8 | 9 |  __repeat until__ _new_ is empty 10 |    _new_ ← { } 11 |    __for each__ _rule_ __in__ _KB_ __do__ 12 |      (_p_1 ∧ ... ∧ _p_n ⇒ _q_) ← STANDARDIZE-VARAIBLES(_rule_) 13 |      __for each__ _θ_ such that SUBST(_θ_, _p_1 ∧ ... ∧ _p_n) = SUBST(_θ_, _p_'1 ∧ ... ∧ _p_'n) 14 |           for some _p_'1 ∧ ... ∧ _p_'n in _KB_ 15 |        _q_' ← SUBST(_θ_, _q_) 16 |        __if__ _q_' does not unify with some sentence already in _KB_ or _new_ __then__ 17 |          add _q_' to _new_ 18 |          _Φ_ _←_ UNIFY(_q_', _α_) 19 |          __if__ _Φ_ is not _fail_ __then return__ _Φ_ 20 |    add _new_ to _KB_ 21 |  __return__ _false_ 22 | 23 | --- 24 | __Figure__ ?? A conceptually straightforward, but very inefficient forward-chaining algorithm. On each iteration, it adds to _KB_ all the atomic sentences that can be inferred in one step from the implication sentences and the atomic sentences already in _KB_. The function STANDARDIZE-VARIABLES replaces all variables in its arguments with new ones that have not been used before. -------------------------------------------------------------------------------- /md/Fixed-Lag-Smoothing.md: -------------------------------------------------------------------------------- 1 | # FIXED-LAG-SMOOTHING 2 | 3 | ## AIMA3e 4 | __function__ FIXED-LAG-SMOOTHING(_et_, _hmm_, _d_) __returns__ a distribution over __X___t_−_d_ 5 |  __inputs__: _et_, the current evidence for time step _t_ 6 |      _hmm_, a hidden Markov model with _S_ × _S_ transition matrix __T__ 7 |      _d_, the length of the lag for smoothing 8 |  __persistent__: _t_, the current time, initially 1 9 |       __f__, the forward message __P__(_Xt_ | _e_1:_t_), initially _hmm_.PRIOR 10 |       __B__, the _d_\-step backward transformation matrix, initially the identity matrix 11 |       _et−d:t_, double\-ended list of evidence from _t_ − _d_ to _t_, initially empty 12 |  __local variables__: __O___t_−_d_, __O___t_, diagonal matrices containing the sensor model information 13 | 14 |  add _et_ to the end of _et−d:t_ 15 |  __O___t_ ← diagonal matrix containing __P__(_et_ | _Xt_) 16 |  __if__ _t_ > _d_ __then__ 17 |    __f__ ← FORWARD(__f__, _et_) 18 |     remove _e__t_−_d_−1 from the beginning of _et−d:t_ 19 |    __O___t_−_d_ ← diagonal matrix containing __P__(_et−d_ | _Xt−d_) 20 |    __B__ ← __O___t_−_d_−1__T__−1 __BTO___t_ 21 |  __else__ __B__ ← __BTO___t_ 22 |  _t_ ← _t_ + 1 23 |  __if__ _t_ > _d_ __then return__ NORMALIZE(__f__ × __B1__) __else return__ null 24 | 25 | --- 26 | __Figure ??__ An algorithm for smoothing with a fixed time lag of _d_ steps, implemented as an oline algorithm that outputs the new smoothed estimate given the observation for a new time step. Notice that the final output NORMALIZE(__f__ × __B1__) is just α __f__ × __b__, by Equation (__??__). 27 | -------------------------------------------------------------------------------- /md/Foil.md: -------------------------------------------------------------------------------- 1 | # FOIL 2 | 3 | ## AIMA3e 4 | __function__ Foil(_examples_, _target_) __returns__ a set of Horn clauses 5 |  __inputs__: _examples_, set of examples 6 |      _target_, a literal for the goal predicate 7 |  __local variables__: _clauses_, set of clauses, initially empty 8 | 9 |  __while__ _examples_ contains positive examples __do__ 10 |    _clause_ ← New-Clause(_examples_, _target_) 11 |    remove positive examples covered by _clause_ from _examples_ 12 |    add _clause_ to _clauses_ 13 |  __return__ _clauses_ 14 | 15 | --- 16 | __function__ New-Clause(_examples_, _target_) __returns__ a Horn clause 17 |  __local variables__: _clause_, a clause with _target_ as head and an empty body 18 |          _l_, a literal to be added to the clause 19 |          *extended_examples*, a set of examples with values for new variables 20 | 21 |  *extended_examples* ← _examples_ 22 |  __while__ *extended_examples* contains negative examples __do__ 23 |    _l_ ← Choose-Literal(New-Literals(_clause_), *extended_examples*) 24 |    append _l_ to the body of _clause_ 25 |    *extended_examples* ← set of examples created by applying Extend-Example 26 |     to each example in *extended_examples* 27 |  __return__ _clause_ 28 | 29 | --- 30 | __function__ Extend-Example(_example_, _literal_) __returns__ a set of examples 31 |  __if__ _example_ satisfies _literal_ 32 |    __then return__ the set of examples created by extending _example_ with 33 |     each possible constant value for each new variable in _literal_ 34 |  __else return__ the empty set 35 | 36 | --- 37 | __Function ??__ Sketch of the Foil algorithm for learning sets of first-order Horn clauses from examples. New-Literals and Choose-Literal are explained in the text. 38 | -------------------------------------------------------------------------------- /md/Forward-Backward.md: -------------------------------------------------------------------------------- 1 | # FORWARD-BACKWARD 2 | 3 | ## AIMA3e 4 | __function__ FORWARD-BACKWARD(__ev__, _prior_) __returns__ a vector of probability distributions 5 |  __inputs__: __ev__, a vector of evidence values for steps 1,…,_t_ 6 |      _prior_, the prior distribution on the initial state, __P__(__X__0) 7 |  __local variables__: __fv__, a vector of forward messages for steps 0,…,_t_ 8 |         __b__, a representation of the backward message, initially all 1s 9 |         __sv__, a vector of smoothed estimates for steps 1,…,_t_ 10 | 11 |  __fv__\[0\] ← _prior_ 12 |  __for__ _i_ = 1 __to__ _t_ __do__ 13 |    __fv__\[_i_\] ← FORWARD(__fv__\[_i_ − 1\], __ev__\[_i_\]) 14 |  __for__ _i_ = _t_ __downto__ 1 __do__ 15 |    __sv__\[_i_\] ← NORMALIZE(__fv__\[_i_\] × __b__) 16 |    __b__ ← BACKWARD(__b__, __ev__\[_i_\]) 17 |  __return__ __sv__ 18 | 19 | --- 20 | __Figure ??__ The forward\-backward algorithm for smoothing: computing posterior probabilities of a sequence of states given a sequence of observations. The FORWARD and BACKWARD operators are defined by Equations (__??__) and (__??__), respectively. 21 | -------------------------------------------------------------------------------- /md/Genetic-Algorithm.md: -------------------------------------------------------------------------------- 1 | # GENETIC-ALGORITHM 2 | 3 | ## AIMA4e 4 | 5 | __function__ GENETIC-ALGORITHM(_population_, FITNESS\-FN) __returns__ an individual 6 |  __inputs__: _population_, the initial random population of individuals 7 |     FITNESS\-FN, a function that measures the fitness of an individual 8 | 9 |  __repeat__ 10 |    _population_ ← [MUTATE(RECOMBINE(SELECT(2, _population_, FITNESS\-FN))) 11 |           __for__ _i_ __in__ _population_] 12 |  __until__ some individual is fit enough, or enough time has elapsed 13 |  __return__ the best individual in _population_, according to FITNESS\-FN 14 | 15 | --- 16 | __function__ SELECT(ρ, _population_, FITNESS\-FN) __returns__ a set of ρ individuals 17 |  _selection_ ← a uniform random sample of 2 * ρ individuals from _population_ 18 |  __return__ the top ρ individuals in _selection_, ranked by FITNESS\-FN 19 | 20 | --- 21 | __function__ RECOMBINE(_x_, _y_) __returns__ an individual 22 |  __inputs__: _x_,_y_, parent individuals 23 | 24 |  _n_ ← LENGTH(_x_) 25 |  _crossover_ ← random integer from 0 to _n_ 26 |  __return__ APPEND(_x_\[0:_crossover_\], _y_\[_crossover_: _n_\]) 27 | 28 | --- 29 | __Figure__ ?? A genetic algorithm. The algorithm is the same as the one diagrammed in Figure ??, with one variation: in this version, each recombination of two parents produces only one offspring, not two. 30 | 31 | ## AIMA3e 32 | __function__ GENETIC-ALGORITHM(_population_,FITNESS\-FN) __returns__ an individual 33 |  __inputs__: _population_, a set of individuals 34 |     FITNESS\-FN, a function that measures the fitness of an individual 35 | 36 |  __repeat__ 37 |    _new\_population_ ← empty set 38 |    __for__ _i_ = 1 to SIZE(_population_) __do__ 39 |      _x_ ← RANDOM-SELECTION(_population_,FITNESS\-FN) 40 |      _y_ ← RANDOM-SELECTION(_population_,FITNESS\-FN) 41 |      _child_ ← REPRODUCE(_x_,_y_) 42 |      __if__ (small random probability) __then__ _child_ ← MUTATE(_child_) 43 |      add _child_ to _new\_population_ 44 |    _population_ ← _new\_population_ 45 |  __until__ some individual is fit enough, or enough time has elapsed 46 |  __return__ the best individual in _population_, according to FITNESS\-FN 47 | 48 | --- 49 | __function__ REPRODUCE(_x_, _y_) __returns__ an individual 50 |  __inputs__: _x_,_y_, parent individuals 51 | 52 |  _n_ ← LENGTH(_x_); _c_ ← random number from 1 to _n_ 53 |  __return__ APPEND(SUBSTRING(_x_, 1, _c_),SUBSTRING(_y_, _c_+1, _n_)) 54 | 55 | --- 56 | __Figure__ ?? A genetic algorithm. The algorithm is the same as the one diagrammed in Figure ??, with one variation: in this more popular version, each mating of two parents produces only one offspring, not two. 57 | -------------------------------------------------------------------------------- /md/Gibbs-Ask.md: -------------------------------------------------------------------------------- 1 | # GIBBS-ASK 2 | 3 | ## AIMA3e 4 | __function__ GIBBS-ASK(_X_, __e__, _bn_, _N_) __returns__ an estimate of __P__(_X_ | __e__) 5 |  __local variables__: __N__, a vector of counts for each value of _X_, initially zero 6 |         __Z__, the nonevidence variables in _bn_ 7 |         __x__, the current state of the network, initially copied from __e__ 8 | 9 |  initialize __x__ with random values for the variables in __Z__ 10 |  __for__ _j_ = 1 to _N_ __do__ 11 |    __for each__ _Zi_ in __Z__ __do__ 12 |      set the value of _Zi_ in __x__ by sampling from __P__(_Zi_ | _mb_(_Zi_)) 13 |      __N__\[_x_\] ← __N__\[_x_\] + 1 where _x_ is the value of _X_ in __x__ 14 |  __return__ NORMALIZE(__N__) 15 | 16 | --- 17 | __Figure__ ?? The Gibbs sampling algorithm for approximate inference in Bayesian networks; this version cycles through the variables, but choosing variables at random also works. 18 | 19 | --- 20 | 21 | ## AIMA4e 22 | __function__ GIBBS-ASK(_X_, __e__, _bn_, _N_) __returns__ an estimate of __P__(_X_ | __e__) 23 |  __local variables__: __N__, a vector of counts for each value of _X_, initially zero 24 |         __Z__, the nonevidence variables in _bn_ 25 |         __x__, the current state of the network, initially copied from __e__ 26 | 27 |  initialize __x__ with random values for the variables in __Z__ 28 |  __for__ _j_ = 1 to _N_ __do__ 29 |    __choose__ any variable _Zi_ from __Z__ acoording to any distribution _ρ(i)_ 30 |      set the value of _Zi_ in __x__ by sampling from __P__(_Zi_ | _mb_(_Zi_)) 31 |      __N__\[_x_\] ← __N__\[_x_\] + 1 where _x_ is the value of _X_ in __x__ 32 |  __return__ NORMALIZE(__N__) 33 | 34 | --- 35 | __Figure__ ?? The Gibbs sampling algorithm for approximate inference in Bayesian networks; this version cycles through the variables, but choosing variables at random also works. 36 | -------------------------------------------------------------------------------- /md/GraphPlan.md: -------------------------------------------------------------------------------- 1 | # GRAPHPLAN 2 | 3 | ## AIMA3e 4 | __function__ GRAPHPLAN(_problem_) __returns__ solution or failure 5 | 6 |  _graph_ ← INITIAL\-PLANNING\-GRAPH(_problem_) 7 |  _goals_ ← CONJUNCTS(_problem_.GOAL) 8 |  _nogoods_ ← an empty hash table 9 |  __for__ _tl_ = 0 __to__ ∞ __do__ 10 |    __if__ _goals_ all non\-mutex in _S_t of _graph_ __then__ 11 |      _solution_ ← EXTRACT\-SOLUTION(_graph_, _goals_, NUMLEVELS(_graph_), _nogoods_) 12 |      __if__ solution ≠ _failure_ __then return__ _solution_ 13 |    __if__ _graph_ __and__ _nogoods_ have both leveled off __then return__ _failure_ 14 |    _graph_ ← EXPAND\-GRAPH(_graph_, _problem_) 15 | 16 | --- 17 | __Figure ??__ The GRAPHPLAN algorithm. GRAPHPLAN calls EXPAND-GRAPH to add a level until either a solution is found by EXTRACT-SOLUTION, or no solution is possible. 18 | -------------------------------------------------------------------------------- /md/Have-Cake-And-Eat-Cake-Too.md: -------------------------------------------------------------------------------- 1 | # HAVE-CAKE-AND-EAT-CAKE-TOO-PROBLEM 2 | 3 | ## AIMA3e 4 | _Init_(_Have_(_Cake_)) 5 | _Goal_(_Have_(_Cake_) ∧ _Eaten_(_Cake_)) 6 | _Action_(_Eat_(_Cake_) 7 |  PRECOND: _Have_(_Cake_) 8 |  EFFECT: ¬ _Have_(_Cake_) ∧ _Eaten_(_Cake_)) 9 | _Action_(_Bake_(_Cake_) 10 |  PRECOND: ¬ _Have_(_Cake_) 11 |  EFFECT: _Have_(_Cake_)) 12 | 13 | --- 14 | __Figure ??__ The "have cake and eat cake too" problem. 15 | -------------------------------------------------------------------------------- /md/Hierarchical-Search.md: -------------------------------------------------------------------------------- 1 | # HIERARCHICAL-SEARCH 2 | 3 | ## AIMA3e 4 | __function__ HIERARCHICAL-SEARCH(_problem_, _hierarchy_) __returns__ a solution, or failure 5 |  _frontier_ ← a FIFO queue with \[_Act_\] as the only element 6 |  __loop do__ 7 |    __if__ EMPTY?(_frontier_) __then return__ _failure_ 8 |    _plan_ ← POP(_frontier_) /\* chooses the shallowest plan in frontier \*/ 9 |    _hla_ ← the first HLA in _plan_, or _null_ if none 10 |    _prefix_,_suffix_ ← the action subsequences before and after _hla_ in plan 11 |    _outcome_ ← RESULT(_problem_.INITIAL\-STATE, _prefix_) 12 |    __if__ _hla_ is null __then__ /\* so _plan_ is primitive and _outcome_ is its result \*/ 13 |      __if__ _outcome_ satisfies _problem_.GOAL __then return__ _plan_ 14 |    __else for each__ _sequence_ __in__ REFINEMENTS(_hla_, _outcome_, _hierarchy_) __do__ 15 |      _frontier_ ← INSERT(APPEND(_prefix_, _sequence_, _suffix_), _frontier_) 16 | 17 | --- 18 | __Figure__ ?? A breadth\-first implementation of hierarchical forward planning search. The initial plan supplied to the algorithm is \[_Act_\]. The REFINEMENTS function returns a set of action sequences, one for each refinement of the HLA whose preconditions are satisfied by the specified state, _outcome_. 19 | -------------------------------------------------------------------------------- /md/Hill-Climbing.md: -------------------------------------------------------------------------------- 1 | # HILL-CLIMBING 2 | 3 | ## AIMA4e 4 | 5 | __function__ HILL-CLIMBING(_problem_) __returns__ a state that is a local maximum 6 |  _current_ ← _problem_.INITIAL\-STATE 7 |  __loop do__ 8 |    _neighbor_ ← a highest\-valued successor of _current_ 9 |    _if_ VALUE(_neighbour_) ≤ VALUE(_current_) __then return__ _current_ 10 |    _current_ ← _neighbor_ 11 | 12 | --- 13 | __Figure 4.2__ The hill-climbing search algorithm, which is the most basic local search technique. At each step the current node is replaced by the best neighbor. 14 | 15 | ## AIMA3e 16 | __function__ HILL-CLIMBING(_problem_) __returns__ a state that is a local maximum 17 |  _current_ ← MAKE\-NODE(_problem_.INITIAL\-STATE) 18 |  __loop do__ 19 |    _neighbor_ ← a highest\-valued successor of _current_ 20 |    __if__ _neighbor_.VALUE ≤ _current_.VALUE __then return__ _current_.STATE 21 |    _current_ ← _neighbor_ 22 | 23 | --- 24 | __Figure ??__ The hill\-climbing search algorithm, which is the most basic local search technique. At each step the current node is replaced by the best neighbor; in this version, that means the neighbor with the highest VALUE, but if a heuristic cost estimate _h_ is used, we would find the neighbor with the lowest _h_. 25 | -------------------------------------------------------------------------------- /md/Hits.md: -------------------------------------------------------------------------------- 1 | # HITS 2 | 3 | ## AIMA3e 4 | __function__ HITS(_query_) __returns__ _pages_ with hub and authority numbers 5 |  _pages_ ← Expand-Pages(Relevant-Pages(_query_)) 6 |  __for each__ _p_ __in__ _pages_ __do__ 7 |   _p_.Authority ← 1 8 |   _p_.Hub ← 1 9 |  __repeat until__ convergence __do__ 10 |   __for each__ _p_ __in__ _pages_ __do__ 11 |    _p_.Authority ← ∑i Inlinki(_p_).Hub 12 |    _p_.Hub ← ∑i Outlinki(_p_).Authority 13 |   Normalize(_pages_) 14 |  __return__ _pages_ 15 | 16 | --- 17 | __Figure ??__ The HITS algorithm for computing hubs and authorities with respect to a query. Relevant-Pages fetches the pages that match the query, and Expand-Pages adds in every page that links to or is linked from one of the relevant pages. Normalize divides each page's score by the square root of sum of the squares of all pages' scores (separately for both the authority and hubs scores). 18 | -------------------------------------------------------------------------------- /md/Hybrid-Wumpus-Agent.md: -------------------------------------------------------------------------------- 1 | # HYBRID-WUMPUS-AGENT 2 | 3 | ## AIMA3e 4 | __function__ HYBRID-WUMPUS-AGENT(_percept_) __returns__ an _action_ 5 |  __inputs__: _percept_, a list, \[_stench_, _breeze_, _glitter_, _bump_, _scream_\] 6 |  __persistent__: _KB_, a knowledge base, initially the atemporal "wumpus physics" 7 |       _t_, a counter, initially 0, indicating time 8 |       _plan_, an action sequence, initially empty 9 | 10 |  TELL(_KB_, MAKE-PERCEPT-SENTENCE(_percept_, _t_)) 11 |  TELL the _KB_ the temporal "physics" sentences for time _t_ 12 |  _safe_ ← {\[_x_, _y_\] : ASK(_KB_, _OK__t__x_,_y_) = _true_} 13 |  __if__ ASK(_KB_, _Glitter__t_) = _true_ __then__ 14 |    _plan_ ← \[_Grab_\] + PLAN-ROUTE(_current_, {\[1,1\]}, _safe_) + \[_Climb_\] 15 |  __if__ _plan_ is empty __then__ 16 |    _unvisited_ ← {\[_x_, _y_\] : ASK(_KB_, _L__t'__x_,_y_) = _false_ for all _t'_ ≤ _t_} 17 |    _plan_ ← PLAN-ROUTE(_current_, _unvisited_ ∩ _safe_, _safe_) 18 |  __if__ _plan_ is empty and ASK(_KB_, _HaveArrow__t_) = _true_ __then__ 19 |    _possible\_wumpus_ ← {\[_x_, _y_\] : ASK(_KB_, ¬_W__x_,_y_) = _false_} 20 |    _plan_ ← PLAN-SHOT(_current_, _possible\_wumpus_, _safe_) 21 |  __if__ _plan_ is empty __then__ //no choice but to take a risk 22 |    _not\_unsafe_ ← {\[_x_, _y_\] : ASK(_KB_, ¬_OK__t__x_,_y_) = _false_} 23 |    _plan_ ← PLAN-ROUTE(_current_, _unvisited_ ∩ _not\_unsafe_, _safe_) 24 |  __if__ _plan_ is empty __then__ 25 |    _plan_ ← PLAN-ROUTE(_current_, {\[1,1\]}, _safe_) + \[_Climb_\] 26 |  _action_ ← POP(_plan_) 27 |  TELL(_KB_, MAKE-ACTION-SENTENCE(_action_, _t_)) 28 |  _t_ ← _t_ + 1 29 |  __return__ _action_ 30 | 31 | --- 32 | __function__ PLAN-ROUTE(_current_, _goals_, _allowed_) __returns__ an action sequence 33 |  __inputs__: _current_, the agent's current position 34 |      _goals_, a set of squares; try to plan a route to one of them 35 |      _allowed_, a set of squares that can form part of the route 36 | 37 |  _problem_ ← ROUTE-PROBLEM(_current_, _goals_, _allowed_) 38 |  __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/Information-Gathering-Agent.md: -------------------------------------------------------------------------------- 1 | # INFORMATION-GATHERING-AGENT 2 | 3 | ## AIMA3e 4 | __function__ INFORMATION-GATHERING-AGENT(_percept_) __returns__ an action 5 |  __persistent__: _D_, a decision network 6 | 7 |  integrate _percept_ into _D_ 8 |  _j_ ← the value that maximizes _VPI_(_Ej_) / _Cost_(_Ej_) 9 |  __if__ _VPI_(_Ej_) > _Cost_(_Ej_) 10 |    __return__ REQUEST(_Ej_) 11 |  __else return__ the best action from _D_ 12 | 13 | --- 14 | __Figure ??__ Design of a simple information-gathering agent. The agent works by repeatedly selecting the observation with the highest information value, until the cost of the next observation is greater than its expected benefit. 15 | -------------------------------------------------------------------------------- /md/Iterative-Deepening-Search.md: -------------------------------------------------------------------------------- 1 | # ITERATIVE-DEEPENING-SEARCH 2 | 3 | ## AIMA3e / AIMA4e 4 | __function__ ITERATIVE-DEEPENING-SEARCH(_problem_) __returns__ a solution, or failure 5 |  __for__ _depth_ = 0 to ∞ __do__ 6 |    _result_ ← DEPTH\-LIMITED\-SEARCH(_problem_,_depth_) 7 |    __if__ _result_ ≠ cutoff __then return__ _result_ 8 | 9 | --- 10 | __Figure__ ?? The iterative deepening search algorithm, which repeatedly applies depth\-limited search with increasing limits. It terminates when a solution is found or if the depth\-limited search returns _failure_, meaning that no solution exists. 11 | -------------------------------------------------------------------------------- /md/Job-Shop-Scheduling-Problem.md: -------------------------------------------------------------------------------- 1 | # JOB-SHOP-SCHEDULING-PROBLEM 2 | 3 | ## AIMA3e 4 | _Jobs({AddEngine1 ≺ AddWheels1 ≺ Inspect1 },_ 5 |  _{AddEngine2 ≺ AddWheels2 ≺ Inspect2 })_ 6 | _Resources(EngineHoists(1), WheelStations(1), Inspectors(2), LugNuts(500))_ 7 | _Action(AddEngine1_, DURATION: 30, 8 |  USE: _EngineHoists(1))_ 9 | _Action(AddEngine2_, DURATION: 60, 10 |  USE: _EngineHoists(1))_ 11 | _Action(AddWheels1_, DURATION: 30, 12 |  CONSUME: _LugNuts(20),_ USE: _WheelStations(1))_ 13 | _Action(AddWheels2_, DURATION: 15, 14 |  CONSUME: _LugNuts(20)_, USE: _WheelStations(1))_ 15 | _Action(Inspecti_, DURATION: 10, 16 |  USE: _Inspectors(1))_ 17 | 18 | --- 19 | __Figure ??__ A job-shop scheduling problem for assembling two cars, with resource constraints. The 20 | notation _A_ ≺ _B_ means that action _A_ must precede action _B_. 21 | -------------------------------------------------------------------------------- /md/KB-Agent.md: -------------------------------------------------------------------------------- 1 | # KB-AGENT 2 | 3 | ## AIMA3e 4 | __function__ KB-AGENT(_percept_) __returns__ an _action_ 5 |  __persistent__: _KB_, a knowledge base 6 |       _t_, a counter, initially 0, indicating time 7 | 8 |  TELL(_KB_, MAKE\-PERCEPT\-SENTENCE(_percept_, _t_)) 9 |  _action_ ← ASK(_KB_, MAKE\-ACTION\-QUERY(_t_)) 10 |  TELL(_KB_, MAKE\-ACTION\-SENTENCE(_action_, _t_)) 11 |  _t_ ← _t_ + 1 12 |  __return__ _action_ 13 | 14 | --- 15 | __Figure__ ?? A generic knowledge\-based agent. Given a percept, the agent adds the percept to its knowledge base, asks the knowledge base for the best action, and tells the knowledge base that it has in fact taken that action. 16 | -------------------------------------------------------------------------------- /md/LRTAStar-Agent.md: -------------------------------------------------------------------------------- 1 | # LRTA\*\-AGENT 2 | 3 | ## AIMA3e 4 | __function__ LRTA\*\-AGENT(_s'_) __returns__ an action 5 |  __inputs__: _s'_, a percept that identifies the current state 6 |  __persistent__: _result_, a table, indexed by state and action, initially empty 7 |       _H_, a table of cost estimates indexed by state, initially empty 8 |       _s_, _a_, the previous state and action, initially null 9 | 10 |  __if__ GOAL\-TEST(_s'_) __then return__ _stop_ 11 |  __if__ _s'_ is a new state (not in _H_) __then__ _H_\[_s'_\] ← _h_(_s'_) 12 |  __if__ _s_ is not null 13 |    _result_\[_s_, _a_\] ← _s'_ 14 |    _H_\[_s_\] ←  __min__  LRTA\*\-COST(_s_, _b_, _result_\[_s_, _b_\], _H_) 15 |       _b_ ∈ ACTIONS(_s_) 16 |  _a_ ← an action _b_ in ACTIONS(_s'_) that minimizes LRTA\*\-COST(_s'_, _b_, _result_\[_s'_, _b_\], _H_) 17 |  _s_ ← _s'_ 18 |  __return__ a 19 | 20 | __function__ LRTA\*\-COST(_s_, _a_, _s'_, _H_) __returns__ a cost estimate 21 |  __if__ _s'_ is undefined __then return__ _h_(_s_) 22 |  __else return__ c(_s_, _a_, _s'_) + _H_\[_s'_\] 23 | 24 | --- 25 | __Figure__ ?? LRTA\*\-AGENT selects an action according to the values of neighboring states, which are updated as the agent moves about the state space. 26 | -------------------------------------------------------------------------------- /md/Likelihood-Weighting.md: -------------------------------------------------------------------------------- 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__(_X1_, …, _Xn_) 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 _Xi_ __in__ _X1_, …, _Xn_ __do__ 20 |    __if__ _Xi_ is an evidence variable with value _xi_ in __e__ 21 |      __then__ _w_ ← _w_ × _P_(_Xi_ = _xi_ | _parents_(_Xi_)) 22 |      __else__ __x__\[i\] ← a random sample from __P__(_Xi_ | _parents_(_Xi_)) 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. 27 | -------------------------------------------------------------------------------- /md/Min-Conflicts.md: -------------------------------------------------------------------------------- 1 | # MIN-CONFLICTS 2 | 3 | ## AIMA3e 4 | __function__ MIN-CONFLICTS(_csp_, _max\_steps_) __returns__ a solution of failure 5 |  __inputs__: _csp_, a constraint satisfaction problem 6 |     _max\_steps_, the number of steps allowed before giving up 7 | 8 |  _current_ ← an initial complete assignment for _csp_ 9 |  __for__ _i_ = 1 to _max\_steps_ __do__ 10 |    __if__ _current_ is a solution for _csp_ __then return__ _current_ 11 |    _var_ ← a randomly chosen conflicted variable from _csp_.VARIABLES 12 |    _value_ ← the value _v_ for _var_ that minimizes CONFLICTS(_var_, _v_, _current_, _csp_) 13 |    set _var_ = _value_ in _current_ 14 |  __return__ _failure_ 15 | 16 | --- 17 | __Figure__ ?? The MIN-CONFLICTS algorithm for solving CSPs by local search. The initial state may be chosen randomly or by a greedy assignment process that chooses a minimal\-conflict value for each variable in turn. The CONFLICTS function counts the number of constraints violated by a particular value, given the rest of the current assignment. 18 | -------------------------------------------------------------------------------- /md/Minimal-Consistent-Det.md: -------------------------------------------------------------------------------- 1 | # MINIMAL-CONSISTENT-DET 2 | 3 | ## AIMA3e 4 | __function__ Minimal-Consistent-Det(_E_, _A_) __returns__ a set of attributes 5 |  __inputs__: _E_, a set of examples 6 |      _A_, a set of attributes, of size _n_ 7 | 8 |  __for__ _i_ = 0 __to__ _n_ __do__ 9 |    __for each__ subset _Ai_ of _A_ of size _i_ __do__ 10 |      __if__ Consistent-Det?(_Ai_, _E_) __then return__ _Ai_ 11 | 12 | --- 13 | __function__ Consistent-Det?(_A_, _E_) __returns__ a truth value 14 |  __inputs__: _A_, a set of attributes 15 |      _E_, a set of examples 16 |  __local variables__: _H_, a hash table 17 | 18 |  __for each__ example _e_ __in__ _E_ __do__ 19 |    __if__ some example in _H_ has the same values as _e_ for the attributes _A_ 20 |     but a different classification __then return__ _false_ 21 |    store the class of _e_ in_H_, indexed by the values for attributes _A_ of the example _e_ 22 |  __return__ _true_ 23 | 24 | --- 25 | __Figure ??__ An algorithm for finding a minimal consistent determination. 26 | -------------------------------------------------------------------------------- /md/Minimax-Decision.md: -------------------------------------------------------------------------------- 1 | # MINIMAX-DECISION and EXPECTIMINIMAX 2 | 3 | ## AIMA3e 4 | __function__ MINIMAX-DECISION(_state_) __returns__ _an action_ 5 |  __return__ arg max _a_ ∈ ACTIONS(_s_) MIN\-VALUE(RESULT(_state_, _a_)) 6 | 7 | --- 8 | __function__ MAX\-VALUE(_state_) __returns__ _a utility value_ 9 |  __if__ TERMINAL\-TEST(_state_) __then return__ UTILITY(_state_) 10 |  _v_ ← −∞ 11 |  __for each__ _a_ __in__ ACTIONS(_state_) __do__ 12 |    _v_ ← MAX(_v_, MIN\-VALUE(RESULT(_state_, _a_))) 13 |  __return__ _v_ 14 | 15 | --- 16 | __function__ MIN\-VALUE(_state_) __returns__ _a utility value_ 17 |  __if__ TERMINAL\-TEST(_state_) __then return__ UTILITY(_state_) 18 |  _v_ ← ∞ 19 |  __for each__ _a_ __in__ ACTIONS(_state_) __do__ 20 |    _v_ ← MIN(_v_, MAX\-VALUE(RESULT(_state_, _a_))) 21 |  __return__ _v_ 22 | 23 | --- 24 | __Figure__ ?? An algorithm for calculating minimax decisions. It returns the action corresponding to the best possible move, that is, the move that leads to the outcome with the best utility, under the assumption that the opponent plays to minimize utility. The functions MAX\-VALUE and MIN\-VALUE go through the whole game tree, all the way to the leaves, to determine the backed\-up value of a state. The notation argmax _a_ ∈ _S_ _f_(_a_) computes the element _a_ of set _S_ that has maximum value of _f_(_a_). 25 | 26 | --- 27 | __function__ EXPECTIMINIMAX(_s_) = 28 |  UTILITY(_s_) __if__ TERMINAL\-TEST(_s_) 29 |  max_a_ EXPECTIMINIMAX(RESULT(_s, a_)) __if__ PLAYER(_s_)= MAX 30 |  min_a_ EXPECTIMINIMAX(RESULT(_s, a_)) __if__ PLAYER(_s_)= MIN 31 |  ∑_r_ P(_r_) EXPECTIMINIMAX(RESULT(_s, r_)) __if__ PLAYER(_s_)= CHANCE 32 | -------------------------------------------------------------------------------- /md/Model-Based-Reflex-Agent.md: -------------------------------------------------------------------------------- 1 | # MODEL-BASED-REFLEX-AGENT 2 | 3 | ## AIMA3e 4 | __function__ MODEL-BASED-REFLEX-AGENT(_percept_) __returns__ an action 5 |  __persistent__: _state_, the agent's current conception of the world state 6 |       _model_, a description of how the next state depends on current state and action 7 |       _rules_, a set of condition\-action rules 8 |       _action_, the most recent action, initially none 9 | 10 |  _state_ ← UPDATE-STATE(_state_, _action_, _percept_, _model_) 11 |  _rule_ ← RULE-MATCH(_state_,_rules_) 12 |  _action_ ← _rule_.ACTION 13 |  __return__ _action_ 14 | 15 | --- 16 | __Figure__ ?? A model-based reflex agent. It keeps track of the current state of the world, using an internal model. It then chooses an action in the same way as the reflex agent. 17 | -------------------------------------------------------------------------------- /md/Model-Selection.md: -------------------------------------------------------------------------------- 1 | # MODEL-SELECTION 2 | 3 | ## AIMA4e 4 | __function__ MODEL-SELECTION(_Learner_, _examples_, _k_) __returns__ a hypothesis 5 |  __local variables__: _err_, an array, indexed by _size_, storing validation\-set error rates 6 |  __for__ _size_ = 1 __to__ ∞ __do__ 7 |    _err_\[_size_\] ← CROSS\-VALIDATION(_Learner_, _size_, _examples_, _k_) 8 |    __if__ _err_ is starting to increase significantly __then do__ 9 |      _best\_size_ ← the value of _size_ with minimum _err_\[_size_\] 10 |      __return__ _Learner_(_best\_size_, _examples_) 11 | 12 | --- 13 | __function__ CROSS\-VALIDATION(_Learner_, _size_, _examples_, _k_) __returns__ average training set error rate: 14 |  _errs_ ← 0 15 |  __for__ _fold_ = 1 __to__ _k_ __do__ 16 |    _training\_set_, _validation\_set_ ← PARTITION(_examples_, _fold_, _k_) 17 |    _h_ ← _Learner_(_size_, _training\_set_) 18 |    _errs_ ← _errs_ + ERROR\-RATE(_h_, _validation\_set_) 19 |  __return__ _errs_ ⁄ _k_ // average error rate on validation sets, across k-fold cross-validation 20 | 21 | --- 22 | 23 | Figure?? An algorithm to select the model that has the lowest error rate on validation data by building models of increasing complexity, and choosing the one with best empirical error rate, _err_, on validation data. _Learner_(_size_, _exmaples_) returns a hypothesis whose complexity is set by the parameter _size_, and which is trained on the _examples_. PARTITION(_examples_, _fold_, _k_) splits _examples_ into two subsets: a validation set of size _N_ ⁄ _k_ and a training set with all the other examples. The split is different for each value of _fold_. 24 | 25 | --- 26 | 27 | In the fourth edition, cross vaidation wrapper has been renamed to Model-Selection. 28 | 29 | -------------------------------------------------------------------------------- /md/Monte-Carlo-Localization.md: -------------------------------------------------------------------------------- 1 | # MONTE-CARLO-LOCALIZATION 2 | 3 | ## AIMA3e 4 | __function__ MONTE-CARLO-LOCALIZATION(_a_, _z_, _N_, _P_(_X'_|_X_, _v_, _w_), _P_(_z_|_z\*_), _m_) __returns__ a set of samples for the next time step 5 |  __inputs__: _a_, robot velocities _v_ and _w_ 6 |      _z_, range scan _z1_,..., _zM_ 7 |      _P_(_X'_|_X_,_v_,_w_), motion model 8 |      _P_(_z_|_z\*_), range sensor noise model 9 |      _m_, 2D map of the environment 10 |  __persistent__: _S_, a vector of samples of size _N_ 11 |  __local variables__: _W_, a vector of weights of size _N_ 12 |           _S'_, a temporary vector of particles of size _N_ 13 |           _W'_, a vector of weights of size _N_ 14 | 15 |  __if__ _S_ is empty __then__   /\* initialization phase \*/ 16 |    __for__ _i_ = 1 to _N_ __do__ 17 |      _S_[_i_] ← sample from _P_(_X0_) 18 |  __for__ _i_ = 1 to _N_ __do__  /\* update cycle \*/ 19 |    _S'_[_i_] ← sample from _P_(_X'_|_X_ = _S_[_i_], _v_, _w_) 20 |    _W'_[_i_] ← 1 21 |    __for__ _j_ = 1 to _M_ __do__ 22 |       _z_\* ← RAYCAST(_j_, _X_ = _S'_[_i_], _m_) 23 |       _W'_[_i_] ← _W'_[_i_] . _P_(_zj_|_z\*_) 24 |  _S_ ← WEIGHTED-SAMPLE-WITH-REPLACEMENT(_N_, _S'_, _W'_) 25 |  __return__ _S_ 26 | 27 | --- 28 | __FIGURE ??__ A Monte Carlo localization algorithm using a range-scan sensor model with independent noise. 29 | -------------------------------------------------------------------------------- /md/Monte-Carlo-Tree-Search.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # MONTE-CARLO-TREE-SEARCH 5 | 6 | ## AIMA4e 7 | __function__ MONTE-CARLO-TREE-SEARCH(_state_) __returns__ an action 8 |  tree ← NODE(_state_) 9 |  __while__ TIME\-REMAINING() __do__ 10 |    __tree__ ← PLAYOUT(_tree_) 11 |  __return__ the _move_ in ACTIONS(_state_) with highest Q(_state_,_move_) 12 | 13 | --- 14 | 15 | __function__ PLAYOUT(_tree_) __returns__ _updated tree_ 16 |  _node_ ← _tree_ 17 |  __while__ _node_ is not terminal and was already in _tree_ __do__ 18 |    _move_ ← SELECT(_node_) 19 |    _node_ ← FOLLOW\-LINK(_node_,_move_) 20 |  _outcome_ ← SIMULATION(_node_.STATE) 21 |  UPDATE(_node_,_outcome_) 22 |  __return__ _tree_ 23 | 24 | --- 25 | 26 | __function__ SELECT(_node_) __returns__ _an action_ 27 |  __return__ argmaxm ∈ FEASIBLE\-ACTIONS(_node_) UCB(RESULT(_node_,_m_)) 28 | 29 | --- 30 | 31 | __function__ UCB(_child_) __returns__ _a number_ 32 |  __return__ _child_.VALUE + C × 33 | 34 | 35 | --- 36 | __FIGURE ??__ The Monte Carlo tree search algorithm. A game tree, _tree_, is initialized, and then grows by one node with each call to PLAYOUT. The function SELECT chooses a move that best balances exploitation and exploration according to the UCB formula. FOLLOW-LINK traverses from the current node by making a move; this could be to a previously-seen node, or to a new node that is added to the tree. Once we have added a new node, we exit the __while__ loop and SIMULATION chooses moves (with a randomized policy that is designed to favor good moves but to compute quickly) until the game is over. Then, UPDATE updates all the nodes in the tree from node to the root, recording the fact that the path led to the final __outcome__. 37 | -------------------------------------------------------------------------------- /md/Online-DFS-Agent.md: -------------------------------------------------------------------------------- 1 | # ONLINE-DFS-AGENT 2 | 3 | ## AIMA3e 4 | __function__ ONLINE-DFS-AGENT(_s'_) __returns__ an action 5 |  __inputs__: _s'_, a percept that identifies the current state 6 |  __persistent__: _result_, a table indexed by state and action, initially empty 7 |       _untried_, a table that lists, for each state, the actions not yet tried 8 |       _unbacktracked_, a table that lists, for each state, the backtracks not yet tried 9 |       _s_, _a_, the previous state and action, initially null 10 | 11 |  __if__ GOAL\-TEST(_s'_) __then return__ _stop_ 12 |  __if__ _s'_ is a new state (not in _untried_) __then__ _untried_\[_s'_\] ← ACTIONS(_s'_) 13 |  __if__ _s_ is not null and _s'_ != _result_\[_s_, _a_\] __then__ 14 |    _result_\[_s_, _a_\] ← _s'_ 15 |    add _s_ to front of _unbacktracked_\[_s'_\] 16 |  __if__ _untried_\[_s'_\] is empty __then__ 17 |    __if__ _unbacktracked_\[_s'_\] is empty __then return__ _stop_ 18 |    __else__ _a_ ← an action _b_ such that _result_\[_s'_, _b_\] = POP(_unbacktracked_\[_s'_\]) 19 |  __else__ _a_ ← POP(_untried_\[_s'_\]) 20 |  _s_ ← _s'_ 21 |  __return__ _a_ 22 | 23 | --- 24 | __Figure__ ?? An online search agent that uses depth-first exploration. The agent is applicable only in state spaces in which every action can be "undone" by some other action. 25 | -------------------------------------------------------------------------------- /md/PL-FC-Entails.md: -------------------------------------------------------------------------------- 1 | # PL-FC-ENTAILS? 2 | 3 | ## AIMA3e 4 | __function__ PL-FC-ENTAILS?(_KB_, _q_) __returns__ _true_ or _false_ 5 |  __inputs__: _KB_, the knowledge base, a set of propositional definite clauses 6 |      _q_, the query, a proposition symbol 7 |  _count_ ← a table, where _count_\[_c_\] is the number of symbols in _c_'s premise 8 |  _inferred_ ← a table, where _inferred_\[_s_\] is initially _false_ for all symbols 9 |  _agenda_ ← a queue of symbols, initially symbols known to be true in _KB_ 10 | 11 |  __while__ _agenda_ is not empty __do__ 12 |    _p_ ← POP(_agenda_) 13 |    __if__ _p_ = _q_ __then return__ _true_ 14 |    __if__ _inferred_\[_p_\] = _false_ __then__ 15 |      _inferred_\[_p_\] ← _true_ 16 |      __for each__ clause _c_ in _KB_ where _p_ is in _c_.PREMISE __do__ 17 |        decrement _count_\[_c_\] 18 |        __if__ _count_\[_c_\] = 0 __then__ add _c_.CONCLUSION to _agenda_ 19 |  __return__ _false_ 20 | 21 | --- 22 | __Figure__ ?? The forward-chaining algorithm for propositional logic. The _agenda_ keeps track of symbols known to be true but not yet "processed". The _count_ table keeps track of how many premises of each implication are as yet unknown. Whenever a new symbol _p_ from the agenda is processed, the count is reduced by one for each implication in whose premise _p_ appears (easily identified in constant time with appropriate indexing.) If a count reaches zero, all the premises of the implication are known, so its conclusion can be added to the agenda. Finally, we need to keep track of which symbols have been processed; a symbol that is already in the set of inferred symbols need not be added to the agenda again. This avoids redundant work and prevents loops caused by implications such as _P_ ⇒ _Q_ and _Q_ ⇒ _P_. 23 | -------------------------------------------------------------------------------- /md/PL-Resolution.md: -------------------------------------------------------------------------------- 1 | # PL-RESOLUTION 2 | 3 | ## AIMA3e 4 | __function__ PL-RESOLUTION(_KB_, _α_) __returns__ _true_ or _false_ 5 |  __inputs__: _KB_, the knowledge base, a sentence in propositional logic 6 |      _α_, the query, a sentence in propositional logic 7 | 8 |  _clauses_ ← the set of clauses in the CNF representation of _KB_ ∧ ¬_α_ 9 |  _new_ ← { } 10 |  __loop do__ 11 |    __for each__ pair of clauses _Ci_, _Cj_ __in__ _clauses_ __do__ 12 |      _resolvents_ ← PL-RESOLVE(_Ci_, _Cj_) 13 |      __if__ _resolvents_ contains the empty clause __then return__ _true_ 14 |      _new_ ← _new_ ∪ _resolvents_ 15 |    __if__ _new_ ⊆ _clauses_ __then return__ _false_ 16 |    _clauses_ ← _clauses_ ∪ _new_ 17 | 18 | --- 19 | Figure ?? A simple resolution algorithm for propositional logic. The function PL-RESOLVE returns the set of all possible clauses obtained by resolving its two inputs. -------------------------------------------------------------------------------- /md/POMDP-Value-Iteration.md: -------------------------------------------------------------------------------- 1 | # POMDP-VALUE-ITERATION 2 | 3 | ## AIMA3e 4 | __function__ POMDP-VALUE-ITERATION(_pomdp_, _ε_) __returns__ a utility function 5 |  __inputs__: _pomdp_, a POMDP with states _S_, actions _A_(_s_), transition model _P_(_s′_ | _s_, _a_), 6 |       sensor model _P_(_e_ | _s_), rewards _R_(_s_), discount _γ_ 7 |      _ε_, the maximum error allowed in the utility of any state 8 |  __local variables__: _U_, _U′_, sets of plans _p_ with associated utility vectors _αp_ 9 | 10 |  _U′_ ← a set containing just the empty plan \[\], with _α\[\]_(_s_) = _R_(_s_) 11 |  __repeat__ 12 |    _U_ ← _U′_ 13 |    _U′_ ← the set of all plans consisting of an action and, for each possible next percept, 14 |      a plan in _U_ with utility vectors computed according to Equation(__??__) 15 |    _U′_ ← REMOVE\-DOMINATED\-PLANS(_U′_) 16 |  __until__ MAX\-DIFFERENCE(_U_, _U′_) < _ε_(1 − _γ_) ⁄ _γ_ 17 |  __return__ _U_ 18 | 19 | --- 20 | __Figure ??__ A high\-level sketch of the value iteration algorithm for POMDPs. The REMOVE\-DOMINATED\-PLANS step and MAX\-DIFFERENCE test are typically implemented as linear programs. 21 | -------------------------------------------------------------------------------- /md/Particle-Filtering.md: -------------------------------------------------------------------------------- 1 | # PARTICLE-FILTERING 2 | 3 | ## AIMA3e 4 | __function__ PARTICLE-FILTERING(__e__, _N_, _dbn_) __returns__ a set of samples for the next time step 5 |  __inputs__: __e__, the new incoming evidence 6 |      _N_, the number of samples to be maintained 7 |      _dbn_, a DBN with prior __P__(__X0__), transition model __P__(__X1__ | __X0__), sensor model __P__(__E1__ | __X1__) 8 |  __persistent__: _S_, a vector of samples of size _N_, initially generated from __P__(__X0__) 9 |  __local variables__: _W_, a vector of weights of size _N_ 10 | 11 |  __for__ _i_ = 1 to _N_ __do__ 12 |    _S_\[_i_\] ← sample from __P__(__X1__ | __X0__ = _S_\[_i_\]) /\* step 1 \*/ 13 |    _W_\[_i_\] ← __P__(__e__ | __X1__ = _S_\[_i_\])       /\* step 2 \*/ 14 |  _S_ ← WEIGHTED\-SAMPLE\-WITH\-REPLACEMENT(_N_, _S_, _W_)  /\* step 3 \*/ 15 |  __return__ _S_ 16 | 17 | --- 18 | __Figure ??__ The particle filtering algorithm implemented as a recursive update operation with state (the set of samples). Each of the sampling operations involves sampling the relevant slice variables in topological order, much as in PRIOR\-SAMPLE. The WEIGHTED\-SAMPLE\-WITH\-REPLACEMENT operation can be implemented to run in _O_(_N_) expected time. The step numbers refer to the description in the text. 19 | -------------------------------------------------------------------------------- /md/Passive-ADP-Agent.md: -------------------------------------------------------------------------------- 1 | # PASSIVE-ADP-AGENT 2 | 3 | ## AIMA3e 4 | __function__ Passive-ADP-Agent(_percept_) __returns__ and action 5 |  __inputs__: _percept_, a percept indication the current state _s'_ and reward signal _r'_ 6 |  __persistent__: _π_, a fixed policy 7 |        _mdp_, an MDP with model _P_, rewards _R_, discount γ 8 |        _U_, a table of utilities, initially empty 9 |        _Nsa_, a table of frequencies for state-action pairs, initially zero 10 |        _Ns'|sa_, a table of outcome frequencies given state-action pairs, initially zero 11 |        _s_, _a_, the previous state and action, initially null 12 |  __if__ _s'_ is new __then__ _U_[_s'_] ← _r'_; _R_[_s'_] ← _r'_ 13 |  __if__ _s_ is not null __then__ 14 |    increment _Nsa_[_s_, _a_] and _Ns'|sa_[_s'_, _s_, _a_] 15 |    __for each__ _t_ such that _Ns'|sa_[_t_, _s_, _a_] is nonzero __do__ 16 |      _P_(_t_ | _s_, _a_) ← _Ns'|sa_[_t_, _s_, _a_] / _Nsa_[_s_, _a_] 17 |  _U_ ← Policy-Evaluation(_π_, _U_, _mdp_) 18 |  __if__ _s'_.Terminal? __then__ _s_, _a_ ← null __else__ _s_, _a_ ← _s'_, _π_[_s'_] 19 | 20 | --- 21 | __Figure ??__ A passive reinforcement learning agent based on adaptive dynamic programming. The Policy-Evaluation function solves the fixed-policy Bellman equations, as described on page ??. 22 | -------------------------------------------------------------------------------- /md/Passive-TD-Agent.md: -------------------------------------------------------------------------------- 1 | # PASSIVE-TD-AGENT 2 | 3 | ## AIMA3e 4 | __function__ Passive-TD-Agent(_percept_) __returns__ an action 5 |  __inputs__: _percept_, a percept indication the current state _s'_ and reward signal _r'_ 6 |  __persistent__: _π_, a fixed policy 7 |        _U_, a table of utilities, initially empty 8 |        _Ns_, a table of frequencies for states, initially zero 9 |        _s_, _a_, _r_, the previous state, action, and reward, initially null 10 | 11 |  __if__ _s'_ is new __then__ _U_[_s'_] ← _r'_ 12 |  __if__ _s_ is not null __then__ 13 |    increment _Ns_[_s_] 14 |    _U_[_s_] ← _U_[_s_] + _α_(_Ns_[_s_])(r + _γ_ _U_[_s'_] - _U_[_s_]) 15 |  __if__ _s'_.Terminal? __then__ _s_, _a_, _r_ ← null __else__ _s_, _a_, _r_ ← _s'_, _π_[_s'_], _r'_ 16 |  return _a_ 17 | 18 | --- 19 | __Figure ??__ A passive reinforcement learning agent that learns utility estimates using temporal differences. The step-size function α(_n_) is chosen to ensure convergence, as described in the text. 20 | -------------------------------------------------------------------------------- /md/Policy-Iteration.md: -------------------------------------------------------------------------------- 1 | # POLICY-ITERATION 2 | 3 | ## AIMA3e 4 | __function__ POLICY-ITERATION(_mdp_) __returns__ a policy 5 |  __inputs__: _mdp_, an MDP with states _S_, actions _A_(_s_), transition model _P_(_s′_ | _s_, _a_) 6 |  __local variables__: _U_, a vector of utilities for states in _S_, initially zero 7 |         _π_, a policy vector indexed by state, initially random 8 | 9 |  __repeat__ 10 |    _U_ ← POLICY\-EVALUATION(_π_, _U_, _mdp_) 11 |    _unchanged?_ ← true 12 |    __for each__ state _s_ __in__ _S_ __do__ 13 |      __if__ max_a_ ∈ _A_(_s_) Σ_s′_ _P_(_s′_ | _s_, _a_) _U_\[_s′_\] > Σ_s′_ _P_(_s′_ | _s_, _π_\[_s_\]) _U_\[_s′_\] __then do__ 14 |        _π_\[_s_\] ← argmax_a_ ∈ _A_(_s_) Σ_s′_ _P_(_s′_ | _s_, _a_) _U_\[_s′_\] 15 |        _unchanged?_ ← false 16 |  __until__ _unchanged?_ 17 |  __return__ _π_ 18 | 19 | --- 20 | __Figure ??__ The policy iteration algorithm for calculating an optimal policy. 21 | 22 | --- 23 | 24 | ## AIMA4e 25 | __function__ POLICY-ITERATION(_mdp_) __returns__ a policy 26 |  __inputs__: _mdp_, an MDP with states _S_, actions _A_(_s_), transition model _P_(_s′_ | _s_, _a_) 27 |  __local variables__: _U_, a vector of utilities for states in _S_, initially zero 28 |         _π_, a policy vector indexed by state, initially random 29 | 30 |  __repeat__ 31 |    _U_ ← POLICY\-EVALUATION(_π_, _U_, _mdp_) 32 |    _unchanged?_ ← true 33 |    __for each__ state _s_ __in__ _S_ __do__ 34 |      _a * _ ← argmax_a_ ∈ _A_(_s_) Q-VALUE(_mdp_,_s_,_a_,_U_) 35 |      __if__ Q-VALUE(_mdp_,_s_,_a*_,_U_) > Q-VALUE(_mdp_,_s_,_π_\[_s_\],_U_) __then do__ 36 |        _π_\[_s_\] ← _a*_ ; _unchanged?_ ← false 37 |  __until__ _unchanged?_ 38 |  __return__ _π_ 39 | 40 | --- 41 | __Figure ??__ The policy iteration algorithm for calculating an optimal policy. 42 | -------------------------------------------------------------------------------- /md/Powers-Of-2.md: -------------------------------------------------------------------------------- 1 | # POWERS-OF-2 2 | 3 | ## AIMA3e 4 | __generator__ Powers-Of-2() __yields__ ints 5 |  _i_ ← 1 6 |  __while__ _true_ __do__ 7 |   __yield__ _i_ 8 |   _i_ ← 2 x _i_ 9 | 10 | --- 11 | __for__ _p_ __in__ Powers-Of-2() __do__ 12 |  PRINT(_p_) 13 | 14 | --- 15 | __Figure ??__ Example of a generator function and its invocation within a loop. 16 | -------------------------------------------------------------------------------- /md/Prior-Sample.md: -------------------------------------------------------------------------------- 1 | # PRIOR-SAMPLE 2 | 3 | ## AIMA3e 4 | __function__ PRIOR-SAMPLE(_bn_) __returns__ an event sampled from the prior specified by _bn_ 5 |  __inputs__: _bn_, a Bayesian network specifying joint distribution __P__(_X1_, …, _Xn_) 6 | 7 |  __x__ ← an event with _n_ elements 8 |  __foreach__ variable _Xi_ __in__ _X1_, …, _Xn_ __do__ 9 |    _x_\[_i_\] ← a random sample from __P__(_Xi_ | _parents_(_Xi_)) 10 |  __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. 14 | -------------------------------------------------------------------------------- /md/Q-Learning-Agent.md: -------------------------------------------------------------------------------- 1 | # Q-LEARNING-AGENT 2 | 3 | #AIMA3e 4 | __function__ Q-Learning_Agent(_percept_) __returns__ an action 5 |  __inputs__: _percept_, a percept indicating the current state _s'_ and reward signal _r'_ 6 |  __persistent__: _Q_, a table of action values indexed by state and action, initially zero 7 |        _Nsa_, a table of frequencies for state-action pairs, initially zero 8 |        _s_, _a_, _r_, the previous state, action, and reward, initially null 9 | 10 |  __if__ Terminal?(_s_) then _Q_[_s_, None] ← _r'_ 11 |  __if__ _s_ is not null __then__ 12 |    increment _Nsa_[_s_, _a_] 13 |    _Q_[_s_, _a_] ← _Q_[_s_, _a_] + _α_(_Nsa_[_s_, _a_])(_r_ + _γ_ maxa' _Q_[_s'_, _a'_] - _Q_[_s_, _a_]) 14 |  _s_, _a_, _r_ ← _s'_, argmaxa' _f_(_Q_[_s'_, _a'_], _Nsa_[_s'_, _a'_]), _r'_ 15 |  __return__ _a_ 16 | 17 | --- 18 | __Figure ??__ An exploratory Q-learning agent. It is an active learner that learns the value _Q_(_s_, _a_) of each action in each situation. It uses the same exploration function _f_ as the exploratory ADP agent, but avoids having to learn the transition model because the Q-value of a state can be related directly to those of its neighbors. 19 | -------------------------------------------------------------------------------- /md/Random-Forest.md: -------------------------------------------------------------------------------- 1 | # Random Forest 2 | 3 | __function__ RANDOMFOREST( S,F ) __return__ solution: 4 |  __input__ S --> training set consisting of (Xi,Yi) 5 |   F --> No. of features 6 |   H <-- null 7 | 8 |  for __each__ i 1,..B(no.of trees) __do__ 9 |    h(i) --> RANDOMISEDTREE( S(i),F ) 10 |    H <-- H U {h(i)} 11 |    __return__ H 12 | 13 | __function__ RANDOMISEDTREE(S,F) __return__ learnt_tree : 14 | 15 |  for each node of the tree do 16 |    f <-- Randomised subset of F 17 |    Split and choose best feature in f 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /md/Recursive-Best-First-Search.md: -------------------------------------------------------------------------------- 1 | # RECURSIVE-BEST-FIRST-SEARCH 2 | 3 | ## AIMA3e 4 | __function__ RECURSIVE-BEST-FIRST-SEARCH(_problem_) __returns__ a solution, or failure 5 |  __return__ RBFS(_problem_,MAKE\-NODE(_problem_.INITIAL\-STATE),∞) 6 | 7 | __function__ RBFS(_problem_,_node_,_f\_limit_) __returns__ a solution, or failure and a new _f_\-cost limit 8 |  if _problem_.GOAL-TEST(_node_.STATE) __then return__ SOLUTION(_node_) 9 |  _successors_ ← \[\] 10 |  __for each__ _action_ __in__ _problem_.ACTIONS(_node_.STATE) __do__ 11 |    add CHILD-NODE(_problem_,_node_,_action_) into _successors_ 12 |  __if__ _successors_ is empty __then return__ _failure_,∞ 13 |  __for each__ _s_ __in__ _successors_ __do__ /\* update _f_ with value from previous search, if any \*/ 14 |    _s.f_ ← max(_s.g_ + _s.h_, _node.f_) 15 |  __loop do__ 16 |    _best_ ← lowest _f_\-value node in _successors_ 17 |    __if__ _best.f_ > _f\_limit_ __then return__ _failure,best.f_ 18 |    _alternative_ ← the second-lowest _f_\-value among _successors_ 19 |    _result,best.f_ ← RBFS(_problem_,_best_,min(_f\_limit_,_alternative_)) 20 |    __if__ _result_ ≠ _failure_ __then return__ _result_ 21 | 22 | --- 23 | __Figure__ ?? The algorithm for recursive best\-first search. 24 | -------------------------------------------------------------------------------- /md/Refinement-High-Level-Actions.md: -------------------------------------------------------------------------------- 1 | # REFINEMENT-HIGH-LEVEL-ACTIONS 2 | 3 | ## AIMA3e 4 | 5 | _Refinement (Go(Home, SFO),_ 6 |  STEPS: _[Drive(Home, SFOLongTermParking ),_ 7 |    _Shuttle(SFOLongTermParking, SFO)] )_ 8 | _Refinement (Go(Home, SFO),_ 9 |  STEPS: _[Taxi(Home, SFO)] )_ 10 | 11 | --- 12 | _Refinement(Navigate([a, b], [x, y]),_ 13 |  PRECOND: _a = x ∧ b = y_ 14 |  STEPS: [ ] ) 15 | _Refinement(Navigate([a, b], [x, y]),_ 16 |  PRECOND: _Connected ([a, b], [a − 1, b])_ 17 |  STEPS: _[Left , Navigate([a − 1, b], [x, y])] )_ 18 | _Refinement (Navigate([a, b], [x, y]),_ 19 |  PRECOND: _Connected ([a, b], [a + 1, b])_ 20 |  STEPS: _[Right , Navigate([a + 1, b], [x, y])] )_ 21 | ... 22 | 23 | --- 24 | __Figure ??__ Definitions of possible refinements for two high-level actions: going to San Francisco 25 | airport and navigating in the vacuum world. In the latter case, note the recursive nature of the refine- 26 | ments and the use of preconditions. 27 | -------------------------------------------------------------------------------- /md/Reflex-Vacuum-Agent.md: -------------------------------------------------------------------------------- 1 | # REFLEX-VACUUM-AGENT 2 | 3 | ## AIMA3e 4 | __function__ REFLEX-VACUUM-AGENT([_location,status_]) __returns__ an action 5 |  __if__ _status_ = _Dirty_ __then return__ _Suck_ 6 |  __else if__ _location_ = A __then return__ _Right_ 7 |  __else if__ _location_ = B __then return__ _Left_ 8 | 9 | --- 10 | __Figure__ ?? The agent program for a simple reflex agent in the two-state vacuum environment. This program implements the agent function tabulated in Figure ??. 11 | -------------------------------------------------------------------------------- /md/Rejection-Sampling.md: -------------------------------------------------------------------------------- 1 | # REJECTION-SAMPLING 2 | 3 | ## AIMA3e 4 | __function__ REJECTION-SAMPLING(_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 8 |      _N_, the total number of samples to be generated 9 |  __local variables__: __N__, a vector of counts for each value of _X_, initially zero 10 | 11 |  __for__ _j_ = 1 to _N_ __do__ 12 |    __x__ ← PRIOR\-SAMPLE(_bn_) 13 |    __if x__ is consistent with __e then__ 14 |      __N__\[_x_\] ← __N__\[_x_\] + 1 where _x_ is the value of _X_ in __x__ 15 |  __return__ NORMALIZE(__N__) 16 | 17 | --- 18 | __Figure__ ?? The rejection\-sampling algorithm for answering queries given evidence in a Bayesian network. 19 | -------------------------------------------------------------------------------- /md/SATPlan.md: -------------------------------------------------------------------------------- 1 | # SATPLAN 2 | 3 | ## AIMA3e 4 | __function__ SATPLAN(_init_, _transition_, _goal_, _T_max) __returns__ solution or failure 5 |  __inputs__: _init_, _transition_, _goal_, constitute a description of the problem 6 |     _T_max, an upper limit for plan length 7 | 8 |  __for__ _t_ = 0 to _T_max __do__ 9 |    _cnf_ ← TRANSLATE-TO-SAT(_init_, _transition_, _goal_, _t_) 10 |    _model_ ← SAT-SOLVER(_cnf_) 11 |    __if__ _model_ is not null __then__ 12 |      __return__ EXTRACT-SOLUTION(_model_) 13 |  __return__ _failure_ 14 | 15 | --- 16 | __Figure__ ?? The SATPlan algorithm. The planning problem is translated into a CNF sentence in which the goal is asserted to hold at a fixed time step _t_ and axioms are included for each time step up to _t_. If the satisfiability algorithm finds a model, then a plan is extracted by looking at those proposition symbols that refer to actions and are assigned _true_ in the model. If no model exists, then the process is repeated with the goal moved one step later. -------------------------------------------------------------------------------- /md/Sentence-Tree.md: -------------------------------------------------------------------------------- 1 | # SENTENCE-TREE 2 | 3 | ## AIMA3e 4 | 5 | [ [S [NP-SBJ-2 Her eyes] 6 |   [VP were 7 |     [VP glazed 8 |       [NP *-2] 9 |       [SBAR-ADV as if 10 |         [S [NP-SBJ she] 11 |           [VP did n’t 12 |            [VP [VP hear [NP *-1]] 13 |              or 14 |              [VP [ADVP even] see [NP *-1]] 15 |              [NP-1 him]]]]]]]] 16 | .] 17 | 18 | --- 19 | __Figure ??__ Annotated tree for the sentence “Her eyes were glazed as if she didn’t hear or even 20 | see him.” from the Penn Treebank. Note that in this grammar there is a distinction between an object 21 | noun phrase (_NP_) and a subject noun phrase (_NP-SBJ_). Note also a grammatical phenomenon we have 22 | not covered yet: the movement of a phrase from one part of the tree to another. This tree analyzes 23 | the phrase “hear or even see him” as consisting of two constituent _VP_ s, [VP hear [NP *-1]] and [VP 24 | [ADVP even] see [NP *-1]], both of which have a missing object, denoted *-1, which refers to the _NP_ 25 | labeled elsewhere in the tree as [NP-1 him]. 26 | -------------------------------------------------------------------------------- /md/Simple-Problem-Solving-Agent.md: -------------------------------------------------------------------------------- 1 | # SIMPLE-PROBLEM-SOLVING-AGENT 2 | 3 | ## AIMA3e 4 | __function__ SIMPLE-PROBLEM-SOLVING-AGENT(_percept_) __returns__ an action 5 |  __persistent__: _seq_, an action sequence, initially empty 6 |       _state_, some description of the current world state 7 |       _goal_, a goal, initially null 8 |       _problem_, a problem formulation 9 | 10 |  _state_ ← UPDATE-STATE(_state_, _percept_) 11 |  __if__ _seq_ is empty __then__ 12 |    _goal_ ← FORMULATE-GOAL(_state_) 13 |    _problem_ ← FORMULATE-PROBLEM(_state_, _goal_) 14 |    _seq_ ← SEARCH(_problem_) 15 |    __if__ _seq_ = _failure_ __then return__ a null action 16 |  _action_ ← FIRST(_seq_) 17 |  _seq_ ← REST(_seq_) 18 |  __return__ _action_ 19 | 20 | --- 21 | __Figure__ ?? A simple problem-solving agent. It first formulates a goal and a problem, searches for a sequence of actions that would solve the problem, and then executes the actions one at a time. When this is complete, it formulates another goal and starts over. 22 | -------------------------------------------------------------------------------- /md/Simple-Reflex-Agent.md: -------------------------------------------------------------------------------- 1 | # SIMPLEX-REFLEX-AGENT 2 | 3 | ## AIMA3e 4 | __function__ SIMPLE-REFLEX-AGENT(_percept_) __returns__ an action 5 |  __persistent__: _rules_, a set of condition\-action rules 6 | 7 |  _state_ ← INTERPRET-INPUT(_percept_) 8 |  _rule_ ← RULE-MATCH(_state_,_rules_) 9 |  _action_ ← _rule_.ACTION 10 |  __return__ _action_ 11 | 12 | --- 13 | __Figure__ ?? A simple reflex agent. It acts according to a rule whose condition matches the current state, as defined by the percept. 14 | -------------------------------------------------------------------------------- /md/Simulated-Annealing.md: -------------------------------------------------------------------------------- 1 | # SIMULATED-ANNEALING 2 | 3 | ## AIMA4e 4 | 5 | __function__ SIMULATED-ANNEALING(_problem_,_schedule_) __returns__ a solution state 6 | 7 |  _current_ ← _problem_.INITIAL\-STATE 8 |  __for__ _t_ = 1 __to__ ∞ __do__ 9 |    _T_ ← _schedule(t)_ 10 |    __if__ _T_ = 0 __then return__ _current_ 11 |    _next_ ← a randomly selected successor of _current_ 12 |    _ΔE_ ← VALUE(_next_) - VALUE(_current_) 13 |    __if__ _ΔE_ > 0 __then__ _current_ ← _next_ 14 |    __else__ _current_ ← _next_ only with probability e_ΔE_/_T_ 15 | 16 | --- 17 | __Figure 4.6__ The simulated annealing algorithm, a version of stochastic hill climbing where 18 | some downhill moves are allowed. The schedule input determines the value of the “temper- 19 | ature” T as a function of time; higher temperatures early in the schedule mean that downhill 20 | moves are accepted more readily; late in the schedule with low temperatures, downhill moves 21 | are mostly rejected. 22 | 23 | 24 | ## AIMA3e 25 | __function__ SIMULATED-ANNEALING(_problem_,_schedule_) __returns__ a solution state 26 |  __inputs__: _problem_, a problem 27 |     _schedule_, a mapping from time to "temperature" 28 | 29 |  _current_ ← MAKE\-NODE(_problem_.INITIAL\-STATE) 30 |  __for__ _t_ = 1 __to__ ∞ __do__ 31 |    _T_ ← _schedule(t)_ 32 |    __if__ _T_ = 0 __then return__ _current_ 33 |    _next_ ← a randomly selected successor of _current_ 34 |    _ΔE_ ← _next_.VALUE - _current_.VALUE 35 |    __if__ _ΔE_ > 0 __then__ _current_ ← _next_ 36 |    __else__ _current_ ← _next_ only with probability e_ΔE_/_T_ 37 | 38 | --- 39 | __Figure__ ?? The simulated annealing algorithm, a version of stochastic hill climbing where some downhill moves are allowed. Downhill moves are accepted readily early in the annealing schedule and then less often as time goes on. The _schedule_ input determines the value of the temperature _T_ as a function of time. 40 | -------------------------------------------------------------------------------- /md/Spare-Tire-Problem.md: -------------------------------------------------------------------------------- 1 | # SPARE-TIRE-PROBLEM 2 | 3 | ## AIMA3e 4 | _Init_(_Tire_(_Flat_) ∧ _Tire_(_Spare_) ∧ _At_(_Flat_, _Axle_) ∧ _At_(_Spare_, _Trunk_)) 5 | _Goal_(_At_(_Spare_, _Axle_)) 6 | _Action_(_Remove_(_obj_, _loc_), 7 |  PRECOND: _At_(_obj_, _loc_) 8 |  EFFECT: ¬ _At_(_obj_, _loc_) ∧ _At_(_obj_, _Ground_)) 9 | _Action_(_PutOn_(_t_, _Axle_), 10 |  PRECOND: _Tire_(_t_) ∧ _At_(_t_, _Ground_) ∧ ¬ _At_(_Flat_, _Axle_) 11 |  EFFECT: ¬ _At_(_t_, _Ground_) ∧ _At_(_t_, _Axle_)) 12 | _Action_(_LeaveOvernight_, 13 |  PRECOND: 14 |  EFFECT: ¬ _At_(_Spare_, _Ground_) ∧ ¬ _At_(_Spare_, _Axle_) ∧ ¬ _At_(_Spare_, _Trunk_) 15 |      ∧ ¬ _At_(_Flat_, _Ground_) ∧ ¬ _At_(_Flat_, _Axle_) ∧ ¬ _At_(_Flat_, _Trunk_)) 16 | 17 | --- 18 | __Figure ??__ The simple spare tire problem. 19 | -------------------------------------------------------------------------------- /md/Successors.md: -------------------------------------------------------------------------------- 1 | # Successors 2 | 3 | ## AIMA4e 4 | 5 | 6 | __function__ SUCCESSORS(_problem_, _parent_) __returns__ an action 7 |  _s_ ← _parent_.state 8 |  _nodes_ ← an empty list 9 |  __for__ _action_ in _problem_.actions(_s_) __do__ 10 |    _s'_ ← _problem_.result(s,_action_) 11 |    _cost_ ← _parent_.pathCost + _problem_.stepCost(_s, action, s′_ ) 12 |    _node_ ← Node(state = _s'_, parent = _parent_, action = _action_, pathCost = _cost_) 13 |    add _node_ to _nodes_ 14 |  __return__ _nodes_ 15 | -------------------------------------------------------------------------------- /md/TT-Entails.md: -------------------------------------------------------------------------------- 1 | # TT-ENTAILS 2 | 3 | ## AIMA3e 4 | __function__ TT-ENTAILS?(_KB_, _α_) __returns__ _true_ or _false_ 5 |  __inputs__: _KB_, the knowledge base, a sentence in propositional logic 6 |       _α_, the query, a sentence in propositional logic 7 | 8 |  _symbols_ ← a list of the propositional symbols in _KB_ and _α_ 9 |  __return__ TT-CHECK-ALL(_KB_, _α_, _symbols_, { }) 10 | 11 | --- 12 | __function__ TT-CHECK-ALL(_KB_, _α_, _symbols_, _model_) __returns__ _true_ or _false_ 13 |  __if__ EMPTY?(_symbols_) __then__ 14 |    __if__ PL-TRUE?(_KB_, _model_) __then return__ PL-TRUE?(_α_, _model_) 15 |    __else return__ _true_ _//_ _when KB is false, always return true_ 16 |  __else do__ 17 |    _P_ ← FIRST(_symbols_) 18 |    _rest_ ← REST(_symbols_) 19 |    __return__(TT-CHECK-ALL(_KB_, _α_, _rest_, _model_ ∪ { _P_ = _true_ }) 20 |       __and__ 21 |       TT-CHECK-ALL(_KB_, _α_, _rest_, _model_ ∪ { _P_ = _false_ })) 22 | 23 | 24 | --- 25 | __Figure__ ?? A truth-table enumeration algorithm for deciding propositional entailment. (TT stands for truth table.) PL-TRUE? returns _true_ if a sentence holds within a model. The variable _model_ represents a partial model \- an assignment to some of the symbols. The keyword "__and__" is used here as a logical operation on its two arguments, returning _true_ or _false_. 26 | -------------------------------------------------------------------------------- /md/Table-Driven-Agent.md: -------------------------------------------------------------------------------- 1 | # TABLE-DRIVEN-AGENT 2 | 3 | ## AIMA3e 4 | __function__ TABLE-DRIVEN-AGENT(_percept_) __returns__ an action 5 |  __persistent__: _percepts_, a sequence, initially empty 6 |       _table_, a table of actions, indexed by percept sequences, initially fully specified 7 | 8 |  append _percept_ to the end of _percepts_ 9 |  _action_ ← LOOKUP(_percepts_, _table_) 10 |  __return__ _action_ 11 | 12 | --- 13 | __Figure__ ?? The TABLE-DRIVEN-AGENT program is invoked for each new percept and returns an action each time. It retains the complete percept sequence in memory. 14 | -------------------------------------------------------------------------------- /md/Tree-CSP-Solver.md: -------------------------------------------------------------------------------- 1 | # TREE-CSP-SOLVER 2 | 3 | ## AIMA3e 4 | __function__ TREE-CSP-SOLVER(_csp_) __returns__ a solution, or failure 5 |  __inputs__: _csp_, a CSP with components _X_, _D_, _C_ 6 | 7 |  _n_ ← number of variables in _X_ 8 |  _assignment_ ← an empty assignment 9 |  _root_ ← any variable in _X_ 10 |  _X_ ← TOPOLOGICALSORT(_X_, _root_) 11 |  __for__ _j_ = _n_ __down to__ 2 __do__ 12 |   MAKE\-ARC\-CONSISTENT(PARENT(_Xj_), _Xj_) 13 |   __if__ it cannot be made consistent __then return__ _failure_ 14 |  __for__ _i_ 1 __to__ _n_ __do__ 15 |   _assignment_[_Xi_] ← any consistent value from _Di_ 16 |   __if__ there is no consistent value __then return__ _failure_ 17 |  __return__ _assignment_ 18 | 19 | --- 20 | __Figure ??__ The TREE-CSP-SOLVER algorithm for solving tree\-structured CSPs. If the CSP has a solution, we will find it in linear time; if not, we will detect a contradiction. 21 | -------------------------------------------------------------------------------- /md/Tree-Search-and-Graph-Search.md: -------------------------------------------------------------------------------- 1 | # GRAPH-SEARCH 2 | 3 | ## AIMA4e 4 | 5 | 6 | __function__ GRAPH-SEARCH(_problem_) __returns__ a solution, or failure 7 |  _frontier_ ← a queue initially containing one path, for the _problem_'s initial state 8 |  _reached_ ← a table of {_state_: _node_}; initially empty 9 |  _solution_ ← failure 10 |  __while__ _frontier_ is not empty __and__ _solution_ can possibly be improved __do__ 11 |    _parent_ ← some node that we choose to remove from _frontier_ 12 |    __for__ _child_ __in__ EXPAND(_parent_) __do__ 13 |      _s_ ← _child_.state 14 |      __if__ _s_ is not in _reached_ __or__ _child_ is a cheaper path than _reached_[_s_] __then__ 15 |        _reached_[_s_] ← _child_ 16 |        add _child_ to _frontier_ 17 |        __if__ _s_ is a goal and _child_ is cheaper than _solution_ __then__ 18 |          _solution_ = _child_ 19 |  __return__ _solution_ 20 | 21 | --- 22 | __function__ EXPAND(_problem, parent_) __returns__ a list of nodes 23 |  _s_ ← _parent_.state 24 |  _nodes_ ← an empty list 25 |  __for__ _action_ __in__ _problem_.actions(_s_) __do__ 26 |    _s'_ ← _problem_.result(_s_, _action_) 27 |    _cost_ ← _parent_.path-cost + _problem_.step-cost(_s, action, s') 28 |    add _node_ to _nodes_ 29 |  __return__ _nodes_ 30 | 31 | --- 32 | __Figure__ ?? In the GRAPH-SEARCH algorithm, we keep track of the best _solution_ found so far, as well as the states that we have already _reached_, and a _frontier_ of paths from which we will choose 33 | the next path to expand. 34 | In any specific search algorithm, we specify (1) the criteria for ordering the paths in the frontier, 35 | and (2) the procedure for determining when it is no longer possible to improve on a solution. 36 | 37 | # TREE-SEARCH and GRAPH-SEARCH 38 | ## AIMA3e 39 | __function__ TREE-SEARCH(_problem_) __returns__ a solution, or failure 40 |  initialize the frontier using the initial state of _problem_ 41 |  __loop do__ 42 |    __if__ the frontier is empty __then return__ failure 43 |    choose a leaf node and remove it from the frontier 44 |    __if__ the node contains a goal state __then return__ the corresponding solution 45 |    expand the chosen node, adding the resulting nodes to the frontier 46 | 47 | --- 48 | __function__ GRAPH-SEARCH(_problem_) __returns__ a solution, or failure 49 |  initialize the frontier using the initial state of _problem_ 50 |  **_initialize the explored set to be empty_** 51 |  __loop do__ 52 |    __if__ the frontier is empty __then return__ failure 53 |    choose a leaf node and remove it from the frontier 54 |    __if__ the node contains a goal state __then return__ the corresponding solution 55 |    **_add the node to the explored set_** 56 |    expand the chosen node, adding the resulting nodes to the frontier 57 |     **_only if not in the frontier or explored set_** 58 | 59 | --- 60 | __Figure__ ?? An informal description of the general tree\-search and graph\-search algorithms. The parts of GRAPH\-SEARCH marked in bold italic are the additions needed to handle repeated states. 61 | -------------------------------------------------------------------------------- /md/Uniform-Cost-Search.md: -------------------------------------------------------------------------------- 1 | # UNIFORM-COST-SEARCH 2 | 3 | ## AIMA4e 4 | 5 | __function__ UNIFORM-COST-SEARCH(_problem_) __returns__ a solution, or failure 6 |  __if__ problem's initial state is a goal __then return__ empty path to initial state 7 |  _frontier_ ← a priority queue ordered by pathCost, with a node for the initial state 8 |  _reached_ ← a table of {_state_: the best path that reached _state_}; initially empty 9 |  _solution_ ← failure 10 |  __while__ _frontier_ is not empty __and__ top(_frontier_) is cheaper than _solution_ __do__ 11 |    _parent_ ← pop(_frontier_) 12 |    __for__ _child_ __in__ successors(_parent_) __do__ 13 |      _s_ ← _child_.state 14 |      __if__ _s_ is not in _reached_ __or__ _child_ is a cheaper path than _reached_[_s_] __then__ 15 |        _reached_[_s_] ← _child_ 16 |        add _child_ to the _frontier_ 17 |        __if__ _child_ is a goal and is cheaper than _solution_ __then__ 18 |          _solution_ = _child_ 19 |  __return__ _solution_ 20 | 21 | --- 22 | __Figure 3.11__ Uniform-cost search on a graph. Finds optimal paths for problems with vary- 23 | ing step costs. 24 | 25 | 26 | ## AIMA3e 27 | __function__ UNIFORM-COST-SEARCH(_problem_) __returns__ a solution, or failure 28 |  _node_ ← a node with STATE = _problem_.INITIAL\-STATE, PATH\-COST = 0 29 |  _frontier_ ← a priority queue ordered by PATH\-COST, with _node_ as the only element 30 |  _explored_ ← an empty set 31 |  __loop do__ 32 |    __if__ EMPTY?(_frontier_) __then return__ failure 33 |    _node_ ← POP(_frontier_) /\* chooses the lowest\-cost node in _frontier_ \*/ 34 |    __if__ _problem_.GOAL\-TEST(_node_.STATE) __then return__ SOLUTION(_node_) 35 |    add _node_.STATE to _explored_ 36 |    __for each__ _action_ __in__ _problem_.ACTIONS(_node_.STATE) __do__ 37 |       _child_ ← CHILD\-NODE(_problem_,_node_,_action_) 38 |       __if__ _child_.STATE is not in _explored_ or _frontier_ __then__ 39 |          _frontier_ ← INSERT(_child_,_frontier_) 40 |       __else if__ _child_.STATE is in _frontier_ with higher PATH\-COST __then__ 41 |          replace that _frontier_ node with _child_ 42 | 43 | --- 44 | __Figure__ ?? Uniform\-cost search on a graph. The algorithm is identical to the general graph search algorithm in Figure ??, except for the use of a priority queue and the addition of an extra check in case a shorter path to a frontier state is discovered. The data structure for _frontier_ needs to support efficient membership testing, so it should combine the capabilities of a priority queue and a hash table. 45 | -------------------------------------------------------------------------------- /md/Unify.md: -------------------------------------------------------------------------------- 1 | # UNIFY 2 | 3 | ## AIMA3e 4 | __function__ UNIFY(_x_, _y_, _θ_) __returns__ a substitution to make _x_ and _y_ identical 5 |  __inputs__: _x_, a variable, constant, list, or compound 6 |     _y_, a variable, constant, list, or compound 7 |     _θ_, the substitution built up so far (optional, defaults to empty) 8 | 9 |  __if__ _θ_ = failure __then return__ failure 10 |  __else if__ _x_ = _y_ __then return__ _θ_ 11 |  __else if__ VARIABLE?(_x_) __then return__ UNIVY-VAR(_x_, _y_, _θ_) 12 |  __else if__ VARIABLE?(_y_) __then return__ UNIFY-VAR(_y_, _x_, _θ_) 13 |  __else if__ COMPOUND?(_x_) and COMPOUND?(_y_) __then__ 14 |    __return__ UNIFY(_x_.ARGS, _y_.ARGS, UNIFY(_x_.OP, _y_.OP, _θ_)) 15 |  __else if__ LIST?(_x_) __and__ LIST?(_y_) __then__ 16 |    __return__ UNIFY(_x_.REST, _y_.REST, UNIFY(_x_.FIRST, _y_.FIRST, _θ_)) 17 |  __else return__ failure 18 | 19 | --- 20 | __function__ UNIFY-VAR(_var_, _x_, _θ_) __returns__ a substitution 21 | 22 |  __if__ {_var_ / _val_} ∈ _θ_ __then return__ UNIFY(_val_, _x_, _θ_) 23 |  __else if__ {_x_ / _val_} ∈ _θ_ __then return__ UNIFY(_var_, _val_, _θ_) 24 |  __else if__ OCCUR-CHECK?(_var_, _x_) __then return__ failure 25 |  __else return__ add {_var_/_x_} to _θ_ 26 | 27 | --- 28 | __Figure__ ?? The unification algorithm. The algorithm works by comparing the structures of the inputs, elements by element. The substitution _θ_ that is the argument to UNIFY is built up along the way and is used to make sure that later comparisons are consistent with bindings that were established earlier. In a compound expression, such as F(A, B), the OP field picks out the function symbol F and the ARGS field picks out the argument list (A, B). -------------------------------------------------------------------------------- /md/Value-Iteration.md: -------------------------------------------------------------------------------- 1 | # VALUE-ITERATION 2 | 3 | ## AIMA3e 4 | __function__ VALUE-ITERATION(_mdp_, _ε_) __returns__ a utility function 5 |  __inputs__: _mdp_, an MDP with states _S_, actions _A_(_s_), transition model _P_(_s′_ | _s_, _a_), 6 |       rewards _R_(_s_), discount _γ_ 7 |    _ε_, the maximum error allowed in the utility of any state 8 |  __local variables__: _U_, _U′_, vectors of utilities for states in _S_, initially zero 9 |         _δ_, the maximum change in the utility of any state in an iteration 10 | 11 |  __repeat__ 12 |    _U_ ← _U′_; _δ_ ← 0 13 |    __for each__ state _s_ in _S_ __do__ 14 |      _U′_\[_s_\] ← _R_(_s_) + _γ_ max_a_ ∈ _A_(_s_) Σ _P_(_s′_ | _s_, _a_) _U_\[_s′_\] 15 |      __if__ | _U′_\[_s_\] − _U_\[_s_\] | > _δ_ __then__ _δ_ ← | _U′_\[_s_\] − _U_\[_s_\] | 16 |  __until__ _δ_ < _ε_(1 − _γ_)/_γ_ 17 |  __return__ _U_ 18 | 19 | --- 20 | __Figure ??__ The value iteration algorithm for calculating utilities of states. The termination condition is from Equation (__??__). 21 | 22 | --- 23 | 24 | ## AIMA4e 25 | __function__ VALUE-ITERATION(_mdp_, _ε_) __returns__ a utility function 26 |  __inputs__: _mdp_, an MDP with states _S_, actions _A_(_s_), transition model _P_(_s′_ | _s_, _a_), 27 |       rewards _R_(_s_,_a_,_s′_), discount _γ_ 28 |    _ε_, the maximum error allowed in the utility of any state 29 |  __local variables__: _U_, _U′_, vectors of utilities for states in _S_, initially zero 30 |         _δ_, the maximum change in the utility of any state in an iteration 31 | 32 |  __repeat__ 33 |    _U_ ← _U′_; _δ_ ← 0 34 |    __for each__ state _s_ in _S_ __do__ 35 |      _U′_\[_s_\] ← max_a_ ∈ _A_(_s_) Q-VALUE(_mdp_,_s_,_a_,_U_) 36 |      __if__ | _U′_\[_s_\] − _U_\[_s_\] | > _δ_ __then__ _δ_ ← | _U′_\[_s_\] − _U_\[_s_\] | 37 |  __until__ _δ_ < _ε_(1 − _γ_)/_γ_ 38 |  __return__ _U_ 39 | 40 | --- 41 | __Figure ??__ The value iteration algorithm for calculating utilities of states. The termination condition is from Equation (__??__). 42 | ~ 43 | -------------------------------------------------------------------------------- /md/Version-Space-Learning.md: -------------------------------------------------------------------------------- 1 | # VERSION-SPACE-LEARNING 2 | 3 | ## AIMA3e 4 | __function__ Version-Space-Learning(_examples_) __returns__ a version space 5 |  __local variables__: _V_, the version space: the set of all hypotheses 6 | 7 |  _V_ ← the set of all hypotheses 8 |  __for each__ example _e_ in _examples_ __do__ 9 |    __if__ _V_ is not empty __then__ _V_ ← Version-Space-Update(_V_, _e_) 10 |  __return__ _V_ 11 | 12 | --- 13 | __function__ Version-Space-Update(_V_, _e_) __returns__ an updated version space 14 |  _V_ ← \{_h_ ∈ _V_ : _h_ is consistent with _e_\} 15 | 16 | --- 17 | __Figure ??__ The version space learning algorithm. It finds a subset of _V_ that is consistent with all the _examples_. 18 | -------------------------------------------------------------------------------- /md/WalkSAT.md: -------------------------------------------------------------------------------- 1 | # WALKSAT 2 | 3 | ## AIMA3e 4 | __function__ WALKSAT(_clauses_, _p_, _max\_flips_) __returns__ a satisfying model or _failure_ 5 |  __inputs__: _clauses_, a set of clauses in propositional logic 6 |     _p_, the probability of choosing to do a "random walk" move, typically around 0.5 7 |     _max\_flips_, number of flips allowed before giving up 8 | 9 |  _model_ ← a random assignment of _true_/_false_ to the symbols in _clauses_ 10 |  __for__ _i_ = 1 to _max\_flips_ __do__ 11 |    __if__ _model_ satisfies _clauses_ __then return__ _model_ 12 |    _clause_ ← a randomly selected clause from _clauses_ that is false in _model_ 13 |    __with probability__ _p_ flip the value in _model_ of a randomly selected symbol from _clause_ 14 |    __else__ flip whichever symbol in _clause_ maximizes the number of satisfied clauses 15 |  __return__ _failure_ 16 | 17 | --- 18 | __Figure__ ?? The WALKSAT algorithm for checking satisfiability by randomly flipping the values of variables. Many versions of the algorithm exist. --------------------------------------------------------------------------------