Skip to content
プロジェクト

概要

RussellとNorvigの『Artificial Intelligence: A Modern Approach』に登場するアルゴリズムのPython実装

AI・機械学習

この数値の測り方

計測したスター増加

24時間
+1
7日間
+8
15日間
+19
1か月
+29

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

aima-python tests license docs Binder lite-badge

Python code for the book Artificial Intelligence: A Modern Approach.

Installation

The code targets the 4th edition of the book and runs on Python 3.11 and up; the CI runs the tests on 3.11 and 3.12, since some optional dependencies (tensorflow, keras, opencv-python) do not yet ship wheels for 3.13+. Clone the repository together with the aima-data submodule (the datasets), install the package aima and its dependencies, and run the tests:

git clone --recurse-submodules https://github.com/aimacode/aima-python.git
cd aima-python
pip install -e .
pip install pytest
pytest

In an existing clone, git submodule update --init fetches the datasets. The algorithms are then imported from the package, e.g., from aima.search import astar_search, and python -i -m aima.search opens an interactive session on one module. A couple of notebooks also need the Graphviz binary dot (e.g., apt install graphviz or brew install graphviz), since the graphviz package on PyPI is only a wrapper.

Notebooks

The folder notebooks/ holds the Jupyter notebooks that explain and demonstrate the code, one per topic plus the per-chapter demos in notebooks/chapterNN/; each starts with %run bootstrap.ipynb, which puts the repository root on sys.path. Each notebook has a jupytext .py mirror, regenerated by the workflow notebooks-to-py.yml (see CONTRIBUTING.md). The notebooks also run in Binder, and those of most chapters run in the browser, with no installation, through JupyterLite (see lite/README.md).

Index of algorithms

The table has one row per algorithm, in the order of the book, and the same rows in all the aimacode repositories. The column Figure gives the figure of the 4th edition or, followed by "(3e)", the one of the 3rd edition when the pseudocode of the algorithm is only there; § gives the section of the 4th edition of an algorithm described in the text, and — marks an algorithm that is not in the book. The names link to the pseudocode in aima-pseudocode.

Figure Name (in 4th edition) Code Tests
2.7 TABLE-DRIVEN-AGENT TableDrivenAgentProgram test_agents.py
2.8 REFLEX-VACUUM-AGENT ReflexVacuumAgent test_agents.py
2.10 SIMPLE-REFLEX-AGENT SimpleReflexAgentProgram test_agents.py
2.12 MODEL-BASED-REFLEX-AGENT ModelBasedReflexAgentProgram test_agents.py
§2.1 Table-Driven-Vacuum-Agent TableDrivenVacuumAgent test_agents.py
§2.4.2 Random-Agent-Program RandomAgentProgram test_agents.py
§2.4.2 Random-Vacuum-Agent RandomVacuumAgent test_agents.py
§2.4.3 Model-Based-Vacuum-Agent ModelBasedVacuumAgent test_agents.py
— Environment-Simulator Environment.run test_agents.py
3.7 BEST-FIRST-SEARCH best_first_graph_search test_search.py
3.9 BREADTH-FIRST-SEARCH breadth_first_graph_search test_search.py
3.9 UNIFORM-COST-SEARCH uniform_cost_search test_search.py
3.12 DEPTH-LIMITED-SEARCH depth_limited_search test_search.py
3.12 ITERATIVE-DEEPENING-SEARCH iterative_deepening_search test_search.py
3.14 BIBF-SEARCH bidirectional_search test_search.py
3.22 RECURSIVE-BEST-FIRST-SEARCH recursive_best_first_search test_search.py
3.1 (3e) SIMPLE-PROBLEM-SOLVING-AGENT SimpleProblemSolvingAgentProgram test_search.py
3.7 (3e) TREE-SEARCH breadth_first_tree_search, depth_first_tree_search test_search.py
3.7 (3e) GRAPH-SEARCH breadth_first_graph_search, depth_first_graph_search test_search.py
§3.1 Romania romania_map test_search.py
§3.2.1 Eight-Puzzle EightPuzzle test_search.py
§3.2.1 N-Queens-Problem NQueensProblem test_search.py
§3.2.2 Traveling-Salesman-Problem TravelingSalesman test_search.py
§3.4.3 Depth-First-Search depth_first_graph_search test_search.py
§3.4.5 Bidirectional-Search bidirectional_breadth_first_search test_search.py
§3.5.1 Greedy-Best-First-Search greedy_best_first_graph_search test_search.py
§3.5.2 A*-Search astar_search test_search.py
§3.5.5 SMA* sma_star_search test_search.py
§3.5.5 Iterative-Deepening-A*-Search iterative_deepening_astar_search test_search.py
— Pour-Problem PourProblem test_search.py
— Grid-Problem GridProblem test_search.py
4.2 HILL-CLIMBING hill_climbing test_search.py
4.4 SIMULATED-ANNEALING simulated_annealing test_search.py
4.7 GENETIC-ALGORITHM genetic_algorithm test_search.py
4.10 AND-OR-GRAPH-SEARCH and_or_graph_search test_search.py
4.20 ONLINE-DFS-AGENT OnlineDFSAgent test_search.py
4.23 LRTA*-AGENT LRTAStarAgent test_search.py
§4.1.1 Stochastic-Hill-Climbing stochastic_hill_climbing test_search.py
§4.1.1 First-Choice-Hill-Climbing first_choice_hill_climbing test_search.py
§4.1.1 Random-Restart-Hill-Climbing random_restart_hill_climbing test_search.py
§4.1.3 Local-Beam-Search local_beam_search test_search.py
§4.3.1 Erratic-Vacuum-World vacuum_world test_search.py
§4.5.1 Online-Search-Problem OnlineSearchProblem test_search.py
§4.5.3 One-Dimensional-State-Space one_dim_state_space test_search.py
— Peak-Finding-Problem PeakFindingProblem test_search.py
5.3 MINIMAX-SEARCH minmax_decision test_games.py
5.7 ALPHA-BETA-SEARCH alpha_beta_search test_games.py
5.11 MONTE-CARLO-TREE-SEARCH monte_carlo_tree_search test_games.py
§5.3.2 Alpha-Beta-Cutoff-Search alpha_beta_cutoff_search test_games.py
§5.3.2 Iterative-Deepening-Alpha-Beta iterative_deepening_alpha_beta_search test_games.py
§5.5 Expectiminimax expect_minmax test_games.py
— Random-Player random_player test_games.py
— Play-Game Game.play_game test_games.py
— Tic-Tac-Toe TicTacToe test_games.py
6.3 AC-3 AC3 test_csp.py
6.5 BACKTRACKING-SEARCH backtracking_search test_csp.py
6.9 MIN-CONFLICTS min_conflicts test_csp.py
6.11 TREE-CSP-SOLVER tree_csp_solver test_csp.py
§6.1.1 Map-Coloring-CSP MapColoringCSP test_csp.py
§6.1.3 Cryptarithmetic two_two_four, send_more_money test_csp.py
§6.2.6 Sudoku Sudoku test_csp.py
§6.3.1 Variable-And-Value-Ordering mrv, lcv test_csp.py
§6.3.2 Forward-Checking forward_checking test_csp.py
§6.3.2 Maintaining-Arc-Consistency mac test_csp.py
§6.4 N-Queens-CSP NQueensCSP test_csp.py
§6 Zebra Zebra test_csp.py
— AC-3b AC3b test_csp.py
— AC-4 AC4 test_csp.py
— Arc-Heuristics no_arc_heuristic, dom_j_up test_csp.py
— N-ary-CSP NaryCSP, Constraint test_csp.py
— GAC-Domain-Splitting ACSolver test_csp.py
— AC-Search-Solver ACSearchSolver test_csp.py
— GAC-Heuristics no_heuristic, sat_up test_csp.py
— Crossword Crossword test_csp.py
— Kakuro Kakuro test_csp.py
7.1 KB-AGENT KBAgentProgram test_logic.py
7.10 TT-ENTAILS tt_entails test_logic.py
7.13 PL-RESOLUTION pl_resolution test_logic.py
7.15 PL-FC-ENTAILS? pl_fc_entails test_logic.py
7.17 DPLL-SATISFIABLE? dpll_satisfiable test_logic.py
7.18 WALKSAT WalkSAT test_logic.py
7.20 HYBRID-WUMPUS-AGENT HybridWumpusAgent test_logic.py
7.22 SATPLAN SAT_plan test_logic.py
§7.5.2 Convert-to-CNF to_cnf test_logic.py
— DPLL-Branching-Heuristics moms, momsf, posit, zm, dlis, dlcs, jw, jw2 test_logic.py
— CDCL cdcl_satisfiable test_logic.py
— Restart-Strategies no_restart, luby, glucose test_logic.py
— Map-Coloring-SAT MapColoringSAT test_logic.py
9.1 UNIFY unify test_logic.py
9.3 FOL-FC-ASK fol_fc_ask test_logic.py
9.6 FOL-BC-ASK fol_bc_ask test_logic.py
9.8 APPEND append test_knowledge.py
§9.1 Subst subst test_logic.py
§9.5.1 Convert-to-CNF-FOL fol_to_cnf test_logic.py
§9.5.2 FOL-Resolution fol_resolution test_logic.py
§9.5.5 Demodulation demodulate test_logic.py
§9.5.5 Paramodulation paramodulate test_logic.py
§9.5.6 Subsumption subsumes test_logic.py
— Unify-MM unify_mm test_logic.py
— Symbolic-Differentiation diff, simp, d test_logic.py
11.1 AIR-CARGO-TRANSPORT-PROBLEM air_cargo test_planning.py
11.2 SPARE-TIRE-PROBLEM spare_tire test_planning.py
11.4 BLOCKS-WORLD blocks_world test_graphplan.py
11.7 REFINEMENT-HIGH-LEVEL-ACTIONS RealWorldPlanningProblem.refinements test_planning.py
11.8 HIERARCHICAL-SEARCH RealWorldPlanningProblem.hierarchical_search test_planning.py
11.11 ANGELIC-SEARCH RealWorldPlanningProblem.angelic_search test_planning.py
11.13 JOB-SHOP-SCHEDULING-PROBLEM job_shop_problem test_planning.py
10.7 (3e) HAVE-CAKE-AND-EAT-CAKE-TOO-PROBLEM have_cake_and_eat_cake_too test_planning.py
10.9 (3e) GRAPHPLAN GraphPlan test_graphplan.py
§11.1.3 Three-Block-Tower three_block_tower test_planning.py
§11.2.1 Forward-State-Space-Search ForwardPlan test_planning.py
§11.2.2 Backward-State-Space-Search BackwardPlan test_planning.py
§11.2.4 Partial-Order-Planner PartialOrderPlanner test_planning.py
§11.3 Planning-Heuristics ForwardPlan.h test_knowledge.py
§11 Planning-Graph Graph test_perception.py
— SATPlan-Planning SATPlan test_planning.py
— CSPlan CSPlan test_planning.py
— Linearize Linearize test_planning.py
12.1 DT-AGENT DTAgentProgram test_probability.py
§12.3 Enumerate-Joint-Ask enumerate_joint_ask test_probability.py
13.11 ENUMERATION-ASK enumeration_ask test_probability.py
13.13 ELIMINATION-ASK elimination_ask test_probability.py
13.16 PRIOR-SAMPLE prior_sample test_probability.py
13.17 REJECTION-SAMPLING rejection_sampling test_probability.py
13.18 LIKELIHOOD-WEIGHTING likelihood_weighting test_probability.py
13.20 GIBBS-ASK gibbs_ask test_probability.py
§13.2.3 Hybrid-Bayesian-Network ContinuousBayesNode test_probability.py
— Read-BIF read_bif test_probability.py
14.4 FORWARD-BACKWARD forward_backward test_probability.py
14.6 FIXED-LAG-SMOOTHING fixed_lag_smoothing test_probability.py
14.17 PARTICLE-FILTERING particle_filtering test_probability.py
§14.2.3 Viterbi viterbi test_probability.py
§14.4 Kalman-Filter kalman_filter, KalmanFilter test_probability.py
§14.5.3 DBN-Unrolling DynamicBayesNet.unroll test_probability.py
15.5 OUPM generate_citation_world test_probabilistic_programming.py
15.6 NET-VISA generate_seismic_world test_probabilistic_programming.py
15.9 RADAR generate_radar_world test_probabilistic_programming.py
15.11 GENERATE-IMAGE generate_image test_probabilistic_programming.py
15.15 GENERATE-MARKOV-LETTERS generate_markov_letters test_probabilistic_programming.py
16.9 INFORMATION-GATHERING-AGENT InformationGatheringAgent test_probability.py
§16.5 Decision-Network DecisionNetwork test_probability.py
17.6 VALUE-ITERATION value_iteration test_mdp.py
17.9 POLICY-ITERATION policy_iteration test_mdp.py
17.16 POMDP-VALUE-ITERATION pomdp_value_iteration test_mdp.py
§17.1 Sequential-Decision-Environment sequential_decision_environment test_reinforcement_learning.py
§17.2.2 Policy-Evaluation policy_evaluation test_mdp.py
§17.5.2 Dynamic-Decision-Network pomdp_lookahead test_mdp.py
18.1 DOUBLES-TENNIS-PROBLEM double_tennis_problem test_planning.py
§18.2.1 Dominant-Strategy dominant_strategy test_game_theory.py
§18.2.1 Iterated-Dominance iterated_dominance test_game_theory.py
§18.2.1 Pure-Nash-Equilibria pure_nash_equilibria test_game_theory.py
§18.2.1 Zero-Sum-Game solve_zero_sum_game test_game_theory.py
§18.3.2 Shapley-Value shapley_value test_game_theory.py
§18.3.2 Core is_in_core test_game_theory.py
§18.4.1 Contract-Net-Protocol contract_net test_game_theory.py
§18.4.2 Vickrey-Auction vickrey_auction test_game_theory.py
§18.4.3 Voting plurality_winner, borda_winner, condorcet_winner test_game_theory.py
§18.4.4 Alternating-Offers-Bargaining alternating_offers_bargaining test_game_theory.py
19.5 LEARN-DECISION-TREE DecisionTreeLearner test_learning.py
19.8 MODEL-SELECTION cross_validation_wrapper test_learning.py
19.11 DECISION-LIST-LEARNING DecisionListLearner test_learning.py
19.25 ADABOOST ada_boost test_learning.py
19.2 (3e) CURRENT-BEST-LEARNING current_best_learning test_knowledge.py
19.3 (3e) VERSION-SPACE-LEARNING version_space_learning test_knowledge.py
19.8 (3e) MINIMAL-CONSISTENT-DET minimal_consistent_det test_knowledge.py
19.12 (3e) FOIL FOILContainer test_knowledge.py
§19.2.1 Restaurant-Data RestaurantDataSet test_learning.py
§19.6.1 Linear-Regression LinearLearner test_learning.py
§19.6.4 Perceptron-Learning PerceptronLearner test_deep_learning.py
§19.6.5 Logistic-Regression LogisticLinearLearner test_learning.py
§19.7.1 K-Nearest-Neighbors NearestNeighborLearner test_learning.py
§19.7.5 Support-Vector-Machine SVC test_learning.py
§19.8 Ensemble-Learning EnsembleLearner test_learning.py
§19.8.2 Random-Forest RandomForest test_learning.py
§19.8.6 Weighted-Majority weighted_majority test_learning.py
§19 Learning-Curve learning_curve test_learning.py
— Support-Vector-Regression SVR test_learning.py
— Weighted-Replicate weighted_replicate test_learning.py
§20.2.2 Naive-Bayes NaiveBayesLearner test_probabilistic_learning.py
§20.3.1 EM-Gaussian-Mixture gaussian_mixture_em test_learning.py
§20.3.2 EM-Bayes-Net-Hidden-Variable naive_bayes_em test_learning.py
§20.3.3 Baum-Welch baum_welch test_probability.py
— Gaussian-Naive-Bayes NaiveBayesContinuous test_probabilistic_learning.py
18.24 (3e) BACK-PROP-LEARNING BackPropagationLearner test_learning.py
§21.1 Dense-Network NeuralNetworkLearner test_deep_learning.py
§21.3 Convolution-Pooling-Batch-Normalization ConvLayer1D, MaxPoolingLayer1D, BatchNormalizationLayer test_deep_learning.py
§21.4 Stochastic-Gradient-Descent stochastic_gradient_descent test_deep_learning.py
§21.4 Adam-Optimizer adam test_deep_learning.py
§21.6 Recurrent-Neural-Network SimpleRNNLearner test_deep_learning.py
§21.7.1 Autoencoder AutoencoderLearner test_deep_learning.py
22.2 PASSIVE-ADP-AGENT PassiveADPAgent test_reinforcement_learning.py
22.4 PASSIVE-TD-AGENT PassiveTDAgent test_reinforcement_learning.py
22.8 Q-LEARNING-AGENT QLearningAgent test_reinforcement_learning.py
§22.2.1 Direct-Utility-Estimation PassiveDUEAgent test_reinforcement_learning.py
§22.3.1 Exploratory-ADP-Agent ExploratoryADPAgent test_reinforcement_learning.py
§22.3.3 SARSA-Agent SARSALearningAgent test_reinforcement_learning.py
23.5 CYK-PARSE CYK_parse test_nlp.py
23.8 SENTENCE-TREE sentence_tree test_nlp.py
22.1 (3e) HITS HITS test_nlp.py
§23.1 Viterbi-Segmentation viterbi_segment test_text.py
§23.1.2 N-Gram-Models NgramWordModel test_text.py
§23.1.3 N-Gram-Char-Model NgramCharModel test_text.py
§23.3 Chart-Parse Chart test_nlp.py
§23.3 Parsing-As-Search astar_search_parsing, beam_search_parsing test_nlp.py
§23 IR-System IRSystem test_text.py
— Shift-Decoder ShiftDecoder test_text.py
— Permutation-Decoder PermutationDecoder test_text.py
§25.3.1 Edge-Detection gradient_edge_detector, gaussian_derivative_edge_detector, laplacian_edge_detector test_perception.py
§25.3.3 Optical-Flow sum_squared_difference test_perception.py
§25.3.4 Segmentation probability_contour_detection, group_contour_detection, image_to_graph test_perception.py
§25.5 ROI-Pooling pool_rois test_perception.py
§25 Histogram-Of-Oriented-Gradients hog test_perception.py
26.6 MONTE-CARLO-LOCALIZATION monte_carlo_localization test_probability.py
29.1 (3e) POWERS-OF-2 powers_of_2 test_utils.py

