AIMA Python Code

This file gives an overview of the Python code for the algorithms in the textbook AI: A Modern Approach. The code is Copyright (c) 2002 by Peter Norvig and is offered free of charge for your use. As you may know, the textbook presents algorithms in pseudo-code format; as a supplement we provide this Python code as well as Lisp code. The intent is to implement all the algorithms in both languages, so that you can choose whichever language you prefer. As yet neither implementation is complete, but the Lisp version is closer.

Installation Instructions

Here is how to download the files and make them ready for use. You only need to do this once, and if you are taking a course, your instructor may have set this up for you.
  1. Download the file aima-python.zip
  2. Unzip it. Your browser may do this automatically, or you can give the command "unzip aima-python.zip" or drag the file to your zip program icon.
  3. You must have Python (version 2.2 or later) installed. If you don't have it yet, you can download it.
  4. Make sure the files are in your module search path. You do this either by always starting Python from the directory where you keep the files, or by editing the environment variable PYTHONPATH.

User's Guide

Once you have the files installed, you can use them in several ways.

Code File Summary

The following table lists the code files (modules), the chapters in the book to which they refer, the number of lines of code in each file, and a brief description of each file. You can also browse through the directory norvig.com/python/ to see all the files, or look at the example output log and link from there to the files.

ChapterModuleLinesDescription
1-2agents485Implement Agents and Environments (Chapters 1-2).
3-4search470Search (Chapters 3-4)
5csp435CSP (Constraint Satisfaction Problems) problems and solvers. (Chapter 5).
6games285Games, or Adversarial Search. (Chapters 6)
7,9logic335Representations and Inference for Logic (Chapters 7,9)
18-21learning579Learn to estimate functions from examples. (Chapters 18-21)
22nlp155A chart parser and some grammars. (Chapter 22)
23text137Statistical Language Processing tools. Not all working yet. (Chapter 23)
 docex205A framework for running unit test examples, written in docstrings.
 py2html126Pretty-print Python code to colorized, hyperlinked html.
 utils604Provide some widely useful utilities. Safe for "from utils import *".
3816

Developer's Guide

If you'd like to contribute to this project, we could really use the help. Read the guidelines and then let me know what you'd like to contribute.
Peter Norvig