Skip to content
Go to file

Latest commit

* Revert "reformulated the map coloring problem"

This reverts commit 20ab0e5.

* Revert "fixed typo errors and removed unnecessary brackets"

This reverts commit f743146.

* Revert "added map coloring SAT problems"

This reverts commit 9e0fa55.

* Revert "removed useless doctest for AC4 in Sudoku because AC4's tests are already present in"

This reverts commit b3cd24c.

* Revert "added doctest in Sudoku for AC4 and and the possibility of choosing the constant propagation algorithm in mac inference"

This reverts commit 6986247.

* Revert "added the mentioned AC4 algorithm for constraint propagation"

This reverts commit 03551fb.

* added map coloring SAT problem

* fixed build error

* Revert "added map coloring SAT problem"

This reverts commit 93af259.

* Revert "fixed build error"

This reverts commit 6641c2c.

* added map coloring SAT problem

* removed redundant parentheses

* added Viterbi algorithm

* added monkey & bananas planning problem

* simplified condition in

* added tests for monkey & bananas planning problem

* removed monkey & bananas planning problem

* Revert "removed monkey & bananas planning problem"

This reverts commit 9d37ae0.

* Revert "added tests for monkey & bananas planning problem"

This reverts commit 24041e9.

* Revert "simplified condition in"

This reverts commit 6d229ce.

* Revert "added monkey & bananas planning problem"

This reverts commit c74933a.

* defined the PlanningProblem as a specialization of a search.Problem & fixed typo errors

* fixed doctest in

* fixed doctest for cascade_distribution

* added ForwardPlanner and tests

* added __lt__ implementation for Expr

* added more tests

* renamed forward planner

* Revert "renamed forward planner"

This reverts commit c4139e5.

* renamed forward planner class & added doc

* added backward planner and tests

* fixed doctests

* removed ignore_delete_lists_heuristic flag

* fixed heuristic for forward and backward planners

* added SATPlan and tests

* fixed ignore delete lists heuristic in forward and backward planners

* fixed backward planner and added tests

* updated doc

* added nary csp definition and examples

* added CSPlan and tests

* fixed CSPlan

* added book's cryptarithmetic puzzle example

* fixed typo errors in test_csp

* fixed #1111

* added sortedcontainers to yml and doc to CSPlan

* added tests for n-ary csp

* fixed utils.extend

* updated

* converted static methods to functions

* added AC3b and AC4 with heuristic and tests

* added conflict-driven clause learning sat solver

* added tests for cdcl and heuristics

* fixed

* fixed import

* fixed kakuro

* added Martelli and Montanari rule-based unification algorithm

* removed duplicate standardize_variables

* renamed variables known as built-in functions

* fixed typos in

* renamed some files and fixed typos

* fixed typos

* fixed typos

* fixed tests

* removed unify_mm

* remove unnecessary brackets

* fixed tests

* moved utility functions to

* fixed typos

* moved utils function to, separated probability learning classes from, fixed typos and fixed imports in .ipynb files

* added missing learners

* fixed Travis build

* fixed typos

* fixed typos

* fixed typos

* fixed typos

* fixed typos in agents files

* fixed imports in agent files

* fixed deep learning .ipynb imports

* fixed typos

* added SVM

* added .ipynb and fixed typos

* adapted code for .ipynb

* fixed typos

* updated .ipynb

* updated .ipynb

* updated

* updated .ipynb

* updated .ipynb

* updated

* updated inf definition

* fixed typos

* fixed typos

* fixed typos

* fixed typos

* Revert "fixed typos"

This reverts commit 658309d.

* Revert "fixed typos"

This reverts commit 08ad660.

* fixed typos

* fixed typos

* fixed typos

* fixed typos

* fixed typos and utils imports in * files

* fixed typos

* fixed typos

* fixed typos

* fixed typos

* fixed import

* fixed typos

* fixed typos

* fixd typos

* fixed typos

* fixed typos

* updated SVM

* added svm test

* fixed SVM and tests

* fixed some definitions and typos

* fixed svm and tests

* added SVMs also in

* fixed inf definition

* fixed .travis.yml

* fixed .travis.yml

* fixed import

* fixed inf definition

* replaced cvxopt with qpsolvers

* replaced cvxopt with quadprog

* fixed some definitions

* fixed typos and removed unnecessary tests

* replaced quadprog with qpsolvers

* fixed extend in utils

* specified error type in try-catch block

* fixed extend in utils

* fixed typos

* fixed

* fixed doctest errors

* added comments

* removed unnecessary if condition

* updated

* fixed imports

* removed unnecessary imports

* fixed keras imports

* fixed typos

* fixed learning_curve

* added comments

* fixed typos

* removed inf and isclose definition from utils and replaced with numpy.inf and numpy.isclose

* fixed doctests

* fixed numpy imports

* fixed superclass call

* removed utils import from 4e py file

* removed unnecessary norm function in utils and fixed Activation definition

