Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In more detail:

## Editions: target the 4th edition

We are **not** maintaining two parallel editions. As [Peter Norvig stated](https://github.com/aimacode/aima-python/issues/1188#issuecomment-641669882), all new work should move toward the 4th edition. When a module exists as a pair (e.g. `agents.py` / `agents4e.py`), prefer adding 4e content; don't extend the 3e-only version. We are converging on a single, 4e version per module. See the *Edition policy* section in the README for details.
We are **not** maintaining two parallel editions. As [Peter Norvig stated](https://github.com/aimacode/aima-python/issues/1188#issuecomment-641669882), all new work should move toward the 4th edition. The old 3e/4e module pairs have now been **merged into a single version per topic** (no `*4e.py` files remain), and every module lives in the importable `aima/` package. Add new 4e content directly to the relevant module (e.g. `aima/search.py`); don't reintroduce edition-suffixed files. See the *Edition policy* section in the README for details.

## New and Improved Algorithms

Expand All @@ -43,7 +43,7 @@ In this project we use Jupyter/IPython Notebooks to showcase the algorithms in t
- Proofread the notebooks for grammar mistakes, typos, or general errors.
- Move visualization and unrelated to the algorithm code from notebooks to `notebook_utils.py` (a file used to store code for the notebooks, like visualization and other miscellaneous stuff). Make sure the notebooks still work and have their outputs showing!
- Replace the `%psource` magic notebook command with the function `psource` from `notebook_utils.py` where needed. Examples where this is useful are a) when we want to show code for algorithm implementation and b) when we have consecutive cells with the magic keyword (in this case, if the code is large, it's best to leave the output hidden).
- Add the function `pseudocode(algorithm_name)` in algorithm sections. The function prints the pseudocode of the algorithm. You can see some example usage in [`knowledge.ipynb`](https://github.com/aimacode/aima-python/blob/master/knowledge.ipynb).
- Add the function `pseudocode(algorithm_name)` in algorithm sections. The function prints the pseudocode of the algorithm. You can see some example usage in [`knowledge_current_best.ipynb`](https://github.com/aimacode/aima-python/blob/master/notebooks/knowledge_current_best.ipynb).
- Edit existing sections for algorithms to add more information and/or examples.
- Add visualizations for algorithms. The visualization code should go in `notebook_utils.py` to keep things clean.
- Add new sections for algorithms not yet covered. The general format we use in the notebooks is the following: First start with an overview of the algorithm, printing the pseudocode and explaining how it works. Then, add some implementation details, including showing the code (using `psource`). Finally, add examples for the implementations, showing how the algorithms work. Don't fret with adding complex, real-world examples; the project is meant for educational purposes. You can of course choose another format if something better suits an algorithm.
Expand Down
75 changes: 39 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ The 4th edition of the book is out now in 2020, and thus we are updating the cod
**Edition policy (3rd vs 4th).** As [Peter Norvig stated](https://github.com/aimacode/aima-python/issues/1188#issuecomment-641669882), we are *not* maintaining two parallel editions — all new work should move toward the 4th edition. Concretely:

- The **4th edition is canonical**: new algorithms, fixes and pseudocode references should follow the 4e numbering and content.
- Some modules still come in pairs (e.g. `agents.py` / `agents4e.py`). The unsuffixed modules are the primary, fully-tested base that the notebooks and tests use today; the `*4e.py` modules carry 4e-specific ports and algorithms not present in the 3e files. We are **converging on a single version per module**; until that migration is complete, prefer adding 4e content over extending the 3e-only versions.
- New 4th-edition-only material (e.g. `deep_learning4e.py`, `game_theory4e.py`, `perception4e.py`) lives directly in its 4e module.
- The 3e/4e split is **done**: there is now a **single version per module** (no `*4e.py` files remain). The old 3e/4e pairs have been merged — the canonical implementation was kept and any genuinely-new 4e algorithms were folded in — and the 4e-only modules (`deep_learning.py`, `game_theory.py`, `making_simple_decisions.py`, `perception.py`) were de-suffixed. Add new 4e content directly to the relevant module.



# Structure of the Project

When complete, this project will have Python implementations for all the pseudocode algorithms in the book, as well as tests and examples of use. For each major topic, such as `search`, we provide the following files:
When complete, this project will have Python implementations for all the pseudocode algorithms in the book, as well as tests and examples of use. The code is organised into three top-level folders:

- `search.ipynb` and `search.py`: Implementations of all the pseudocode algorithms, and necessary support functions/classes/data. The `.py` file is generated automatically from the `.ipynb` file; the idea is that it is easier to read the documentation in the `.ipynb` file.
- `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.
- **`aima/`** — the importable Python package: one module per major topic (e.g. `aima/search.py`) with the implementations of the pseudocode algorithms and their support functions/classes/data.
- **`notebooks/`** — the Jupyter notebooks that explain and demonstrate the code (e.g. `notebooks/search.ipynb`), plus the per-chapter `notebooks/chapterNN/` demos. Each notebook starts with a small bootstrap cell so it runs correctly from the `notebooks/` folder (it `chdir`s to the repo root so `from aima import ...` and the `aima-data/`/`images/` paths resolve).
- **`tests/`** — a lightweight test suite (e.g. `tests/test_search.py`), using `assert` statements, designed for use with [`py.test`](http://pytest.org/latest/) but also usable on their own.

# Python 3.9 and up

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](https://mybinder.org/v2/gh/aimacode/aima-python/master). Alternatively, visit [jupyter.org](http://jupyter.org/) for instructions on setting up your own Jupyter notebook environment.
The algorithms live in the `aima` package, so you import them as `from aima.search import astar_search` (or `from aima import search`). You can install the package in editable mode with `pip install -e .` and then run the code in an IDE, or from the command line with `python -i -m aima.search` where the `-i` option puts you in an interactive loop where you can run Python functions. All notebooks are available in a [binder environment](https://mybinder.org/v2/gh/aimacode/aima-python/master). 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:
- [f-strings](https://docs.python.org/3.6/whatsnew/3.6.html#whatsnew36-pep498): all string formatting should be done with `f'var = {var}'`, not with `'var = {}'.format(var)` nor `'var = %s' % var`.
Expand All @@ -57,6 +56,10 @@ cd aima-python
pip install -r requirements.txt
```

A couple of notebooks also need the [Graphviz](https://graphviz.org/download/) system
binary (`dot`) for rendering — the `graphviz` PyPI package is only a wrapper. Install it
with your OS package manager if needed (e.g. `apt install graphviz`, `brew install graphviz`).

You also need to fetch the datasets from the [`aima-data`](https://github.com/aimacode/aima-data) repository:

```
Expand All @@ -77,7 +80,7 @@ And you are good to go!

# Index of Algorithms

Here is a table of algorithms, the figure, name of the algorithm in the book and in the repository, and the file where they are implemented in the repository. This chart was originally made for the third edition of the book; per the edition policy above, the project is converging on the fourth edition (4e modules and numbering). Empty implementations are a good place for contributors to look for an issue. The [aima-pseudocode](https://github.com/aimacode/aima-pseudocode) project describes all the algorithms from the book. An asterisk next to the file name denotes the algorithm is not fully implemented. Another great place for contributors to start is by adding tests and writing on the notebooks. You can see which algorithms have tests and notebook sections below. If the algorithm you want to work on is covered, don't worry! You can still add more tests and provide some examples of use in the notebook!
Here is a table of algorithms, the figure, name of the algorithm in the book and in the repository, and the file where they are implemented in the repository. This chart was originally made for the third edition of the book; per the edition policy above, the project has converged on the fourth edition (4th-edition content, a single module per topic, all under the `aima/` package). Empty implementations are a good place for contributors to look for an issue. The [aima-pseudocode](https://github.com/aimacode/aima-pseudocode) project describes all the algorithms from the book. An asterisk next to the file name denotes the algorithm is not fully implemented. Another great place for contributors to start is by adding tests and writing on the notebooks. You can see which algorithms have tests and notebook sections below. If the algorithm you want to work on is covered, don't worry! You can still add more tests and provide some examples of use in the notebook!

| **Figure** | **Name (in 3<sup>rd</sup> edition)** | **Name (in repository)** | **File** | **Tests** | **Notebook**
|:-------|:----------------------------------|:------------------------------|:--------------------------------|:-----|:---------|
Expand Down Expand Up @@ -159,16 +162,16 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 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 |
| 17.4 | Dynamic-Decision-Network | `pomdp_lookahead` | [`mdp.py`](aima/mdp.py) | Done | Included |
| 18.2 | Iterated-Dominance | `iterated_dominance` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.2 | Pure-Nash-Equilibria | `pure_nash_equilibria` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.2 | Zero-Sum-Game (LP) | `solve_zero_sum_game` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.3 | Shapley-Value | `shapley_value` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.3 | Core (cooperative game) | `is_in_core` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.4 | Voting (plurality/Borda/Condorcet)| `plurality_winner` etc. | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.4 | Vickrey-Auction | `vickrey_auction` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.4.1 | Contract-Net-Protocol | `contract_net` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.4.4 | Alternating-Offers-Bargaining | `alternating_offers_bargaining` | [`game_theory.py`](aima/game_theory.py) | Done | Included |
| 18.5 | Decision-Tree-Learning | `DecisionTreeLearner` | [`learning.py`][learning] | Done | Included |
| 18.8 | Cross-Validation | `cross_validation` | [`learning.py`][learning] | Done | Included |
| 18.11 | Decision-List-Learning | `DecisionListLearner` | [`learning.py`][learning] | Done | Included |
Expand All @@ -177,10 +180,10 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 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 |
| 19.2 | Current-Best-Learning | `current_best_learning` | [`knowledge.py`](aima/knowledge.py) | Done | Included |
| 19.3 | Version-Space-Learning | `version_space_learning` | [`knowledge.py`](aima/knowledge.py) | Done | Included |
| 19.8 | Minimal-Consistent-Det | `minimal_consistent_det` | [`knowledge.py`](aima/knowledge.py) | Done | Included |
| 19.12 | FOIL | `FOILContainer` | [`knowledge.py`](aima/knowledge.py) | Done | Included |
| 21.2 | Passive-ADP-Agent | `PassiveADPAgent` | [`reinforcement_learning.py`][rl] | Done | Included |
| 21.4 | Passive-TD-Agent | `PassiveTDAgent` | [`reinforcement_learning.py`][rl] | Done | Included |
| 21.8 | Q-Learning-Agent | `QLearningAgent` | [`reinforcement_learning.py`][rl] | Done | Included |
Expand Down Expand Up @@ -212,18 +215,18 @@ Here is a table of the implemented data structures, the figure, name of the impl
Many thanks for contributions over the years. I got bug reports, corrected code, and other support from Darius Bacon, Phil Ruggera, Peng Shao, Amit Patil, Ted Nienstedt, Jim Martin, Ben Catanzariti, and others. Now that the project is on GitHub, you can see the [contributors](https://github.com/aimacode/aima-python/graphs/contributors) who are doing a great job of actively improving the project. Many thanks to all contributors, especially [@darius](https://github.com/darius), [@SnShine](https://github.com/SnShine), [@reachtarunhere](https://github.com/reachtarunhere), [@antmarakis](https://github.com/antmarakis), [@Chipe1](https://github.com/Chipe1), [@ad71](https://github.com/ad71) and [@MariannaSpyrakou](https://github.com/MariannaSpyrakou).

<!---Reference Links-->
[agents]:../master/agents.py
[csp]:../master/csp.py
[games]:../master/games.py
[agents]:../master/aima/agents.py
[csp]:../master/aima/csp.py
[games]:../master/aima/games.py
[grid]:../master/grid.py
[knowledge]:../master/knowledge.py
[learning]:../master/learning.py
[logic]:../master/logic.py
[mdp]:../master/mdp.py
[nlp]:../master/nlp.py
[planning]:../master/planning.py
[probability]:../master/probability.py
[rl]:../master/reinforcement_learning.py
[search]:../master/search.py
[utils]:../master/utils.py
[text]:../master/text.py
[knowledge]:../master/aima/knowledge.py
[learning]:../master/aima/learning.py
[logic]:../master/aima/logic.py
[mdp]:../master/aima/mdp.py
[nlp]:../master/aima/nlp.py
[planning]:../master/aima/planning.py
[probability]:../master/aima/probability.py
[rl]:../master/aima/reinforcement_learning.py
[search]:../master/aima/search.py
[utils]:../master/aima/utils.py
[text]:../master/aima/text.py
Loading
Loading