Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
283 commits
Select commit Hold shift + click to select a range
396c38b
Merge remote-tracking branch 'upstream/master'
dmeoli Aug 23, 2019
776c131
defined the PlanningProblem as a specialization of a search.Problem &…
dmeoli Aug 27, 2019
ccc7de1
fixed doctest in logic.py
dmeoli Aug 27, 2019
7e98afb
fixed doctest for cascade_distribution
dmeoli Aug 27, 2019
061cba1
added ForwardPlanner and tests
dmeoli Aug 30, 2019
8c10d9f
added __lt__ implementation for Expr
dmeoli Aug 30, 2019
aa61869
added more tests
dmeoli Aug 30, 2019
c4139e5
renamed forward planner
dmeoli Aug 31, 2019
e4c4343
Revert "renamed forward planner"
dmeoli Aug 31, 2019
6e084c0
renamed forward planner class & added doc
dmeoli Aug 31, 2019
b6a0cbd
added backward planner and tests
dmeoli Sep 2, 2019
1131f4d
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 3, 2019
1af8978
fixed mdp4e.py doctests
dmeoli Sep 3, 2019
a4ad133
removed ignore_delete_lists_heuristic flag
dmeoli Sep 3, 2019
26f2b5d
fixed heuristic for forward and backward planners
dmeoli Sep 6, 2019
9faf17a
added SATPlan and tests
dmeoli Sep 6, 2019
0be0f5d
fixed ignore delete lists heuristic in forward and backward planners
dmeoli Sep 7, 2019
2cc2d3f
fixed backward planner and added tests
dmeoli Sep 8, 2019
4222176
updated doc
dmeoli Sep 8, 2019
30af352
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 11, 2019
b69a907
added nary csp definition and examples
dmeoli Sep 11, 2019
6ff465a
added CSPlan and tests
dmeoli Sep 11, 2019
d3c291c
fixed CSPlan
dmeoli Sep 11, 2019
785850a
added book's cryptarithmetic puzzle example
dmeoli Sep 11, 2019
7249058
fixed typo errors in test_csp
dmeoli Sep 11, 2019
42e9cbc
fixed #1111
dmeoli Sep 12, 2019
0fb48f6
added sortedcontainers to yml and doc to CSPlan
dmeoli Sep 12, 2019
5cce7d9
added tests for n-ary csp
dmeoli Sep 13, 2019
b567a6d
fixed utils.extend
dmeoli Sep 13, 2019
2eba772
updated test_probability.py
dmeoli Sep 14, 2019
427e85a
converted static methods to functions
dmeoli Sep 15, 2019
cd1ad41
added AC3b and AC4 with heuristic and tests
dmeoli Sep 15, 2019
0092f27
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 16, 2019
d9dd4bb
added conflict-driven clause learning sat solver
dmeoli Sep 16, 2019
c0220d2
added tests for cdcl and heuristics
dmeoli Sep 16, 2019
8f0779d
fixed probability.py
dmeoli Sep 17, 2019
7a59010
fixed import
dmeoli Sep 17, 2019
0135db6
fixed kakuro
dmeoli Sep 20, 2019
ac98bd8
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 21, 2019
dca70da
added Martelli and Montanari rule-based unification algorithm
dmeoli Sep 25, 2019
84e7a55
removed duplicate standardize_variables
dmeoli Sep 25, 2019
20bc37b
renamed variables known as built-in functions
dmeoli Sep 26, 2019
4b02d92
fixed typos in learning.py
dmeoli Sep 26, 2019
8427b5f
renamed some files and fixed typos
dmeoli Sep 26, 2019
3ffe3e9
fixed typos
dmeoli Sep 26, 2019
2d0dbc2
fixed typos
dmeoli Sep 27, 2019
b7e8206
fixed tests
dmeoli Sep 27, 2019
0c5f0ac
removed unify_mm
dmeoli Sep 29, 2019
bcc169d
remove unnecessary brackets
dmeoli Sep 29, 2019
9dd097b
fixed tests
dmeoli Sep 29, 2019
abc8f17
moved utility functions to utils.py
dmeoli Sep 29, 2019
9839d14
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 29, 2019
50e036f
fixed typos
dmeoli Oct 1, 2019
44e1f9c
moved utils function to utils.py, separated probability learning clas…
dmeoli Oct 3, 2019
17285cc
added missing learners
dmeoli Oct 3, 2019
d80fed5
fixed Travis build
dmeoli Oct 3, 2019
a734d46
fixed typos
dmeoli Oct 3, 2019
df16744
fixed typos
dmeoli Oct 3, 2019
c81425f
fixed typos
dmeoli Oct 3, 2019
0071746
fixed typos
dmeoli Oct 4, 2019
25ac7b3
Merge branch 'master' into master
dmeoli Oct 4, 2019
f4f8663
fixed typos in agents files
dmeoli Oct 4, 2019
dd8ae31
fixed imports in agent files
dmeoli Oct 4, 2019
13000ac
Merge branch 'ml'
dmeoli Oct 4, 2019
b11adf4
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 7, 2019
e041479
fixed deep learning .ipynb imports
dmeoli Oct 8, 2019
be7c131
fixed typos
dmeoli Oct 8, 2019
9b3c8ba
added SVM
dmeoli Oct 8, 2019
8bede28
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 8, 2019
fa6676c
Merge branch 'master' into ml
dmeoli Oct 8, 2019
e0b4a1c
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 24, 2019
e31a5a3
Merge branch 'master' into ml
dmeoli Oct 24, 2019
99c1b4c
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 29, 2019
a672234
Merge branch 'master' into ml
dmeoli Oct 29, 2019
b9236db
added .ipynb and fixed typos
dmeoli Nov 1, 2019
3001803
adapted code for .ipynb
dmeoli Nov 1, 2019
e5f75f3
fixed typos
dmeoli Nov 1, 2019
278574d
updated .ipynb
dmeoli Nov 1, 2019
25c590d
updated .ipynb
dmeoli Nov 1, 2019
23e3d95
updated logic.py
dmeoli Nov 1, 2019
aa79be3
updated .ipynb
dmeoli Nov 1, 2019
42a6d4a
updated .ipynb
dmeoli Nov 1, 2019
ce3d0c6
updated planning.py
dmeoli Nov 1, 2019
8f5ef83
updated inf definition
dmeoli Nov 1, 2019
9d27673
fixed typos
dmeoli Nov 2, 2019
181d257
fixed typos
dmeoli Nov 2, 2019
08ad660
fixed typos
dmeoli Nov 2, 2019
658309d
fixed typos
dmeoli Nov 2, 2019
35fc24d
Revert "fixed typos"
dmeoli Nov 2, 2019
ecc7c2d
Revert "fixed typos"
dmeoli Nov 2, 2019
dbbe897
fixed typos
dmeoli Nov 2, 2019
8ef5e0c
fixed typos
dmeoli Nov 2, 2019
cf95e44
fixed typos
dmeoli Nov 2, 2019
0d64274
fixed typos
dmeoli Nov 2, 2019
3404deb
Merge branch 'master' into ml
dmeoli Nov 2, 2019
29644d4
fixed typos and utils imports in *4e.py files
dmeoli Nov 2, 2019
43f09c6
Merge branch 'master' into ml
dmeoli Nov 2, 2019
1c68b8a
Merge remote-tracking branch 'upstream/master'
dmeoli Nov 3, 2019
47df065
Merge remote-tracking branch 'upstream/master' into ml
dmeoli Nov 3, 2019
1654a9c
fixed typos
dmeoli Nov 3, 2019
fe5801e
Merge branch 'master' into ml
dmeoli Nov 3, 2019
b3d0352
Merge remote-tracking branch 'upstream/master'
dmeoli Nov 4, 2019
3960568
Merge branch 'master' into ml
dmeoli Nov 4, 2019
089d4b9
fixed typos
dmeoli Nov 4, 2019
c531100
Merge branch 'master' into ml
dmeoli Nov 4, 2019
b065c3f
fixed typos
dmeoli Nov 6, 2019
c7787cf
fixed typos
dmeoli Nov 6, 2019
e3b6a0c
Merge branch 'master' into ml
dmeoli Nov 6, 2019
d10fa04
fixed import
dmeoli Nov 10, 2019
e334940
fixed typos
dmeoli Nov 11, 2019
598a4ca
fixed typos
dmeoli Nov 11, 2019
8aeccda
fixd typos
dmeoli Nov 11, 2019
5afbf72
fixed typos
dmeoli Nov 11, 2019
182c588
fixed typos
dmeoli Nov 14, 2019
a47a516
updated SVM
dmeoli Nov 15, 2019
45cceab
added svm test
dmeoli Nov 15, 2019
86f91f9
fixed SVM and tests
dmeoli Nov 18, 2019
3f8f759
fixed some definitions and typos
dmeoli Nov 19, 2019
602627e
fixed svm and tests
dmeoli Nov 19, 2019
47c559e
added SVMs also in learning4e.py
dmeoli Nov 19, 2019
bcec266
fixed inf definition
dmeoli Nov 19, 2019
9a2541b
fixed .travis.yml
dmeoli Nov 19, 2019
2b55d16
fixed .travis.yml
dmeoli Nov 19, 2019
6143a07
fixed import
dmeoli Nov 19, 2019
bc4dd41
fixed inf definition
dmeoli Nov 19, 2019
d6f5024
replaced cvxopt with qpsolvers
dmeoli Nov 20, 2019
3473fc6
replaced cvxopt with quadprog
dmeoli Nov 20, 2019
924a4fb
fixed some definitions
dmeoli Nov 20, 2019
0044cbf
fixed typos and removed unnecessary tests
dmeoli Nov 20, 2019
75b8c2f
replaced quadprog with qpsolvers
dmeoli Nov 20, 2019
0a5fa77
fixed extend in utils
dmeoli Nov 20, 2019
132bf13
specified error type in try-catch block
dmeoli Nov 20, 2019
b81a7a6
fixed extend in utils
dmeoli Nov 20, 2019
72b5c20
fixed typos
dmeoli Nov 21, 2019
b63a622
fixed learning.py
dmeoli Nov 21, 2019
210c800
fixed doctest errors
dmeoli Nov 21, 2019
dca1c90
added comments
dmeoli Nov 21, 2019
bc4b18f
removed unnecessary if condition
dmeoli Nov 21, 2019
bd74894
updated learning.py
dmeoli Nov 22, 2019
94e81e1
fixed imports
dmeoli Nov 24, 2019
27dd36a
removed unnecessary imports
dmeoli Nov 24, 2019
8f5b1b0
fixed keras imports
dmeoli Nov 24, 2019
ede8658
fixed typos
dmeoli Nov 24, 2019
72a9040
fixed learning_curve
dmeoli Nov 30, 2019
c8a507c
added comments
dmeoli Dec 2, 2019
1b0d37c
Merge remote-tracking branch 'upstream/master'
dmeoli Dec 3, 2019
3260123
Merge remote-tracking branch 'upstream/master'
dmeoli Dec 12, 2019
83d84d7
fixed typos
dmeoli Dec 12, 2019
6b278c3
removed inf and isclose definition from utils and replaced with numpy…
dmeoli Dec 14, 2019
2847f54
fixed doctests
dmeoli Dec 14, 2019
0a8b1a9
Merge remote-tracking branch 'upstream/master'
dmeoli Dec 14, 2019
c1383d1
Merge remote-tracking branch 'upstream/master'
dmeoli Dec 19, 2019
d4b87b6
fixed numpy imports
dmeoli Jan 2, 2020
33ff87a
fixed superclass call
dmeoli Jan 2, 2020
b2f6d59
removed utils import from 4e py file
dmeoli Jan 2, 2020
d1b31da
removed unnecessary norm function in utils and fixed Activation defin…
dmeoli Jan 2, 2020
8205e43
Merge remote-tracking branch 'upstream/master'
dmeoli Jan 3, 2020
968c861
removed unnecessary clip function
dmeoli Jan 3, 2020
6584ee8
removed unnecessary import and functions from utils
dmeoli Jan 3, 2020
4de42bc
added tests and fxed some functions
dmeoli Jan 4, 2020
a3f3e39
fixed doc
dmeoli Jan 4, 2020
da5a834
Merge remote-tracking branch 'upstream/master'
dmeoli Jan 4, 2020
c97a543
fixed typos in gui folder
dmeoli Jan 8, 2020
1bfa61b
Merge remote-tracking branch 'upstream/master'
dmeoli Jan 8, 2020
f795d6f
removed unnecessary Keras classes and updated pytest.ini
dmeoli Jan 24, 2020
d229c23
Merge remote-tracking branch 'upstream/master'
dmeoli Jan 24, 2020
d9a67f7
fixed some details
dmeoli Jan 24, 2020
09262c9
readded Keras classes
dmeoli Jan 24, 2020
716459e
fixed import
dmeoli Jan 24, 2020
64f1cd3
fixed some parameters
dmeoli Jan 24, 2020
53ec4e2
removed unnecessary superclass
dmeoli Jan 25, 2020
d285097
Merge remote-tracking branch 'upstream/master'
dmeoli Jan 25, 2020
184a109
fixed neural net
dmeoli Jan 28, 2020
cc307c7
added LinearLearner, LogisticLearner with tests and fixed NeuralNetLe…
dmeoli Jan 28, 2020
70d662b
removed random_weights and substituted with np.random.uniform
dmeoli Jan 28, 2020
aaf9c7b
fixed imports
dmeoli Jan 28, 2020
96b85f2
Revert "fixed imports"
dmeoli Jan 28, 2020
1d68018
Revert "removed random_weights and substituted with np.random.uniform"
dmeoli Jan 28, 2020
13e4fcf
revert
dmeoli Jan 28, 2020
4547721
fixed typo
dmeoli Jan 28, 2020
4ee4c1c
fixed .ini and DecisionTreeLearner
dmeoli Jan 28, 2020
2988c95
fixed tests
dmeoli Jan 29, 2020
5bfde8e
removed main and fixed AutoencoderLearner
dmeoli Jan 29, 2020
7435c47
revert NeuralNetLearner and PerceptronLearner definition
dmeoli Jan 29, 2020
ed25383
fixed all tests and removed Learner class
dmeoli Jan 29, 2020
104e202
fixed tests
dmeoli Jan 29, 2020
9f5db94
fixed tests
dmeoli Jan 29, 2020
2c8f121
fixed tests
dmeoli Jan 29, 2020
3362d9b
fixed some function definition
dmeoli Jan 30, 2020
67b627c
fixed verbose definition
dmeoli Jan 30, 2020
bf97d7d
fixed tests
dmeoli Jan 30, 2020
7d6d8e1
fixed tests
dmeoli Jan 30, 2020
507f922
fixed tests
dmeoli Jan 30, 2020
d358ce7
Merge remote-tracking branch 'upstream/master'
dmeoli Feb 4, 2020
377106a
updated .travis.yml
dmeoli Feb 10, 2020
57e3982
fixed .travis.yml
dmeoli Feb 10, 2020
133170d
fixed .travis.yml
dmeoli Feb 10, 2020
04c9151
fixed all tests
dmeoli Feb 10, 2020
53e08db
fixed requirements.txt
dmeoli Feb 10, 2020
4a6c4b6
fixed .travis.yml
dmeoli Feb 10, 2020
17a5cf7
update .travis.yml
dmeoli Feb 10, 2020
ddd6230
rollback .travis.yml
dmeoli Feb 10, 2020
eaa0530
rollback tests
dmeoli Feb 10, 2020
30318a5
Merge remote-tracking branch 'upstream/master'
dmeoli Feb 16, 2020
9216c37
fixed output layer with softmax as activation function
dmeoli Feb 17, 2020
7619fb8
Merge remote-tracking branch 'upstream/master'
dmeoli Feb 21, 2020
0460e87
updated yml
dmeoli Apr 21, 2020
b259e8e
Merge remote-tracking branch 'upstream/master'
dmeoli Apr 21, 2020
6fb2cd6
updated requirements.txt
dmeoli Apr 21, 2020
4dd9ebb
fixed svc
dmeoli Apr 21, 2020
a4d36de
fixed syntax warns
dmeoli Apr 21, 2020
962dd1e
fixed syntax warns
dmeoli Apr 21, 2020
3987d5d
removed 3.8
dmeoli Apr 21, 2020
d1f94ef
added python 3.8 support
dmeoli Apr 23, 2020
a6bb53e
fixed doctests
dmeoli Apr 23, 2020
792d85e
fixed spaces and doctest
dmeoli Apr 23, 2020
1e3015f
added SVR with r2 and accuracy metrics
dmeoli May 16, 2020
0ed3931
Merge remote-tracking branch 'upstream/master'
dmeoli Jun 10, 2020
db80d0d
Merge remote-tracking branch 'upstream/master'
dmeoli Jun 22, 2020
41fd6e2
fixed imports
dmeoli Jun 22, 2020
472b9d7
fixed tests
dmeoli Jun 22, 2020
c1ba725
removed not allowed imports
dmeoli Jun 22, 2020
76452f4
fixed
dmeoli Jun 23, 2020
7f817ec
fixed keras
dmeoli Jun 23, 2020
fa68504
fixed
dmeoli Jun 23, 2020
0240551
updated requirements.txt
dmeoli Jun 23, 2020
31a09c9
Merge remote-tracking branch 'upstream/master'
dmeoli Jun 23, 2020
05ca823
Merge branch 'aimacode:master' into master
dmeoli Jun 8, 2022
3094b8d
Merge remote-tracking branch 'upstream/master'
dmeoli Jun 23, 2026
597131e
Fix NotImplementedError raises, docstring escapes, keras lr arg and f…
dmeoli Jun 23, 2026
d62e21a
Add Kalman filter (Section 15.4)
dmeoli Jun 23, 2026
0a70586
Add EM for Gaussian mixtures (Section 20.3)
dmeoli Jun 23, 2026
d4899a3
Add Baum-Welch for HMM learning (Section 20.3)
dmeoli Jun 23, 2026
fd985f8
Add dynamic decision network POMDP look-ahead agent (Section 17.4)
dmeoli Jun 23, 2026
36054b0
Add EM for Bayes net with hidden variables (Section 20.3.2)
dmeoli Jun 23, 2026
f95540c
Add non-cooperative game theory: dominance, Nash equilibria, zero-sum…
dmeoli Jun 23, 2026
a149b53
Add cooperative game theory (Shapley, core) and social choice (voting…
dmeoli Jun 23, 2026
b9d7374
Add contract net protocol and alternating-offers bargaining (Section …
dmeoli Jun 23, 2026
e5055d7
Add dynamic Bayesian network with unrolling and exact filtering (Sect…
dmeoli Jun 23, 2026
46240c2
Add SARSA on-policy TD-learning agent (Section 21.3)
dmeoli Jun 23, 2026
33ea0b9
Add iterated elimination of dominated strategies (Section 18.2)
dmeoli Jun 23, 2026
1f5dfb1
Add executed demo notebooks for the new 4e algorithms
dmeoli Jun 23, 2026
51fb6c5
Add tests from the book and solutions manual (zero-sum 17.17, saddle …
dmeoli Jun 23, 2026
774263e
Fix spelling typos in comments, docstrings and data labels
dmeoli Jun 23, 2026
ead0c1b
Update README: modern Python version support and typo fix
dmeoli Jun 23, 2026
28018e3
Clean up game_theory.py line lengths for flake8
dmeoli Jun 23, 2026
1128866
Modernize CI: bump Travis Python versions and add GitHub Actions work…
dmeoli Jun 23, 2026
779463f
Add tests for SAT heuristics/restarts and n-ary CSP extras
dmeoli Jun 23, 2026
ceea007
Rename files to follow snake_case and 4e conventions
dmeoli Jun 23, 2026
389d5a7
Rename camelCase identifiers to snake_case (PEP 8)
dmeoli Jun 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
env:
MPLBACKEND: Agg
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov flake8

- name: Lint with flake8
run: flake8 .
continue-on-error: true

- name: Run tests
run: pytest --cov=./
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ __pycache__/
# Distribution / packaging
.Python
env/
.venv/
venv/
build/
develop-eggs/
dist/
Expand Down
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: python

dist: jammy

python:
- 3.5
- 3.6
- 3.7
- 3.8
- 3.9
- 3.10
- 3.11
- 3.12

before_install:
- git submodule update --remote
Expand All @@ -14,10 +16,9 @@ install:

script:
- py.test --cov=./
- python -m doctest -v *.py

after_success:
- flake8 --max-line-length 100 --ignore=E121,E123,E126,E221,E222,E225,E226,E242,E701,E702,E704,E731,W503 .
- flake8 --max-line-length 100 --ignore=E121,E123,E126,E221,E222,E225,E226,E242,E701,E702,E704,E731,W503,W504,F405,F841 .

notifications:
email: false
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@


# `aima-python` [![Build Status](https://travis-ci.org/aimacode/aima-python.svg?branch=master)](https://travis-ci.org/aimacode/aima-python) [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/aimacode/aima-python)
# `aima-python` [![tests](https://github.com/aimacode/aima-python/actions/workflows/tests.yml/badge.svg)](https://github.com/aimacode/aima-python/actions/workflows/tests.yml) [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/aimacode/aima-python)


Python code for the book *[Artificial Intelligence: A Modern Approach](http://aima.cs.berkeley.edu).* You can use this in conjunction with a course on AI, or for study on your own. We're looking for [solid contributors](https://github.com/aimacode/aima-python/blob/master/CONTRIBUTING.md) to help.

# Updates for 4th Edition

The 4th edition of the book as out now in 2020, and thus we are updating the code. All code here will reflect the 4th edition. Changes include:
The 4th edition of the book is out now in 2020, and thus we are updating the code. All code here will reflect the 4th edition. Changes include:

- Move from Python 3.5 to 3.7.
- Move from Python 3.5 to 3.7, and on to modern Python (the code now runs on Python 3.9 and up).
- More emphasis on Jupyter (Ipython) notebooks.
- More projects using external packages (tensorflow, etc.).

Expand All @@ -23,9 +23,9 @@ When complete, this project will have Python implementations for all the pseudoc
- `search_XX.ipynb`: Notebooks that show how to use the code, broken out into various topics (the `XX`).
- `tests/test_search.py`: A lightweight test suite, using `assert` statements, designed for use with [`py.test`](http://pytest.org/latest/), but also usable on their own.

# Python 3.7 and up
# Python 3.9 and up

The code for the 3rd edition was in Python 3.5; the current 4th edition code is in Python 3.7. It should also run in later versions, but does not run in Python 2. You can [install Python](https://www.python.org/downloads) or use a browser-based Python interpreter such as [repl.it](https://repl.it/languages/python3).
The code for the 3rd edition was in Python 3.5; the 4th edition code targets Python 3.7 and runs on Python 3.9 and up, but does not run in Python 2. Continuous integration runs the full test suite (including the deep-learning modules) on Python 3.9, 3.10, 3.11 and 3.12; note that some optional dependencies (`tensorflow`, `keras`, `opencv-python`) do not yet ship wheels for the very latest releases (3.13+), so one of those versions is recommended for running everything. You can [install Python](https://www.python.org/downloads) or use a browser-based Python interpreter such as [repl.it](https://repl.it/languages/python3).
You can run the code in an IDE, or from the command line with `python -i filename.py` where the `-i` option puts you in an interactive loop where you can run Python functions. All notebooks are available in a [binder environment](http://mybinder.org/repo/aimacode/aima-python). Alternatively, visit [jupyter.org](http://jupyter.org/) for instructions on setting up your own Jupyter notebook environment.

Features from Python 3.6 and 3.7 that we will be using for this version of the code:
Expand Down Expand Up @@ -120,7 +120,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 7.15 | PL-FC-Entails? | `pl_fc_entails` | [`logic.py`][logic] | Done | Included |
| 7.17 | DPLL-Satisfiable? | `dpll_satisfiable` | [`logic.py`][logic] | Done | Included |
| 7.18 | WalkSAT | `WalkSAT` | [`logic.py`][logic] | Done | Included |
| 7.20 | Hybrid-Wumpus-Agent | `HybridWumpusAgent` | | | |
| 7.20 | Hybrid-Wumpus-Agent | `HybridWumpusAgent` | [`logic.py`][logic] | Done | Included |
| 7.22 | SATPlan | `SAT_plan` | [`logic.py`][logic] | Done | Included |
| 9 | Subst | `subst` | [`logic.py`][logic] | Done | Included |
| 9.1 | Unify | `unify` | [`logic.py`][logic] | Done | Included |
Expand All @@ -147,22 +147,38 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 15.4 | Forward-Backward | `forward_backward` | [`probability.py`][probability] | Done | Included |
| 15.6 | Fixed-Lag-Smoothing | `fixed_lag_smoothing` | [`probability.py`][probability] | Done | Included |
| 15.17 | Particle-Filtering | `particle_filtering` | [`probability.py`][probability] | Done | Included |
| 15.4 | Kalman-Filter | `KalmanFilter` | [`probability.py`][probability] | Done | Included |
| 15.5 | Dynamic-Bayesian-Network | `DynamicBayesNet` | [`probability.py`][probability] | Done | Included |
| 16.9 | Information-Gathering-Agent | `InformationGatheringAgent` | [`probability.py`][probability] | Done | Included |
| 17.4 | Value-Iteration | `value_iteration` | [`mdp.py`][mdp] | Done | Included |
| 17.7 | Policy-Iteration | `policy_iteration` | [`mdp.py`][mdp] | Done | Included |
| 17.9 | POMDP-Value-Iteration | `pomdp_value_iteration` | [`mdp.py`][mdp] | Done | Included |
| 17.4 | Dynamic-Decision-Network | `pomdp_lookahead` | [`mdp4e.py`](mdp4e.py) | Done | Included |
| 18.2 | Iterated-Dominance | `iterated_dominance` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.2 | Pure-Nash-Equilibria | `pure_nash_equilibria` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.2 | Zero-Sum-Game (LP) | `solve_zero_sum_game` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.3 | Shapley-Value | `shapley_value` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.3 | Core (cooperative game) | `is_in_core` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.4 | Voting (plurality/Borda/Condorcet)| `plurality_winner` etc. | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.4 | Vickrey-Auction | `vickrey_auction` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.4.1 | Contract-Net-Protocol | `contract_net` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.4.4 | Alternating-Offers-Bargaining | `alternating_offers_bargaining` | [`game_theory4e.py`](game_theory4e.py) | Done | Included |
| 18.5 | Decision-Tree-Learning | `DecisionTreeLearner` | [`learning.py`][learning] | Done | Included |
| 18.8 | Cross-Validation | `cross_validation` | [`learning.py`][learning]\* | | |
| 18.11 | Decision-List-Learning | `DecisionListLearner` | [`learning.py`][learning]\* | | |
| 18.8 | Cross-Validation | `cross_validation` | [`learning.py`][learning] | Done | Included |
| 18.11 | Decision-List-Learning | `DecisionListLearner` | [`learning.py`][learning] | Done | Included |
| 18.24 | Back-Prop-Learning | `BackPropagationLearner` | [`learning.py`][learning] | Done | Included |
| 18.34 | AdaBoost | `AdaBoost` | [`learning.py`][learning] | Done | Included |
| 20.X | EM (Mixture of Gaussians) | `gaussian_mixture_em` | [`learning.py`][learning] | Done | Included |
| 20.3.2 | EM (Bayes net hidden variable) | `naive_bayes_em` | [`learning.py`][learning] | Done | Included |
| 20.3 | Baum-Welch (HMM learning) | `baum_welch` | [`probability.py`][probability] | Done | Included |
| 19.2 | Current-Best-Learning | `current_best_learning` | [`knowledge.py`](knowledge.py) | Done | Included |
| 19.3 | Version-Space-Learning | `version_space_learning` | [`knowledge.py`](knowledge.py) | Done | Included |
| 19.8 | Minimal-Consistent-Det | `minimal_consistent_det` | [`knowledge.py`](knowledge.py) | Done | Included |
| 19.12 | FOIL | `FOIL_container` | [`knowledge.py`](knowledge.py) | Done | Included |
| 21.2 | Passive-ADP-Agent | `PassiveADPAgent` | [`rl.py`][rl] | Done | Included |
| 21.4 | Passive-TD-Agent | `PassiveTDAgent` | [`rl.py`][rl] | Done | Included |
| 21.8 | Q-Learning-Agent | `QLearningAgent` | [`rl.py`][rl] | Done | Included |
| 21.8 | SARSA-Agent | `SARSALearningAgent` | [`rl.py`][rl] | Done | Included |
| 22.1 | HITS | `HITS` | [`nlp.py`][nlp] | Done | Included |
| 23 | Chart-Parse | `Chart` | [`nlp.py`][nlp] | Done | Included |
| 23.5 | CYK-Parse | `CYK_parse` | [`nlp.py`][nlp] | Done | Included |
Expand Down
8 changes: 4 additions & 4 deletions csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def queen_constraint(A, a, B, b):


class NQueensCSP(CSP):
"""
r"""
Make a CSP for the nQueens problem for search with min_conflicts.
Suitable for large n, it uses only data structures of size O(n).
Think of placing queens one per column, from left to right.
Expand Down Expand Up @@ -818,7 +818,7 @@ def Zebra():
Colors = 'Red Yellow Blue Green Ivory'.split()
Pets = 'Dog Fox Snails Horse Zebra'.split()
Drinks = 'OJ Tea Coffee Milk Water'.split()
Countries = 'Englishman Spaniard Norwegian Ukranian Japanese'.split()
Countries = 'Englishman Spaniard Norwegian Ukrainian Japanese'.split()
Smokes = 'Kools Chesterfields Winston LuckyStrike Parliaments'.split()
variables = Colors + Pets + Drinks + Countries + Smokes
domains = {}
Expand All @@ -829,7 +829,7 @@ def Zebra():
neighbors = parse_neighbors("""Englishman: Red;
Spaniard: Dog; Kools: Yellow; Chesterfields: Fox;
Norwegian: Blue; Winston: Snails; LuckyStrike: OJ;
Ukranian: Tea; Japanese: Parliaments; Kools: Horse;
Ukrainian: Tea; Japanese: Parliaments; Kools: Horse;
Coffee: Green; Green: Ivory""")
for type in [Colors, Pets, Drinks, Countries, Smokes]:
for A in type:
Expand Down Expand Up @@ -857,7 +857,7 @@ def zebra_constraint(A, a, B, b, recurse=0):
return same
if A == 'LuckyStrike' and B == 'OJ':
return same
if A == 'Ukranian' and B == 'Tea':
if A == 'Ukrainian' and B == 'Tea':
return same
if A == 'Japanese' and B == 'Parliaments':
return same
Expand Down
6 changes: 3 additions & 3 deletions deep_learning4e.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def forward(self, inputs):
class Activation:

def function(self, x):
return NotImplementedError
raise NotImplementedError

def derivative(self, x):
return NotImplementedError
raise NotImplementedError

def __call__(self, x):
return self.function(x)
Expand Down Expand Up @@ -575,7 +575,7 @@ def AutoencoderLearner(inputs, encoding_size, epochs=200, verbose=False):
model.add(Dense(input_size, activation='relu', kernel_initializer='random_uniform', bias_initializer='ones'))

# update model with sgd
sgd = optimizers.SGD(lr=0.01)
sgd = optimizers.SGD(learning_rate=0.01)
model.compile(loss='mean_squared_error', optimizer=sgd, metrics=['accuracy'])

# train the model
Expand Down
152 changes: 152 additions & 0 deletions dynamic_decision_network.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "07e68a51",
"metadata": {},
"source": [
"# Dynamic Decision Networks (Section 17.4)\n",
"\n",
"Online decision making for a POMDP modeled as a dynamic decision network, using the belief-state look-ahead agent in [`mdp4e.py`](mdp4e.py)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "bded6ebb",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-23T10:42:10.709493Z",
"iopub.status.busy": "2026-06-23T10:42:10.709226Z",
"iopub.status.idle": "2026-06-23T10:42:10.874538Z",
"shell.execute_reply": "2026-06-23T10:42:10.872073Z"
}
},
"outputs": [],
"source": [
"from mdp4e import POMDP, update_belief, pomdp_lookahead"
]
},
{
"cell_type": "markdown",
"id": "f0fb1298",
"metadata": {},
"source": [
"A two-state 'tiger-like' POMDP: action 0 pays off in state 0, action 1 in state 1, and action 2 is a sensing action (small cost, informative observation)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cccf717e",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-23T10:42:10.877731Z",
"iopub.status.busy": "2026-06-23T10:42:10.877319Z",
"iopub.status.idle": "2026-06-23T10:42:10.883821Z",
"shell.execute_reply": "2026-06-23T10:42:10.882142Z"
}
},
"outputs": [],
"source": [
"t_prob = [[[0.65, 0.35], [0.65, 0.35]], [[0.65, 0.35], [0.65, 0.35]], [[1.0, 0.0], [0.0, 1.0]]]\n",
"e_prob = [[[0.5, 0.5], [0.5, 0.5]], [[0.5, 0.5], [0.5, 0.5]], [[0.8, 0.2], [0.3, 0.7]]]\n",
"rewards = [[5, -10], [-20, 5], [-1, -1]]\n",
"pomdp = POMDP(('0', '1', '2'), t_prob, e_prob, rewards, ('0', '1'), gamma=0.95)"
]
},
{
"cell_type": "markdown",
"id": "1b6315c8",
"metadata": {},
"source": [
"### Belief update (POMDP filtering, Equation 17.17)\n",
"Observation 0 (more likely in state 0) shifts a uniform belief towards state 0."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e117ad73",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-23T10:42:10.888179Z",
"iopub.status.busy": "2026-06-23T10:42:10.887720Z",
"iopub.status.idle": "2026-06-23T10:42:10.910700Z",
"shell.execute_reply": "2026-06-23T10:42:10.909496Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"belief after sensing obs 0: [0.727, 0.273]\n"
]
}
],
"source": [
"print('belief after sensing obs 0:', [round(b, 3) for b in update_belief(pomdp, [0.5, 0.5], '2', 0)])"
]
},
{
"cell_type": "markdown",
"id": "578f7466",
"metadata": {},
"source": [
"### Look-ahead decisions\n",
"When the state is known the agent commits to the rewarding action; when it is unknown it prefers to gather information first."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d904ab41",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-23T10:42:10.914146Z",
"iopub.status.busy": "2026-06-23T10:42:10.913844Z",
"iopub.status.idle": "2026-06-23T10:42:10.937111Z",
"shell.execute_reply": "2026-06-23T10:42:10.936126Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"belief [0.9, 0.1], depth 1 -> action 0\n",
"belief [0.1, 0.9], depth 1 -> action 1\n",
"belief [0.5, 0.5], depth 2 -> action 2 (sense)\n"
]
}
],
"source": [
"print('belief [0.9, 0.1], depth 1 -> action', pomdp_lookahead(pomdp, [0.9, 0.1], depth=1))\n",
"print('belief [0.1, 0.9], depth 1 -> action', pomdp_lookahead(pomdp, [0.1, 0.9], depth=1))\n",
"print('belief [0.5, 0.5], depth 2 -> action', pomdp_lookahead(pomdp, [0.5, 0.5], depth=2), '(sense)')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading