Skip to main content

An implementation of AI algorithms based on aima-python

Project description

Simple AI

Project home: http://github.com/fisadev/simpleai

This lib implements many of the artificial intelligence algorithms described on the book “Artificial Ingelligence, a Modern Approach”, from Stuart Russel and Peter Norvig. We strongly recommend you to read the book, or at least the introductory chapters and the ones related to the components you want to use, because we won’t explain the algorithms here.

This implementation takes some of the ideas from the Norvig’s implementation (the aima-python <https://code.google.com/p/aima-python/> lib), but it’s made with a more “pythonic” approach, and more enphasis on creating a stable, modern, and mantenible version. We are testing the majority of the lib, it’s available via pip install, has a standar repo and lib architecture, well documented, respects the python pep8 guidelines, provides only working code (no placeholders for future things), etc. Even the internal code is written with readability in mind, not only the external API.

At this moment, the implementation includes:

  • Search algorithms (not informed and informed)

  • Local Search algorithms

  • Constraint Satisfaction Problems algorithms

Installation

Just get it:

pip install simpleai

Examples

Simple AI allows you to define problems and look for the solution with different strategies. Another samples are in the samples directory, but here is an easy one.

This problem tries to create the string “HELLO WORLD” using the A* algorithm:

from simpleai.models import Problem
from simpleai.search import astar

GOAL = 'HELLO WORLD'

class HelloProblem(Problem):
    def actions(self, state):
        if len(state) < len(GOAL):
            return [c for c in ' ABCDEFGHIJKLMNOPQRSTUVWXYZ']
        else:
            return []

    def result(self, state, action):
        return state + action

    def is_goal(self, state):
        return state == GOAL

    def heuristic(self, state):
        # how far are we from the goal?
        wrong = sum([1 if state[i] != GOAL[i] else 0
                    for i in range(len(state))])
        missing = len(GOAL) - len(state)
        return wrong + missing


problem = HelloProblem(initial_state='')
result = astar(problem)

print result.state
print result.path()

More detailed documentation

You can read the docs online here. Or for offline access, you can clone the project code repository and read them from the docs folder.

Authors

Special acknowledgements to Machinalis for the time provided to work on this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpleai-0.3.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file simpleai-0.3.tar.gz.

File metadata

  • Download URL: simpleai-0.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for simpleai-0.3.tar.gz
Algorithm Hash digest
SHA256 352661d2a2638eb660f483e1b9b58e401a95e8e5c2abd247ff4bfbdfba82668c
MD5 3028c48ac81f07177c82472a287f8bea
BLAKE2b-256 18faf224600fdbc05f25954cf74a3c0d422015ec24d66dfd8f88fc662b2eae9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page