next up previous contents
Next: Attributes & Variables Up: Class: Population Previous: Class: Population   Contents

Subsections

Methods


new()

Arguments: ExperimentId => STRING, ATTRIBUTE-HASH (optional)
Return value: OBJECT
Defined in: PerlGPObject.pm
Mainly called by: perlgp-run.pl
Usually calls: _init()
Relevant attributes: all

The constructor for the Population class. You may customise the object by setting attributes as arguments to the constructor or edit _init() in Population.pm.


_init()

Arguments: ATTRIBUTE-HASH
Return value:
Defined in: GPPopulation.pm
Mainly called by:
Usually calls:
Relevant attributes:

A standard cascading _init() routine, which sets attributes. It also creates PopulationDir if it doesn't exist. If you want to change the attributes, edit the hash %defaults in _init() in Population.pm.


addIndividual()

Arguments: OBJECT individual
Return value:
Defined in: GPPopulation.pm
Mainly called by:
Usually calls:
Relevant attributes:

Adds individual to Individuals.


findNewDBFileStem()

Arguments:
Return value:
Defined in: GPPopulation.pm
Mainly called by: perlgp-run.pl
Usually calls:
Relevant attributes:

Searches the scratch directory (PERLGP_SCRATCH) for an unused filename of the format ``Individual-%06d'' where the last bit is a serial number. For speed, instead of checking for the existence of files, a hash table in memory (%usedfilestems) is used.


repopulate()

Arguments: RandomFraction => NUMBER (optional)
Return value:
Defined in: GPPopulation.pm
Mainly called by: perlgp-run.pl
Usually calls: addIndividual()
Relevant attributes: PopulationDir

This is called on a newly created Population object in perlgp-run.pl in order to load up any pre-existing Individuals. First, it looks in PopulationDir for DBM files. If there are no files and if a gzipped tar file backup exists (see backup() for this Population, then the tar file is unpacked into PopulationDir. In other words, the Population directory in PERLGP_SCRATCH is recovered from the backup.

Then all the unique filestems in PopulationDir are used to create new Individual objects which are passed to addIndividual(). In other words, new Individuals are made, each one tied to a DBM file in PopulationDir.


backup()

Arguments:
Return value:
Defined in: GPPopulation.pm
Mainly called by: TournamentGP::run()
Usually calls:
Relevant attributes: ExperimentId

This routine simply tars up the entire PopulationDir and saves it in the directory PERLGP_POPS with a name based on ExperimentId. To recover a population, see repopulate().


emigrate()

Arguments:
Return value:
Defined in: GPPopulation.pm
Mainly called by: TournamentGP::run()
Usually calls: selectCohort(), Individual::save()
Relevant attributes: MigrationSize

This method randomly selects MigrationSize Individuals and saves them in a temporary directory, which is then tarred up into a file in PERLGP_POPS (the name comes from the method export_tar_file()).


export_tar_file()

Arguments:
Return value: STRING
Defined in: GPPopulation.pm
Mainly called by: emigrate(), immigrate()
Usually calls:
Relevant attributes: ExperimentId

All this does is return the following string:

  sprintf "%s/%s.export.tar.gz", $ENV{PERLGP_POPS}, $self->ExperimentId();

(Sometimes Perl is easier to understand than English.)


immigrate()

Arguments:
Return value:
Defined in: GPPopulation.pm
Mainly called by: TournamentGP::run()
Usually calls: randomIndividual(), Individual::load()
Relevant attributes:

First, some explanation of a major assumption we make about migrating populations: that is that mutually migrating populations are assumed to have the same base ExperimentId followed by a minus sign and an integer, i.e. pi-01 pi-02 pi-03 pi-04. These directories are made automatically by the wrapper script perlgp-mrun.pl.

Potential immigrant population samples are gathered by a glob in PERLGP_POPS for ExperimentId-*.export.tar.gz. Then one of these is selected at random (but not a sample exported from this Population, of course), and is unpacked into a temporary directory. This temporary directory contains DBM files, and these are loaded up into randomly selected Individuals from this Population using Individual::load(). Each of the affected Individuals now has a new genome so its fitness is reset with a call to initFitness() (because the previous fitness may have been calculated on different training examples in the other Population).


initFitnesses()

Arguments:
Return value:
Defined in: GPPopulation.pm
Mainly called by:
Usually calls:
Relevant attributes:

A routine to call initFitness() on each Individual in the Population.


countIndividuals()

Arguments:
Return value: NUMBER
Defined in: BasePopulation.pm
Mainly called by:
Usually calls:
Relevant attributes:

Returns the number of Individuals in the Population, not to be confused with PopulationSize.


randomIndividual()

Arguments:
Return value: OBJECT
Defined in: BasePopulation.pm
Mainly called by: selectCohort()
Usually calls:
Relevant attributes:

Returns one randomly selected Individual from Individuals.


selectCohort()

Arguments: NUMBER size
Return value: ARRAY
Defined in: BasePopulation.pm
Mainly called by: TournamentGP::tournament(), emigrate()
Usually calls: randomIndividual()
Relevant attributes:

Returns size different, randomly selected Individuals from the Population.


next up previous contents
Next: Attributes & Variables Up: Class: Population Previous: Class: Population   Contents
Bob MacCallum 2003-02-03