Package pygene :: Module prog :: Class ProgOrganism
[show private | hide private]
[frames | no frames]

Type ProgOrganism

object --+        
         |        
PGXmlMixin --+    
             |    
  BaseOrganism --+
                 |
                ProgOrganism


Implements an organism for genetic programming

Introspects to discover functions and terminals.

You should add the folling class attribs:
Method Summary
  __init__(self, root)
Creates this organism
  calc(self, **vars)
Executes this program organism, using the given keyword parameters
  copy(self)
returns a deep copy of this organism
  dump(self, node, level)
prints out this organism's node tree
  fitness(self)
Return the fitness level of this organism, as a float
  genNode(self, depth)
Randomly generates a node to build in to this organism
  mate(self, mate)
Perform recombination of subtree elements
  mutate(self)
Mutates this organism's node tree
  split(self)
support for recombination, returns a tuple with four values:
  testFunc(self, **kw)
this is the 'reference function' toward which organisms are trying to evolve
  xmlDumpSelf(self, doc, parent)
Dumps out this object's contents into an xml tree
    Inherited from BaseOrganism
  __add__(self, partner)
Allows '+' operator for sexual reproduction
  __cmp__(self, other)
Convenience method which invokes duel
  __repr__(self)
Delivers a minimal string representation of this organism.
  duel(self, opponent)
Duels this organism against an opponent
  xmlDumpAttribs(self, elem)
Dump out the custom attributes of this organism
    Inherited from PGXmlMixin
  xmlDump(self, fileobj)
Dumps out the population to an open file in XML format.
  xmlDumpClass(self, tag)
dumps out class information
  xmlDumps(self)
dumps out to xml, returning a string of the raw generated xml
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
type __metaclass__ = pygene.prog.ProgOrganismMetaclass
list consts = []
dict funcs = {}
dict funcsDict = {}
list funcsList = []
int maxDepth = 4                                                                     
float mutProb = 0.01                                                                  
list vars = []

Method Details

__init__(self, root=None)
(Constructor)

Creates this organism
Overrides:
__builtin__.object.__init__

calc(self, **vars)

Executes this program organism, using the given keyword parameters

You shouldn't need to override this

copy(self)

returns a deep copy of this organism

dump(self, node=None, level=1)

prints out this organism's node tree
Overrides:
pygene.organism.BaseOrganism.dump

fitness(self)

Return the fitness level of this organism, as a float

Should return a number from 0.0 to infinity, where 0.0 means 'perfect'

Organisms should evolve such that 'fitness' converges to zero.

This method must be overridden

In your override, you should generate a set of values, either deterministically or randomly, and pass each value to both .testFunc() and .calculate(), comparing the results and using this to calculate the fitness
Overrides:
pygene.organism.BaseOrganism.fitness

genNode(self, depth=1)

Randomly generates a node to build in to this organism

mate(self, mate)

Perform recombination of subtree elements
Overrides:
pygene.organism.BaseOrganism.mate

mutate(self)

Mutates this organism's node tree

returns the mutant
Overrides:
pygene.organism.BaseOrganism.mutate

split(self)

support for recombination, returns a tuple with four values:
  • root - a copy of the tree, except for the fragment to be swapped
  • subtree - the subtree fragment to be swapped
  • lst - a list within the tree, containing the fragment
  • idx - index within the list where mate's fragment should be written

testFunc(self, **kw)

this is the 'reference function' toward which organisms are trying to evolve

You must override this in your organism subclass

xmlDumpSelf(self, doc, parent)

Dumps out this object's contents into an xml tree

Arguments:
  • doc - an xml.dom.minidom.Document object
  • parent - an xml.dom.minidom.Element parent, being the node into which this node should be placed
Overrides:
pygene.organism.BaseOrganism.xmlDumpSelf

Class Variable Details

consts

Type:
list
Value:
[]                                                                     

funcs

Type:
dict
Value:
{}                                                                     

funcsDict

Type:
dict
Value:
{}                                                                     

funcsList

Type:
list
Value:
[]                                                                     

maxDepth

Type:
int
Value:
4                                                                     

mutProb

Type:
float
Value:
0.01                                                                  

vars

Type:
list
Value:
[]                                                                     

Generated by Epydoc 2.1 on Mon Dec 12 14:37:12 2005 http://epydoc.sf.net