Data structures

Figure Name (in 4th edition) Code Tests
§2 Agent Agent test_agents.py
§2 Environment Environment test_agents.py
§2 XY-Environment XYEnvironment test_agents.py
§2 Vacuum-World TrivialVacuumEnvironment, VacuumEnvironment test_agents.py
§3 Problem Problem test_search.py
§3 Node Node test_search.py
§3 Queue PriorityQueue test_utils.py
§5 Stochastic-Game StochasticGame test_games.py
§5 Game Game test_games.py
§6 CSP CSP test_csp.py
§7 Wumpus-World WumpusEnvironment test_agents.py
§7 KB KB test_logic.py
§7 Propositional-Logic-Sentence Expr test_utils.py
§11 Planning-Problem PlanningProblem test_graphplan.py
§12 Probability-Distribution ProbDist test_probability.py
§13 Bayesian-Network BayesNet test_probability.py
§14 Hidden-Markov-Model HiddenMarkovModel test_probability.py
§14 Dynamic-Bayesian-Network DynamicBayesNet test_probability.py
§17 Markov-Decision-Process MDP test_mdp.py
§19 Data-Set DataSet test_learning.py
§20 Counting-Probability-Distribution CountingProbDist test_probabilistic_learning.py
§23 Grammar Grammar test_nlp.py
§23 Probabilistic-Grammar ProbGrammar test_nlp.py