* removed unnecessary clip function

* removed unnecessary import and functions from utils

* added tests and fxed some functions

* fixed doc

* fixed typos in gui folder

* removed unnecessary Keras classes and updated pytest.ini

* fixed some details

* readded Keras classes

* fixed import

* fixed some parameters

* removed unnecessary superclass

* fixed neural net

* added LinearLearner, LogisticLearner with tests and fixed NeuralNetLearner and PerceptronLearner

* removed random_weights and substituted with np.random.uniform

* fixed imports

* Revert "fixed imports"

This reverts commit aaf9c7b.

* Revert "removed random_weights and substituted with np.random.uniform"

This reverts commit 70d662b.

* revert

* fixed typo

* fixed .ini and DecisionTreeLearner

* fixed tests

* removed main and fixed AutoencoderLearner

* revert NeuralNetLearner and PerceptronLearner definition

* fixed all tests and removed Learner class

* fixed tests

* fixed tests

* fixed tests

* fixed some function definition

* fixed verbose definition

* fixed tests

* fixed tests

* fixed tests

* updated .travis.yml

* fixed .travis.yml

* fixed .travis.yml

* fixed all tests

* fixed requirements.txt

* fixed .travis.yml

* update .travis.yml

* rollback .travis.yml

* rollback tests

* fixed output layer with softmax as activation function

* updated yml

* updated requirements.txt

* fixed svc

* fixed syntax warns

* fixed syntax warns

* removed 3.8

* added python 3.8 support

* fixed doctests

* fixed spaces and doctest

* added SVR with r2 and accuracy metrics

* fixed imports

* fixed tests

* removed not allowed imports

* fixed

* fixed keras

* fixed

* updated requirements.txt

Git stats


Failed to load latest commit information.
Latest commit message
Commit time

aima-python Build Status Binder

Python code for the book Artificial Intelligence: A Modern Approach. You can use this in conjunction with a course on AI, or for study on your own. We're looking for solid contributors to help.

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 nlp (natural language processing), we provide the following files:

  • Implementations of all the pseudocode algorithms, and necessary support functions/classes/data.
  • tests/ A lightweight test suite, using assert statements, designed for use with py.test, but also usable on their own.
  • nlp.ipynb: A Jupyter (IPython) notebook that explains and gives examples of how to use the code.
  • nlp_apps.ipynb: A Jupyter notebook that gives example applications of the code.

Python 3.5 and up

This code requires Python 3.5 or later, and does not run in Python 2. You can install Python or use a browser-based Python interpreter such as You can run the code in an IDE, or from the command line with python -i where the -i option puts you in an interactive loop where you can run Python functions. All notebooks are available in a binder environment. Alternatively, visit for instructions on setting up your own Jupyter notebook environment.

There is a sibling aima-docker project that shows you how to use docker containers to run more complex problems in more complex software environments.

Installation Guide

To download the repository:

git clone

Then you need to install the basic dependencies to run the project on your system:

cd aima-python
pip install -r requirements.txt

You also need to fetch the datasets from the aima-data repository:

git submodule init
git submodule update

Wait for the datasets to download, it may take a while. Once they are downloaded, you need to install pytest, so that you can run the test suite:

pip install pytest

