Package pygene :: Module population :: Class Population
[show private | hide private]
[frames | no frames]

Type Population

object --+    
         |    
PGXmlMixin --+
             |
            Population


Represents a population of organisms

You might want to subclass this

Overridable class variables: Supports the following python operators:
Method Summary
  __init__(self, *items, **kw)
Create a population with zero or more members
  __add__(self, other)
Produce a whole new population consisting of an aggregate of this population and the other population's members
  __getitem__(self, n)
Return the nth member of this population, which we guarantee to be sorted in order from fittest first
  __len__(self)
return the number of organisms in this population
  __repr__(self)
crude human-readable dump of population's members
  add(self, *args)
Add an organism, or a population of organisms, to this population
  best(self)
returns the fittest member of the population
  fitness(self)
returns the average fitness value for the population
  gen(self, nfittest, nchildren)
Executes a generation of the population.
  getRandom(self, items)
randomly select one of the given items (or one of this population's members, if items not given).
  sort(self)
Sorts this population in order of fitness, with the fittest first.
  xmlDumpSelf(self, doc, parent)
Writes out the contents of this population into the xml tree
    Inherited from PGXmlMixin
  xmlDump(self, fileobj)
Dumps out the population to an open file in XML format.
  xmlDumpAttribs(self, tag)
  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
int childCount = 100                                                                   
int childCull = 20                                                                    
int incest = 10                                                                    
int initPopulation = 10                                                                    
float mutants = 0.10000000000000001                                                   
bool mutateAfterMating = True
int numNewOrganisms = 0                                                                     
type species = pygene.organism.Organism

Method Details

__init__(self, *items, **kw)
(Constructor)

Create a population with zero or more members

Arguments:
  • any number of arguments and/or sequences of args, where each arg is an instance of this population's species. If no arguments are given, organisms are randomly created and added automatically, according to self.initPopulation and self.species
Keywords:
  • init - size of initial population to randomly create. Ignored if 1 or more constructor arguments are given. if not given, value comes from self.initPopulation
  • species - species of organism to create and add. If not given, value comes from self.species
Overrides:
__builtin__.object.__init__

__add__(self, other)
(Addition operator)

Produce a whole new population consisting of an aggregate of this population and the other population's members

__getitem__(self, n)
(Indexing operator)

Return the nth member of this population, which we guarantee to be sorted in order from fittest first

__len__(self)
(Length operator)

return the number of organisms in this population

__repr__(self)
(Representation operator)

crude human-readable dump of population's members
Overrides:
__builtin__.object.__repr__

add(self, *args)

Add an organism, or a population of organisms, to this population

You can also pass lists or tuples of organisms and/or populations, to any level of nesting

best(self)

returns the fittest member of the population

fitness(self)

returns the average fitness value for the population

gen(self, nfittest=None, nchildren=None)

Executes a generation of the population.

This consists of:
  • producing 'nchildren' children, parented by members randomly selected with preference for the fittest
  • culling the children to the fittest 'nfittest' members
  • killing off the parents, and replacing them with the children
Read the source code to study the method of probabilistic selection.

getRandom(self, items=None)

randomly select one of the given items (or one of this population's members, if items not given).

Favours fitter members

sort(self)

Sorts this population in order of fitness, with the fittest first.

We keep track of whether this population is in order of fitness, so we don't perform unnecessary and costly sorting

xmlDumpSelf(self, doc, parent)

Writes out the contents of this population into the xml tree
Overrides:
pygene.xmlio.PGXmlMixin.xmlDumpSelf

Class Variable Details

childCount

Type:
int
Value:
100                                                                   

childCull

Type:
int
Value:
20                                                                    

incest

Type:
int
Value:
10                                                                    

initPopulation

Type:
int
Value:
10                                                                    

mutants

Type:
float
Value:
0.10000000000000001                                                   

mutateAfterMating

Type:
bool
Value:
True                                                                   

numNewOrganisms

Type:
int
Value:
0                                                                     

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