$ show aimacode/aima-python
This repository is the official Python implementation of the algorithms from the textbook *Artificial Intelligence: A Modern Approach* (AIMA) by Russell and Norvig. It is primarily an educational library, providing clean, well-documented reference implementations of classic AI algorithms. The code is organized as a monolithic Python package (`aima/`) with modules corresponding to major AI subfields (search, logic, probability, learning, NLP, planning, agents, etc.), complemented by an extensive set of Jupyter notebooks that serve as interactive tutorials and a JupyterLite deployment for browser-based execution. The architecture emphasizes clarity and adherence to textbook pseudocode over production performance. The library demonstrates high craftsmanship in its core abstractions. The `Problem`/`Node` search framework, the `Expr` symbolic logic engine, the `BayesNet` probabilistic inference system, and the `CSP` constraint satisfaction framework are all well-isolated, reusable components that could be extracted for other projects. The code is extensively tested with pytest and actively maintained, with a very low open issue count relative to its popularity. While the core library is robust and written in pure Python with minimal dependencies, some modules (particularly `deep_learning.py` and `perception.py`) rely on heavy external libraries like TensorFlow/Keras and OpenCV, which have experienced significant API drift over time. The educational focus means the code prioritizes readability and algorithmic correctness over scalability or performance optimization. Overall, it is an invaluable resource for learning AI and a solid foundation for building educational tools and demonstrations.
The LLM identified 8 files worth highlighting for reuse:
Provides foundational data structures (`PriorityQueue`, `Expr`) and utility functions (`memoize`, `distance`, `normalize`) used across all other modules. The `Expr` class is a cleverly designed symbolic expression handler that underpins the logic and planning modules. Highly reusable in any Python project needing symbolic computation or priority queues.
Defines the classic `Problem` and `Node` abstractions for state-space search. Implements a wide range of search algorithms (BFS, DFS, A*, IDA*, RBFS, hill climbing, simulated annealing, genetic algorithms). The clean separation of problem definition from search strategy makes it an excellent template for solving any search problem.
Implements propositional and first-order logic knowledge bases, a powerful `Expr` system for symbolic manipulation, unification algorithms (`unify`, `unify_mm`), and SAT solvers (DPLL, CDCL, WalkSAT). The CDCL solver with watched literals and VSIDS heuristic is a particularly impressive implementation of a modern SAT algorithm.
Provides a generic `CSP` class and a suite of algorithms for solving constraint satisfaction problems, including `backtracking_search` with various heuristics (MRV, LCV) and inference (forward checking, MAC), as well as arc consistency algorithms (AC3, AC4). Includes built-in problem definitions (N-Queens, Sudoku, Zebra, Crossword, Kakuro).
Implements a full Bayesian network framework (`BayesNet`, `BayesNode`) with exact inference (`enumeration_ask`, `elimination_ask`) and approximate inference (rejection sampling, likelihood weighting, Gibbs sampling). Also includes Hidden Markov Models, Kalman Filters, and Dynamic Bayesian Networks. The BIF parser (`read_bif`) allows loading standard network files.
Provides a `DataSet` class for managing ML datasets and implements a variety of learners (Decision Trees, k-NN, Naive Bayes, Neural Networks, SVMs, Ensemble methods like AdaBoost and Random Forest). The `DataSet` class handles loading, splitting, and cross-validation, making it a solid foundation for educational ML experiments.
Implements a comprehensive NLP framework including grammar definitions (`Grammar`, `ProbGrammar`), chart parsing (`Chart`, `CYK_parse`), and web search ranking (`HITS`). The CYK parser is a clean implementation of a classic algorithm, and the grammar DSL is intuitive.
Defines the foundational `Agent`, `Environment`, and `Thing` classes that form the core abstraction of the AIMA textbook. Implements various agent programs (reflex, model-based, goal-based, utility-based) and environments (vacuum, Wumpus). This framework is the entry point for understanding the agent-centric view of AI.