AI library

Felix Benner felix.benner at imail.de
Fri Dec 15 06:50:58 EST 2006


I thought about an AI library for python. This is the possible 
structure I came up with. Are there any thoughts about it?

ailib/

    search.py

        class State:
            "represents an immutable state of a problem"
            def __str__(self):
                pass

            def __hash__(self):
                pass

        class StateSpace:
            "represents a traversable collection of states"
            def start(self):
                "returns a list of initial states"
                pass

            def follow(self, state).
                "returns a list of states that follow after state"
                pass

            def search(self, order=none):
                """returns an iterator over all states according to 
order
                order can be a constant (depth, breadth, incdepth) or 
a
                heuristic. If none some default search will be 
used."""
                pass

            def __iter__(self):
                return self.search()

        class Heuristic:
            def follow(self, state):
                "returns a list of states probably closer to the 
solution than s
                pass

        class Graph(StateSpace):
            def __init__(self, paths)
                "paths is a set of tuples (nodeFrom, nodeTo, weight)"
                pass

            def a-star(self, nodeFrom, nodeTo):
                """searches the shortest path (minimal weight) from
                nodeFrom to nodeTo."""
                pass

    plan.py

        class State(search.State):
            "represents a state of the world that can be changed 
through action.
            pass

        class Agent(search.StateSpace):
            """For any given state an Agent has a set of possible 
actions
            that transform the initial state into a subsequent 
state."""

            def perceive(self):
                "returns the state of the world the agent perceives to 
be in."
                pass

            def actions(self, state):
                "returns an iterator over actions available in the 
given state."
                pass

            def __iter__(self):
                return self.actions(self.perceive())

            def plan(self, state, currentState=none):
                """returns a sequence of actions that are supposed to
                transform the currently perceived state of the world
                into the desired state."""
                if currentState==none:
                    currentState = self.perceive()
                else:
                    pass

    logic.py

        class Symbol:
            "a Symbol that can be bound to a value or unbound."
            def bound(self):
                "returns true if the symbol is bound."

            def value(self):
                "if bound returns the value."

        class Function:
            "transforms a list of symbols into another symbol."
            def __init__(self, *symbols):
                self.symbols = symbols

            def __call__(self):
                "returns some symbol."
                pass

        class Predicate:
            "either is or is not valid for a given list of symbols"
            def __init__(self, *symbols):
                self.symbols = symbols

            def __call__(self):
                "returns true or false"
                pass

        class Junctor:
            """a relation between predicates deriving a truth value 
from the
            truth values of the predicates"""
            def __init__(self, *predicates):
                self.predicates = predicates

            def __call__(self):
                "returns some truth value"
                pass

        class Quantifier:
            "somehow binds symbols."
            pass

        class Clause:
            "A quantified junctor."
            pass

        class Axioms:
            "A list of clauses"
            def consistent(self):
                "returns true if the list of axioms is consistent"
                pass

            def valid(self, clause, bind=true):
                """returns true if the clause is consistent with the 
set of axio
                If bind is true, any unbound symbol will be bound to a 
value if
                pass

    statistics.py

        class Entity:
            "bearer of statistically relevant features."
            pass

        class Set:
            "set of entities. defines usual statistical functions"
            def __iter__(self):
                "iterate over all entities."

            def avg(self, feature):
                "returns the average of the given feature of all 
entities."
                pass
            # likewise other functions

            def entropy(self, a, b):
                "returns the level of randomnes (0..1) between the 
given feature
                pass

            def correlates(self, a, b, e=0.5):
                return self.entropy(a, b) < e

            def mine(self):
                "returns the tuple of features with the least 
entropy."

    game.py

        class Game:
            """Basically extends planning with multiple agents who
            take turns."""
            pass

    language.py

        class Morphology:
            "word recognition."
            def lookup(self, word, guess=false):
                """returns a list of dictionaries of features for the 
given word
                If guess is true, tries to guess features if 
unsure."""

        class Rule:
            "a Rule of the language like S -> np, vp. Can have a 
probability."
            pass

        class Language:
            "A set of rules."

            def parse(self, sentence):
                """tries to parse the sentence according to the rules.
                returns an iterator over possible parse trees which 
are
                tuples (category, content). If rules have probability
                the iterator returns tuples (parse tree, probability) 
in
                the order of descending probability."""
                pass

            def semantics(self, parse):
                "returns a semantic interpretation (logic.Clause) of a 
given par
                pass

        class Text:
            "A list of sentences who stand in rethorical relations to 
each other
            pass

        class Discourse:
            """A list of texts as utterances of given speakers 
(plan.Agent)
            which are each supposed to further the established 
knowledge about
            the discourse universe."""
            pass

    neural.py

        class Neuron:
            "Turns a vector of input to an output."
            def __init__(self, weights):
                self.weights = weights

            def __call__(self, input):
                "scalar product of input and weights"
                pass

        class NeuralNetwork:
            def __init__(self, input, inter, output):
                """specify size of input matrix, intermediate matrix 
and output
                neurons will be generated."""
                pass

            def train(self, input, output):
                "train network to produce output from input."
                pass

            def __call__(self, input):
                "produces output matrix from input."





More information about the Python-list mailing list