Then to run the tests:


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 made for the third edition of the book and is being updated for the upcoming fourth edition. Empty implementations are a good place for contributors to look for an issue. The 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 3rd edition) Name (in repository) File Tests Notebook
2 Random-Vacuum-Agent RandomVacuumAgent Done Included
2 Model-Based-Vacuum-Agent ModelBasedVacuumAgent Done Included
2.1 Environment Environment Done Included
2.1 Agent Agent Done Included
2.3 Table-Driven-Vacuum-Agent TableDrivenVacuumAgent Done Included
2.7 Table-Driven-Agent TableDrivenAgent Done Included
2.8 Reflex-Vacuum-Agent ReflexVacuumAgent Done Included
2.10 Simple-Reflex-Agent SimpleReflexAgent Done Included
2.12 Model-Based-Reflex-Agent ReflexAgentWithState Done Included
3 Problem Problem Done Included
3 Node Node Done Included
3 Queue Queue Done No Need
3.1 Simple-Problem-Solving-Agent SimpleProblemSolvingAgent Done Included
3.2 Romania romania Done Included
3.7 Tree-Search depth/breadth_first_tree_search Done Included
3.7 Graph-Search depth/breadth_first_graph_search Done Included
3.11 Breadth-First-Search breadth_first_graph_search Done Included
3.14 Uniform-Cost-Search uniform_cost_search Done Included
3.17 Depth-Limited-Search depth_limited_search Done Included
3.18 Iterative-Deepening-Search iterative_deepening_search Done Included
3.22 Best-First-Search best_first_graph_search Done Included
3.24 A*-Search astar_search Done Included
3.26 Recursive-Best-First-Search recursive_best_first_search Done Included
4.2 Hill-Climbing hill_climbing Done Included
4.5 Simulated-Annealing simulated_annealing Done Included
4.8 Genetic-Algorithm genetic_algorithm Done Included
4.11 And-Or-Graph-Search and_or_graph_search Done Included
4.21 Online-DFS-Agent online_dfs_agent Done Included
4.24 LRTA*-Agent LRTAStarAgent Done Included
5.3 Minimax-Decision minimax_decision Done Included
5.7 Alpha-Beta-Search alphabeta_search Done Included
6 CSP CSP Done Included
6.3 AC-3 AC3 Done Included
6.5 Backtracking-Search backtracking_search Done Included
6.8 Min-Conflicts min_conflicts Done Included
6.11 Tree-CSP-Solver tree_csp_solver Done Included
7 KB KB Done Included
7.1 KB-Agent KB_AgentProgram Done Included
7.7 Propositional Logic Sentence Expr Done Included
7.10 TT-Entails tt_entails Done Included
7.12 PL-Resolution pl_resolution Done Included
7.14 Convert to CNF to_cnf Done Included
7.15 PL-FC-Entails? pl_fc_entails Done Included
7.17 DPLL-Satisfiable? dpll_satisfiable Done Included
7.18 WalkSAT WalkSAT Done Included
7.20 Hybrid-Wumpus-Agent HybridWumpusAgent
7.22 SATPlan SAT_plan Done Included
9 Subst subst Done Included
9.1 Unify unify Done Included
9.3 FOL-FC-Ask fol_fc_ask Done Included
9.6 FOL-BC-Ask fol_bc_ask Done Included
10.1 Air-Cargo-problem air_cargo Done Included
10.2 Spare-Tire-Problem spare_tire Done Included
10.3 Three-Block-Tower three_block_tower Done Included
10.7 Cake-Problem have_cake_and_eat_cake_too Done Included
10.9 Graphplan GraphPlan Done Included
10.13 Partial-Order-Planner PartialOrderPlanner Done Included
11.1 Job-Shop-Problem-With-Resources job_shop_problem Done Included
11.5 Hierarchical-Search hierarchical_search Done Included
11.8 Angelic-Search angelic_search Done Included
11.10 Doubles-tennis double_tennis_problem Done Included
13 Discrete Probability Distribution ProbDist Done Included
13.1 DT-Agent DTAgent Done Included
14.9 Enumeration-Ask enumeration_ask Done Included
14.11 Elimination-Ask elimination_ask Done Included
14.13 Prior-Sample prior_sample Done Included
14.14 Rejection-Sampling rejection_sampling Done Included
14.15 Likelihood-Weighting likelihood_weighting Done Included
14.16 Gibbs-Ask gibbs_ask Done Included
15.4 Forward-Backward forward_backward Done Included
15.6 Fixed-Lag-Smoothing fixed_lag_smoothing Done Included
15.17 Particle-Filtering particle_filtering Done Included
16.9 Information-Gathering-Agent InformationGatheringAgent Done Included
17.4 Value-Iteration value_iteration Done Included
17.7 Policy-Iteration policy_iteration Done Included
17.9 POMDP-Value-Iteration pomdp_value_iteration Done Included
18.5 Decision-Tree-Learning DecisionTreeLearner Done Included
18.8 Cross-Validation cross_validation*
18.11 Decision-List-Learning DecisionListLearner*
18.24 Back-Prop-Learning BackPropagationLearner Done Included
18.34 AdaBoost AdaBoost Done Included
19.2 Current-Best-Learning current_best_learning Done Included
19.3 Version-Space-Learning version_space_learning Done Included
19.8 Minimal-Consistent-Det minimal_consistent_det Done Included
19.12 FOIL FOIL_container Done Included
21.2 Passive-ADP-Agent PassiveADPAgent Done Included
21.4 Passive-TD-Agent PassiveTDAgent Done Included
21.8 Q-Learning-Agent QLearningAgent Done Included
22.1 HITS HITS Done Included
23 Chart-Parse Chart Done Included
23.5 CYK-Parse CYK_parse Done Included
25.9 Monte-Carlo-Localization monte_carlo_localization Done Included

Index of data structures

Here is a table of the implemented data structures, the figure, name of the implementation in the repository, and the file where they are implemented.

Figure Name (in repository) File
3.2 romania_map
4.9 vacumm_world
4.23 one_dim_state_space
6.1 australia_map
7.13 wumpus_world_inference
7.16 horn_clauses_KB
17.1 sequential_decision_environment
18.2 waiting_decision_tree


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 who are doing a great job of actively improving the project. Many thanks to all contributors, especially @darius, @SnShine, @reachtarunhere, @antmarakis, @Chipe1, @ad71 and @MariannaSpyrakou.


Python implementation of algorithms from Russell And Norvig's "Artificial Intelligence - A Modern Approach"




No releases published
You can’t perform that action at this time.