|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.epochx.core.GPAbstractModel<TYPE>
public abstract class GPAbstractModel<TYPE>
GPAbstractModel is a partial implementation of GPModel which provides sensible defaults for many of the necessary control parameters. It also provides a simple way of setting many values so an extending class isn't required to override all methods they wish to alter, and can instead use a simple setter method call.
Those methods that it isn't possible to provide a sensible default for, for example getFitness(CandidateProgram), getTerminals() and getFunctions(), are not implemented to force the extending class to consider their implementation.
GPModel| Constructor Summary | |
|---|---|
GPAbstractModel()
Construct a GPModel with a set of sensible defaults. |
|
| Method Summary | |
|---|---|
boolean |
acceptCrossover(CandidateProgram<TYPE>[] parents,
CandidateProgram<TYPE>[] children)
Default implementation which accepts all crossovers. |
boolean |
acceptMutation(CandidateProgram<TYPE> parent,
CandidateProgram<TYPE> child)
Default implementation which accepts all mutations. |
void |
crossoverStats(java.lang.Object[] stats)
Default implementation. |
void |
generationStats(int generation,
java.lang.Object[] stats)
Default implementation. |
Crossover<TYPE> |
getCrossover()
Retrieves the implementation of Crossover to use to perform the genetic operation of crossover between 2 parents. |
double |
getCrossoverProbability()
Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the crossover genetic operator, as opposed to mutation or reproduction. |
CrossoverStatField[] |
getCrossoverStatFields()
Default implementation. |
CrossoverStatListener |
getCrossoverStatListener()
Get a listener which will be informed of statistics about crossovers. |
GenerationStatListener |
getGenerationStatListener()
Get a listener which will be informed of statistics about generations. |
GenerationStatField[] |
getGenStatFields()
Default implementation. |
Initialiser<TYPE> |
getInitialiser()
Retrieves the Initialiser which will generate the first generation population from which the evolution will proceed. |
int |
getInitialMaxDepth()
Retrieves the maximum depth of CandidatePrograms allowed in the population after initialisation. |
LifeCycleListener<TYPE> |
getLifeCycleListener()
Default implementation returns this model as the life cycle listener. |
int |
getMaxProgramDepth()
Retrieves the maximum depth of CandidatePrograms allowed in the population after undergoing genetic operators. |
double |
getMutationProbability()
Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the mutation genetic operator, as opposed to crossover or reproduction. |
MutationStatField[] |
getMutationStatFields()
Default implementation. |
MutationStatListener |
getMutationStatListener()
Get a listener which will be informed of statistics about mutations. |
Mutation<TYPE> |
getMutator()
Retrieves the implementation of Mutator to use to perform the genetic operation of mutation on a CandidateProgram. |
int |
getNoElites()
Retrieves the number of elites that should be copied straight to the next population. |
int |
getNoGenerations()
Retrieves the number of generations that each run should use before terminating, unless prior termination occurs due to one of the other termination criterion. |
int |
getNoRuns()
Retrieves the number of runs that should be carried out using this model as the basis. |
PoolSelector<TYPE> |
getPoolSelector()
Retrieves the selector to use to construct a breeding pool from which parents can be selected using the parent selector returned by getProgramSelector() to undergo the genetic operators. |
int |
getPoolSize()
Retrieves the size of the breeding pool to be used for parent selection when performing the genetic operators. |
int |
getPopulationSize()
Retrieves the number of CandidatePrograms that should make up each generation. |
ProgramSelector<TYPE> |
getProgramSelector()
Retrieves the selector to use to pick parents from either a pre-selected breeding pool (selected by the PoolSelector returned by getPoolSelector()) or the previous population for use as input to the genetic operators. |
double |
getReproductionProbability()
Retrieves a numerical value between 0.0 and 1.0 which represents the probability of selecting the reproduction genetic operator, as opposed to crossover or mutation. |
RandomNumberGenerator |
getRNG()
Returns the RandomNumberGenerator instance that should be used for the generation of random numbers throughout execution. |
RunStatField[] |
getRunStatFields()
Default implementation. |
RunStatListener |
getRunStatListener()
Get a listener which will be informed of statistics about runs. |
java.util.List<Node<TYPE>> |
getSyntax()
Returns the union of calls to getTerminals() and getFunctions. |
double |
getTerminationFitness()
The fitness score at which a run should be stopped. |
void |
mutationStats(java.lang.Object[] stats)
Default implementation. |
CandidateProgram<TYPE>[] |
onCrossover(CandidateProgram<TYPE>[] parents,
CandidateProgram<TYPE>[] children)
Called after selection and crossover of 2 individuals. |
java.util.List<CandidateProgram<TYPE>> |
onElitism(java.util.List<CandidateProgram<TYPE>> elites)
Called after selection of elites. |
void |
onFitnessTermination()
Called on termination of the GE run where execution ended because of the successful identification of a CandidateProgram with a fitness equal to or lower than the models termination fitness parameter. |
void |
onGenerationStart()
Called at the start of each generation. |
void |
onGenerationTermination()
Called on termination of the GE run where execution ended because the requested number of generations was completed without identification of a CandidateProgram with a fitness equal to or lower than the models termination fitness parameter. |
java.util.List<CandidateProgram<TYPE>> |
onInitialisation(java.util.List<CandidateProgram<TYPE>> pop)
Called after initialisation. |
CandidateProgram<TYPE> |
onMutation(CandidateProgram<TYPE> parent,
CandidateProgram<TYPE> child)
Called after selection and mutation of an individual program. |
java.util.List<CandidateProgram<TYPE>> |
onPoolSelection(java.util.List<CandidateProgram<TYPE>> pool)
Called after selection of the breeding pool. |
CandidateProgram<TYPE> |
onReproduction(CandidateProgram<TYPE> child)
Called after selection of an individual to be reproduced into the next generation. |
void |
runStats(int runNo,
java.lang.Object[] stats)
Default implementation. |
void |
setCrossover(Crossover<TYPE> crossover)
Overwrites the default crossover operator. |
void |
setCrossoverProbability(double crossoverProbability)
Overwrites the default crossover probability. |
void |
setCrossoverStatFields(CrossoverStatField[] crossoverStatFields)
Set the crossover statistics that the given CrossoverStatListener will receive after each crossover operation. |
void |
setCrossoverStatListener(CrossoverStatListener crossoverStatListener)
Overwrites the default listener for crossover statistics. |
void |
setGenerationStatListener(GenerationStatListener generationStatListener)
Overwrites the default listener for generation statistics. |
void |
setGenStatFields(GenerationStatField[] generationStatFields)
Set the generation statistics that the given GenerationStatListener will receive at the end of each generation. |
void |
setInitialiser(Initialiser<TYPE> initialiser)
Overwrites the default initialiser. |
void |
setInitialMaxDepth(int maxInitialDepth)
Overwrites the default max program tree depth allowed after initialisation is performed. |
void |
setLifeCycleListener(LifeCycleListener<TYPE> lifeCycleListener)
Overwrites the default life cycle listener. |
void |
setMaxProgramDepth(int maxDepth)
Overwrites the default max program tree depth allowed after genetic operators are performed. |
void |
setMutationProbability(double mutationProbability)
Overwrites the default mutation probability. |
void |
setMutationStatFields(MutationStatField[] mutationStatFields)
Set the mutation statistics that the given MutationStatListener will receive after each mutation operation. |
void |
setMutationStatListener(MutationStatListener mutationStatListener)
Overwrites the default listener for mutation statistics. |
void |
setMutator(Mutation<TYPE> mutator)
Overwrites the default mutator used to perform mutation. |
void |
setNoElites(int noElites)
Overwrites the default number of elites to copy from one generation to the next. |
void |
setNoGenerations(int noGenerations)
Overwrites the default number of generations. |
void |
setNoRuns(int noRuns)
Overwrites the default number of runs. |
void |
setPoolSelector(PoolSelector<TYPE> poolSelector)
Overwrites the default pool selector used to generate a mating pool. |
void |
setPoolSize(int poolSize)
Overwrites the default pool size value. |
void |
setPopulationSize(int populationSize)
Overwrites the default population size of CandidatePrograms. |
void |
setProgramSelector(ProgramSelector<TYPE> programSelector)
Overwrites the default parent selector used to select parents to undergo a genetic operator from either a pool or the previous population. |
void |
setRNG(RandomNumberGenerator rng)
Overwrites the default random number generator used to generate random numbers to control behaviour throughout a run. |
void |
setRunStatFields(RunStatField[] runStatFields)
Set the run statistics that the given RunStatListener will receive at the end of each run. |
void |
setRunStatListener(RunStatListener runStatListener)
Overwrites the default listener for run statistics. |
void |
setTerminationFitness(double terminationFitness)
Overwrites the default fitness for run termination. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.epochx.core.GPModel |
|---|
getFitness, getFunctions, getTerminals |
| Constructor Detail |
|---|
public GPAbstractModel()
| Method Detail |
|---|
public Initialiser<TYPE> getInitialiser()
Defaults to FullInitialiser in GPAbstractModel.
getInitialiser in interface GPModel<TYPE>public void setInitialiser(Initialiser<TYPE> initialiser)
initialiser - the new Initialiser to use when generating the
starting population.public Crossover<TYPE> getCrossover()
Defaults to UniformPointCrossover in GPAbstractModel.
getCrossover in interface GPModel<TYPE>UniformPointCrossover,
KozaCrossoverpublic void setCrossover(Crossover<TYPE> crossover)
crossover - the crossover to setpublic Mutation<TYPE> getMutator()
Defaults to SubtreeMutation in GPAbstractModel.
getMutator in interface GPModel<TYPE>public void setMutator(Mutation<TYPE> mutator)
mutator - the mutator to set.public ProgramSelector<TYPE> getProgramSelector()
Defaults to RandomSelector in GPAbstractModel.
getProgramSelector in interface GPModel<TYPE>TournamentSelectorpublic void setProgramSelector(ProgramSelector<TYPE> programSelector)
programSelector - the new ProgramSelector to be used when selecting
parents for a genetic operator.public PoolSelector<TYPE> getPoolSelector()
Defaults to TournamentSelector with a tournament size of 3
in GPAbstractModel.
getPoolSelector in interface GPModel<TYPE>TournamentSelectorpublic void setPoolSelector(PoolSelector<TYPE> poolSelector)
poolSelector - the new PoolSelector to be used when building a
breeding pool.public java.util.List<Node<TYPE>> getSyntax()
getSyntax in interface GPModel<TYPE>public RandomNumberGenerator getRNG()
Defaults to JavaRandom in GEAbstractModel.
getRNG in interface GPModel<TYPE>public void setRNG(RandomNumberGenerator rng)
rng - the random number generator to be used any time random
behaviour is required.public int getNoRuns()
Defaults to 1 in GPAbstractModel.
getNoRuns in interface GPModel<TYPE>public void setNoRuns(int noRuns)
noRuns - the new number of runs to execute with this model.public int getNoGenerations()
Defaults to 50 in GPAbstractModel.
getNoGenerations in interface GPModel<TYPE>public void setNoGenerations(int noGenerations)
noGenerations - the new number of generations to use within a run.public int getPopulationSize()
Defaults to 500 in GPAbstractModel.
getPopulationSize in interface GPModel<TYPE>public void setPopulationSize(int populationSize)
populationSize - the new number of CandidatePrograms each generation
should contain.public int getPoolSize()
Defaults to 50 in GPAbstractModel.
getPoolSize in interface GPModel<TYPE>public void setPoolSize(int poolSize)
poolSize - the new size of the mating pool to use.public int getNoElites()
Defaults to 10 in GPAbstractModel.
getNoElites in interface GPModel<TYPE>public void setNoElites(int noElites)
noElites - the new number of elites to copy across from one
population to the next.public int getInitialMaxDepth()
Defaults to 6 in GPAbstractModel.
getInitialMaxDepth in interface GPModel<TYPE>public void setInitialMaxDepth(int maxInitialDepth)
maxInitialDepth - the new max program tree depth to use.public int getMaxProgramDepth()
Defaults to 17 in GPAbstractModel.
getMaxProgramDepth in interface GPModel<TYPE>public void setMaxProgramDepth(int maxDepth)
maxDepth - the new max program tree depth to use.public double getCrossoverProbability()
Within one generation approximately Pc proportion of the CandidatePrograms will have been created through crossover, Pm through mutation and Pr through reproduction. Where Pc, Pm, Pr are the values returned by getCrossoverProbability(), getMutationProbability() and getReproductionProbability() respectively. The sum of the calls to getCrossoverProbability(), getReproductionProbability() and getMutationProbability() should total 1.0.
Defaults to 0.9 in GPAbstractModel to represent a 90% chance.
getCrossoverProbability in interface GPModel<TYPE>public void setCrossoverProbability(double crossoverProbability)
crossoverProbability - the new crossover probability to use.public double getMutationProbability()
Within one generation approximately Pc proportion of the CandidatePrograms will have been created through crossover, Pm through mutation and Pr through reproduction. Where Pc, Pm, Pr are the values returned by getCrossoverProbability(), getMutationProbability() and getReproductionProbability() respectively. The sum of the calls to getCrossoverProbability(), getReproductionProbability() and getMutationProbability() should total 1.0.
Defaults to 0.0 in GPAbstractModel to represent a 0% chance.
getMutationProbability in interface GPModel<TYPE>public void setMutationProbability(double mutationProbability)
mutationProbability - the new mutation probability to use.public double getReproductionProbability()
Within one generation approximately Pc proportion of the CandidatePrograms will have been created through crossover, Pm through mutation and Pr through reproduction. Where Pc, Pm, Pr are the values returned by getCrossoverProbability(), getMutationProbability() and getReproductionProbability() respectively. The sum of the calls to getCrossoverProbability(), getReproductionProbability() and getMutationProbability() should total 1.0.
Automatically calculates the reproduction probability based upon the crossover and mutation probabilities as all three together must add up to 100%.
getReproductionProbability in interface GPModel<TYPE>public double getTerminationFitness()
Defaults to 0.0 in GPAbstractModel.
getTerminationFitness in interface GPModel<TYPE>public void setTerminationFitness(double terminationFitness)
terminationFitness - the new fitness below which a run will be
terminated.
public boolean acceptCrossover(CandidateProgram<TYPE>[] parents,
CandidateProgram<TYPE>[] children)
acceptCrossover in interface GPModel<TYPE>parents - The programs that were crossed over to create the given
children.children - The children that resulted from the parents being
crossed over.
public boolean acceptMutation(CandidateProgram<TYPE> parent,
CandidateProgram<TYPE> child)
acceptMutation in interface GPModel<TYPE>parent - The program before the mutation operation.child - The program after the mutation operation has been carried
out.
public RunStatListener getRunStatListener()
Defaults to this model object.
getRunStatListener in interface GPModel<TYPE>public void setRunStatListener(RunStatListener runStatListener)
runStatListener - the run stat listener to set.public GenerationStatListener getGenerationStatListener()
Defaults to this model object.
getGenerationStatListener in interface GPModel<TYPE>public void setGenerationStatListener(GenerationStatListener generationStatListener)
generationStatListener - the generation stat listener to set.public CrossoverStatListener getCrossoverStatListener()
Defaults to this model object.
getCrossoverStatListener in interface GPModel<TYPE>public void setCrossoverStatListener(CrossoverStatListener crossoverStatListener)
crossoverStatListener - the crossover stat listener to set.public MutationStatListener getMutationStatListener()
Defaults to this model object.
getMutationStatListener in interface GPModel<TYPE>public void setMutationStatListener(MutationStatListener mutationStatListener)
mutationStatListener - the mutation stat listener to set.public RunStatField[] getRunStatFields()
Typically it is the model that receives the statistics but this can be overridden by returning a different RunStatListener in the getRunStatListener() method. The runStats method of this object will then be called at the end of each run with these requested statistics.
getRunStatFields in interface RunStatListenerpublic void setRunStatFields(RunStatField[] runStatFields)
runStatFields - an array of RunStatFields that indicate the
statistics fields that the RunStatListener will
receive. The fields will be delivered in the same
order as given here.
public void runStats(int runNo,
java.lang.Object[] stats)
runStats in interface RunStatListenerrunNo - the run number of the current run. Runs are indexed from
zero (0).stats - an array of the statistics that were requested, given in
the order that they were requested. The data type of each
of the stats fields varies according to the field and is
specified in the JavaDoc of the RunStatField enum.public GenerationStatField[] getGenStatFields()
Typically it is the model that receives the statistics but this can be overridden by returning a different GenerationStatListener in the getGenerationStatListener() method. The genenerationStats method of this object will then be called at the end of each generation with these requested statistics.
getGenStatFields in interface GenerationStatListenerpublic void setGenStatFields(GenerationStatField[] generationStatFields)
generationStatFields - an array of GenerationStatFields that
indicate the statistics fields that the
GenerationStatListener will receive. The
fields will be delivered in the same order
as given here.
public void generationStats(int generation,
java.lang.Object[] stats)
generationStats in interface GenerationStatListenergeneration - the generation number of the current run. The first
generation in a run will be zero (0), which references
the population immediately after initialisation.stats - an array of the statistics that were requested, given in
the order that they were requested. The data type of each
of the stats fields varies according to the field and is
specified in the JavaDoc of the GenerationStatField enum.public CrossoverStatField[] getCrossoverStatFields()
Typically it is the model that receives the statistics but this can be overridden by returning a different CrossoverStatListener in the getCrossoverStatListener() method. The crossoverStats method of this object will then be called at the end of each run with these requested statistics.
getCrossoverStatFields in interface CrossoverStatListenerpublic void setCrossoverStatFields(CrossoverStatField[] crossoverStatFields)
crossoverStatFields - an array of CrossoverStatFields that indicate
the statistics fields that the
CrossoverStatListener will receive. The fields
will be delivered in the same order as given
here.public void crossoverStats(java.lang.Object[] stats)
crossoverStats in interface CrossoverStatListenerstats - an array of the statistics that were requested, given in
the order that they were requested. The data type of each
of the stats fields varies according to the field and is
specified in the JavaDoc of the CrossoverStatField enum.public MutationStatField[] getMutationStatFields()
Typically it is the model that receives the statistics but this can be overridden by returning a different MutationStatListener in the getMutationStatListener() method. The mutationStats method of this object will then be called at the end of each run with these requested statistics.
getMutationStatFields in interface MutationStatListenerpublic void setMutationStatFields(MutationStatField[] mutationStatFields)
mutationStatFields - an array of MutationStatFields that indicate
the statistics fields that the
MutationStatListener will receive. The fields
will be delivered in the same order as given
here.public void mutationStats(java.lang.Object[] stats)
mutationStats in interface MutationStatListenerstats - an array of the statistics that were requested, given in
the order that they were requested. The data type of each
of the stats fields varies according to the field and is
specified in the JavaDoc of the MutationStatField enum.public LifeCycleListener<TYPE> getLifeCycleListener()
getLifeCycleListener in interface GPModel<TYPE>public void setLifeCycleListener(LifeCycleListener<TYPE> lifeCycleListener)
lifeCycleListener - the object that should be informed about life
cycle events as they happen.public java.util.List<CandidateProgram<TYPE>> onInitialisation(java.util.List<CandidateProgram<TYPE>> pop)
Default implementation confirms the initialised population by returning the given population argument.
onInitialisation in interface InitialisationListener<TYPE>pop - the newly initialised population.
public java.util.List<CandidateProgram<TYPE>> onElitism(java.util.List<CandidateProgram<TYPE>> elites)
Default implementation confirms the selected elites by returning the given list of elites.
onElitism in interface ElitismListener<TYPE>elites - the selection of chosen elites.
public java.util.List<CandidateProgram<TYPE>> onPoolSelection(java.util.List<CandidateProgram<TYPE>> pool)
Default implementation confirms the selected breeding pool by returning the given list of programs.
onPoolSelection in interface PoolSelectionListener<TYPE>pool - the suggested breeding pool of programs.
public CandidateProgram<TYPE>[] onCrossover(CandidateProgram<TYPE>[] parents,
CandidateProgram<TYPE>[] children)
Default implementation confirms the crossover operation by returning the given array of children.
onCrossover in interface CrossoverListener<TYPE>parents - the programs that were selected to undergo crossover.children - the programs that were generated as a result of the
crossover operation.
public CandidateProgram<TYPE> onMutation(CandidateProgram<TYPE> parent,
CandidateProgram<TYPE> child)
Default implementation confirms the mutation operation by returning the given child program.
onMutation in interface MutationListener<TYPE>parent - the program that was selected to undergo mutation.child - the resultant program from the parent undergoing mutation.
public CandidateProgram<TYPE> onReproduction(CandidateProgram<TYPE> child)
Default implementation confirms the reproduction operation by returning the given selected program.
onReproduction in interface ReproductionListener<TYPE>child - the program that was selected to be reproduced.
public void onGenerationStart()
Default implementation does nothing.
onGenerationStart in interface GenerationListenerpublic void onFitnessTermination()
Default implementation does nothing.
onFitnessTermination in interface TerminationListenerpublic void onGenerationTermination()
Default implementation does nothing.
onGenerationTermination in interface TerminationListener
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||