Exercises

This table lists the exercises of aima-exercises whose answer a program can check, with the same tests in all the repositories; the chapters are those of the 3rd edition, as on that site.

Chapter Exercises Tests
2. Intelligent Agents 2, 11, 12, 13, 14, 15 test_exercises_ch02.py
3. Solving Problems by Searching 2, 3, 4, 5, 6, 7, 8, 9, 11, 17, 18, 19, 20, 21, 22, 24, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 test_exercises_ch03.py
4. Beyond Classical Search 1, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16 test_exercises_ch04.py
5. Adversarial Search 2, 3, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20 test_exercises_ch05.py
6. Constraint Satisfaction Problems 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 14, 15, 16, 19, 20 test_exercises_ch06.py
7. Logical Agents 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35 test_exercises_ch07.py
8. First-Order Logic 6, 13, 17, 18, 33, 34 test_exercises_ch08.py
9. Inference in First-Order Logic 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29 test_exercises_ch09.py
10. Classical Planning 1, 3, 4, 5, 8, 10, 11, 16, 18 test_exercises_ch10.py
11. Planning and Acting in the Real World 3, 5, 7, 9, 10, 14, 15 test_exercises_ch11.py
12. Knowledge Representation 15, 16, 22, 28, 29 test_exercises_ch12.py
13. Quantifying Uncertainty 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 22, 23, 25, 26, 27, 28, 29, 30, 31 test_exercises_ch13.py
14. Probabilistic Reasoning 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24 test_exercises_ch14.py
15. Probabilistic Reasoning over Time 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 20 test_exercises_ch15.py
16. Making Simple Decisions 1, 2, 3, 4, 6, 7, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 test_exercises_ch16.py
17. Making Complex Decisions 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 25 test_exercises_ch17.py
18. Learning from Examples 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 test_exercises_ch18.py
19. Knowledge in Learning 1, 5, 7, 8 test_exercises_ch19.py
20. Learning Probabilistic Models 1, 2, 3, 5, 6, 8, 10, 11 test_exercises_ch20.py
21. Reinforcement Learning 1, 3, 6, 7, 9, 10, 11 test_exercises_ch21.py
22. Natural Language Processing 1, 2, 3, 4, 5 test_exercises_ch22.py
23. Natural Language for Communication 2, 3, 4, 6, 7, 10, 11, 12, 13, 14, 15, 19, 20, 21 test_exercises_ch23.py
24. Perception 5, 8 test_exercises_ch24.py
25. Robotics 1, 2, 4, 5, 7, 9, 10 test_exercises_ch25.py

Other code in this repository

Name Code Tests
Australia map australia_map test_search.py
Wumpus world KB wumpus_world_inference test_logic.py
Horn clauses KB horn_clauses_KB test_logic.py

Contributing

See CONTRIBUTING.md.

Authors

In order of the lines they wrote in the current files: Donato Meoli, Aman Deep Singh, Antonis Maronikolakis, Tianqi Yang, Marianna Spyrakou, Tarun Kumar Vangani, Peter Norvig, C.G. Vedant, Nouman Ahmed, Apurv Bajaj, Surya Teja Cheedella; see also all the contributors.

I also thank, for their earlier contributions, Darius Bacon, Lucas Moura, Mirco Tracolli, Phil Ruggera, Peng Shao, Amit Patil, Ted Nienstedt, Jim Martin and Ben Catanzariti.

Other aimacode projects

aima-java · aima-csharp · aima-scala · aima-julia · aima-lisp · aima-javascript · aima-pseudocode · aima-exercises · aima-data · aima-glossary

関連プロジェクトを探す

読み込み中…