org.encog.ml.ea.train.basic
Class BasicEA
- java.lang.Object
-
- org.encog.ml.ea.train.basic.BasicEA
-
- All Implemented Interfaces:
- java.io.Serializable, EncogShutdownTask, EvolutionaryAlgorithm, MultiThreadable
- Direct Known Subclasses:
- TrainEA
public class BasicEA extends java.lang.Object implements EvolutionaryAlgorithm, MultiThreadable, EncogShutdownTask, java.io.Serializable
Provides a basic implementation of a multi-threaded Evolutionary Algorithm. The EA works from a score function.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description BasicEA(Population thePopulation, CalculateScore theScoreFunction)Construct an EA.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanaddChild(Genome genome)Add a child to the next iteration.voidaddOperation(double probability, EvolutionaryOperator opp)Add an operation.voidaddScoreAdjuster(AdjustScore scoreAdjust)Add a score adjuster.voidcalculateScore(Genome g)Calculate the score for a genome.static voidcalculateScoreAdjustment(Genome genome, java.util.List<AdjustScore> adjusters)Calculate the score adjustment, based on adjusters.voidfinishTraining()Called when training is finished.GenomeComparatorgetBestComparator()Get the comparator that is used to choose the "true best" genome.GenomegetBestGenome()EvolutionaryOperatorgetChampMutation()GeneticCODECgetCODEC()doublegetEliteRate()doublegetError()intgetIteration()intgetMaxIndividualSize()intgetMaxOperationErrors()intgetMaxTries()GenomegetOldBestGenome()OperationListgetOperators()PopulationgetPopulation()RandomFactorygetRandomNumberFactory()java.util.List<AdjustScore>getScoreAdjusters()CalculateScoregetScoreFunction()SelectionOperatorgetSelection()GenomeComparatorgetSelectionComparator()Get the comparator that is used to choose the "best" genome for selection, as opposed to the "true best".booleangetShouldIgnoreExceptions()SpeciationgetSpeciation()intgetThreadCount()booleanisValidationMode()voiditeration()Perform a training iteration.voidperformShutdownTask()voidreportError(java.lang.Throwable t)Called by a thread to report an error.voidsetBestComparator(GenomeComparator theComparator)Set the comparator.voidsetChampMutation(EvolutionaryOperator champMutation)voidsetCODEC(GeneticCODEC theCodec)Set the CODEC to use.voidsetEliteRate(double eliteRate)voidsetIteration(int iteration)Set the current iteration number.voidsetMaxOperationErrors(int maxOperationErrors)voidsetMaxTries(int maxTries)voidsetPopulation(Population thePopulation)Set the population.voidsetRandomNumberFactory(RandomFactory randomNumberFactory)voidsetSelection(SelectionOperator selection)Set the selection operator.voidsetSelectionComparator(GenomeComparator theComparator)Set the comparator that is used to choose the "best" genome for selection, as opposed to the "true best".voidsetShouldIgnoreExceptions(boolean b)Determines if genetic operator exceptions should be ignored.voidsetSpeciation(Speciation speciation)Set the speciation method.voidsetThreadCount(int numThreads)Set the number of threads to use.voidsetValidationMode(boolean validationMode)Determine if the genomes should be validated.
-
-
-
Constructor Detail
-
BasicEA
public BasicEA(Population thePopulation, CalculateScore theScoreFunction)
Construct an EA.- Parameters:
thePopulation- The population.theScoreFunction- The score function.
-
-
Method Detail
-
calculateScoreAdjustment
public static void calculateScoreAdjustment(Genome genome, java.util.List<AdjustScore> adjusters)
Calculate the score adjustment, based on adjusters.- Parameters:
genome- The genome to adjust.adjusters- The score adjusters.
-
addChild
public boolean addChild(Genome genome)
Add a child to the next iteration.- Parameters:
genome- The child.- Returns:
- True, if the child was added successfully.
-
addOperation
public void addOperation(double probability, EvolutionaryOperator opp)Add an operation.- Specified by:
addOperationin interfaceEvolutionaryAlgorithm- Parameters:
probability- The probability of using this operator.opp- The operator to add.
-
addScoreAdjuster
public void addScoreAdjuster(AdjustScore scoreAdjust)
Add a score adjuster. Score adjusters are used to adjust the adjusted score of a genome. This allows bonuses and penalties to be applied for desirable or undesirable traits.- Specified by:
addScoreAdjusterin interfaceEvolutionaryAlgorithm- Parameters:
scoreAdjust- The score adjustor to add.
-
calculateScore
public void calculateScore(Genome g)
Calculate the score for a genome.- Specified by:
calculateScorein interfaceEvolutionaryAlgorithm- Parameters:
g- The genome to calculate the score for.
-
finishTraining
public void finishTraining()
Called when training is finished. This allows the EA to properly shut down.- Specified by:
finishTrainingin interfaceEvolutionaryAlgorithm
-
getBestComparator
public GenomeComparator getBestComparator()
Get the comparator that is used to choose the "true best" genome. This uses the real score, and not the adjusted score.- Specified by:
getBestComparatorin interfaceEvolutionaryAlgorithm- Returns:
- The best comparator.
-
getBestGenome
public Genome getBestGenome()
- Specified by:
getBestGenomein interfaceEvolutionaryAlgorithm- Returns:
- the bestGenome
-
getChampMutation
public EvolutionaryOperator getChampMutation()
- Returns:
- the champMutation
-
getCODEC
public GeneticCODEC getCODEC()
- Specified by:
getCODECin interfaceEvolutionaryAlgorithm- Returns:
- The CODEC that is used to transform between genome and phenome.
-
getEliteRate
public double getEliteRate()
- Returns:
- the eliteRate
-
getError
public double getError()
- Specified by:
getErrorin interfaceEvolutionaryAlgorithm- Returns:
- The current score. This value should either be minimized or maximized, depending on the score function.
-
getIteration
public int getIteration()
- Specified by:
getIterationin interfaceEvolutionaryAlgorithm- Returns:
- The current iteration number. Also sometimes referred to as generation or epoch.
-
getMaxIndividualSize
public int getMaxIndividualSize()
- Specified by:
getMaxIndividualSizein interfaceEvolutionaryAlgorithm- Returns:
- The maximum size an individual genome can be. This is an arbitrary number defined by the genome. Lower numbers are less complex.
-
getMaxTries
public int getMaxTries()
- Specified by:
getMaxTriesin interfaceEvolutionaryAlgorithm- Returns:
- The maximum number to try certain genetic operations. This prevents endless loops.
-
getOldBestGenome
public Genome getOldBestGenome()
- Returns:
- the oldBestGenome
-
getOperators
public OperationList getOperators()
- Specified by:
getOperatorsin interfaceEvolutionaryAlgorithm- Returns:
- The operators.
-
getPopulation
public Population getPopulation()
- Specified by:
getPopulationin interfaceEvolutionaryAlgorithm- Returns:
- The population.
-
getRandomNumberFactory
public RandomFactory getRandomNumberFactory()
- Returns:
- the randomNumberFactory
-
getScoreAdjusters
public java.util.List<AdjustScore> getScoreAdjusters()
- Specified by:
getScoreAdjustersin interfaceEvolutionaryAlgorithm- Returns:
- The score adjusters. This allows bonuses and penalties to be applied for desirable or undesirable traits.
-
getScoreFunction
public CalculateScore getScoreFunction()
- Specified by:
getScoreFunctionin interfaceEvolutionaryAlgorithm- Returns:
- The score function.
-
getSelection
public SelectionOperator getSelection()
- Specified by:
getSelectionin interfaceEvolutionaryAlgorithm- Returns:
- The selection operator. Used to choose genomes.
-
getSelectionComparator
public GenomeComparator getSelectionComparator()
Get the comparator that is used to choose the "best" genome for selection, as opposed to the "true best". This uses the adjusted score, and not the score.- Specified by:
getSelectionComparatorin interfaceEvolutionaryAlgorithm- Returns:
- The selection comparator.
-
getShouldIgnoreExceptions
public boolean getShouldIgnoreExceptions()
- Specified by:
getShouldIgnoreExceptionsin interfaceEvolutionaryAlgorithm- Returns:
- True if exceptions that occur during genetic operations should be ignored.
-
getSpeciation
public Speciation getSpeciation()
- Specified by:
getSpeciationin interfaceEvolutionaryAlgorithm- Returns:
- The speciation method.
-
getThreadCount
public int getThreadCount()
- Specified by:
getThreadCountin interfaceMultiThreadable- Returns:
- The number of threads to use, 0 to automatically determine based on core count.
-
isValidationMode
public boolean isValidationMode()
- Specified by:
isValidationModein interfaceEvolutionaryAlgorithm- Returns:
- True if any genome validators should be applied.
-
iteration
public void iteration()
Perform a training iteration. Also called generations or epochs.- Specified by:
iterationin interfaceEvolutionaryAlgorithm
-
performShutdownTask
public void performShutdownTask()
- Specified by:
performShutdownTaskin interfaceEncogShutdownTask
-
reportError
public void reportError(java.lang.Throwable t)
Called by a thread to report an error.- Parameters:
t- The error reported.
-
setBestComparator
public void setBestComparator(GenomeComparator theComparator)
Set the comparator.- Specified by:
setBestComparatorin interfaceEvolutionaryAlgorithm- Parameters:
theComparator- The comparator.
-
setChampMutation
public void setChampMutation(EvolutionaryOperator champMutation)
- Parameters:
champMutation- the champMutation to set
-
setCODEC
public void setCODEC(GeneticCODEC theCodec)
Set the CODEC to use.- Parameters:
theCodec- The CODEC to use.
-
setEliteRate
public void setEliteRate(double eliteRate)
- Parameters:
eliteRate- the eliteRate to set
-
setIteration
public void setIteration(int iteration)
Set the current iteration number.- Parameters:
iteration- The iteration number.
-
setMaxTries
public void setMaxTries(int maxTries)
- Parameters:
maxTries- the maxTries to set
-
setPopulation
public void setPopulation(Population thePopulation)
Set the population.- Specified by:
setPopulationin interfaceEvolutionaryAlgorithm- Parameters:
thePopulation- The population.
-
setRandomNumberFactory
public void setRandomNumberFactory(RandomFactory randomNumberFactory)
- Parameters:
randomNumberFactory- the randomNumberFactory to set
-
setSelection
public void setSelection(SelectionOperator selection)
Set the selection operator.- Specified by:
setSelectionin interfaceEvolutionaryAlgorithm- Parameters:
selection- The selection operator.
-
setSelectionComparator
public void setSelectionComparator(GenomeComparator theComparator)
Set the comparator that is used to choose the "best" genome for selection, as opposed to the "true best". This uses the adjusted score, and not the score.- Specified by:
setSelectionComparatorin interfaceEvolutionaryAlgorithm- Parameters:
theComparator- The selection comparator.
-
setShouldIgnoreExceptions
public void setShouldIgnoreExceptions(boolean b)
Determines if genetic operator exceptions should be ignored.- Specified by:
setShouldIgnoreExceptionsin interfaceEvolutionaryAlgorithm- Parameters:
b- True if exceptions should be ignored.
-
setSpeciation
public void setSpeciation(Speciation speciation)
Set the speciation method.- Specified by:
setSpeciationin interfaceEvolutionaryAlgorithm- Parameters:
speciation- The speciation method.
-
setThreadCount
public void setThreadCount(int numThreads)
Set the number of threads to use.- Specified by:
setThreadCountin interfaceMultiThreadable- Parameters:
numThreads- The number of threads to use, or zero to automatically determine based on core count.
-
setValidationMode
public void setValidationMode(boolean validationMode)
Determine if the genomes should be validated. This takes more time but can help isolate a problem.- Specified by:
setValidationModein interfaceEvolutionaryAlgorithm- Parameters:
validationMode- True, if validation mode is enabled.
-
getMaxOperationErrors
public int getMaxOperationErrors()
- Returns:
- the maxOperationErrors
-
setMaxOperationErrors
public void setMaxOperationErrors(int maxOperationErrors)
- Parameters:
maxOperationErrors- the maxOperationErrors to set
-
-
DMelt 3.0 © DataMelt by jWork.ORG