org.encog.ml.ea.train.basic

## Class BasicEA

- java.lang.Object
- - org.encog.ml.ea.train.basic.BasicEA

- All Implemented Interfaces:
    Serializable, EncogShutdownTask, EvolutionaryAlgorithm, MultiThreadable
  Direct Known Subclasses:
    TrainEA

      public class BasicEA
      extends Object
      implements EvolutionaryAlgorithm, MultiThreadable, EncogShutdownTask, 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

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addChild(Genome genome)` Add a child to the next iteration.
    `void` | `addOperation(double probability, EvolutionaryOperator opp)` Add an operation.
    `void` | `addScoreAdjuster(AdjustScore scoreAdjust)` Add a score adjuster.
    `void` | `calculateScore(Genome g)` Calculate the score for a genome.
    `static void` | `calculateScoreAdjustment(Genome genome, List<AdjustScore> adjusters)` Calculate the score adjustment, based on adjusters.
    `void` | `finishTraining()` Called when training is finished.
    `GenomeComparator` | `getBestComparator()` Get the comparator that is used to choose the "true best" genome.
    `Genome` | `getBestGenome()`
    `EvolutionaryOperator` | `getChampMutation()`
    `GeneticCODEC` | `getCODEC()`
    `double` | `getEliteRate()`
    `double` | `getError()`
    `int` | `getIteration()`
    `int` | `getMaxIndividualSize()`
    `int` | `getMaxOperationErrors()`
    `int` | `getMaxTries()`
    `Genome` | `getOldBestGenome()`
    `OperationList` | `getOperators()`
    `Population` | `getPopulation()`
    `RandomFactory` | `getRandomNumberFactory()`
    `RuleHolder` | `getRules()`
    `List<AdjustScore>` | `getScoreAdjusters()`
    `CalculateScore` | `getScoreFunction()`
    `SelectionOperator` | `getSelection()`
    `GenomeComparator` | `getSelectionComparator()` Get the comparator that is used to choose the "best" genome for selection, as opposed to the "true best".
    `boolean` | `getShouldIgnoreExceptions()`
    `Speciation` | `getSpeciation()`
    `int` | `getThreadCount()`
    `boolean` | `isValidationMode()`
    `void` | `iteration()` Perform a training iteration.
    `void` | `performShutdownTask()`
    `void` | `reportError(Throwable t)` Called by a thread to report an error.
    `void` | `setBestComparator(GenomeComparator theComparator)` Set the comparator.
    `void` | `setChampMutation(EvolutionaryOperator champMutation)`
    `void` | `setCODEC(GeneticCODEC theCodec)` Set the CODEC to use.
    `void` | `setEliteRate(double eliteRate)`
    `void` | `setIteration(int iteration)` Set the current iteration number.
    `void` | `setMaxOperationErrors(int maxOperationErrors)`
    `void` | `setMaxTries(int maxTries)`
    `void` | `setPopulation(Population thePopulation)` Set the population.
    `void` | `setRandomNumberFactory(RandomFactory randomNumberFactory)`
    `void` | `setRules(RuleHolder rules)` Set the rules holder to use.
    `void` | `setSelection(SelectionOperator selection)` Set the selection operator.
    `void` | `setSelectionComparator(GenomeComparator theComparator)` Set the comparator that is used to choose the "best" genome for selection, as opposed to the "true best".
    `void` | `setShouldIgnoreExceptions(boolean b)` Determines if genetic operator exceptions should be ignored.
    `void` | `setSpeciation(Speciation speciation)` Set the speciation method.
    `void` | `setThreadCount(int numThreads)` Set the number of threads to use.
    `void` | `setValidationMode(boolean validationMode)` Determine if the genomes should be validated.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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,
                                      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:
        `addOperation` in interface `EvolutionaryAlgorithm`
      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:
        `addScoreAdjuster` in interface `EvolutionaryAlgorithm`
      Parameters:
        `scoreAdjust` - The score adjustor to add.

    - #### calculateScore

          public void calculateScore(Genome g)

      Calculate the score for a genome.
      Specified by:
        `calculateScore` in interface `EvolutionaryAlgorithm`
      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:
        `finishTraining` in interface `EvolutionaryAlgorithm`

    - #### 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:
        `getBestComparator` in interface `EvolutionaryAlgorithm`
      Returns:
        The best comparator.

    - #### getBestGenome

          public Genome getBestGenome()

      Specified by:
        `getBestGenome` in interface `EvolutionaryAlgorithm`
      Returns:
        the bestGenome

    - #### getChampMutation

          public EvolutionaryOperator getChampMutation()

      Returns:
        the champMutation

    - #### getCODEC

          public GeneticCODEC getCODEC()

      Specified by:
        `getCODEC` in interface `EvolutionaryAlgorithm`
      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:
        `getError` in interface `EvolutionaryAlgorithm`
      Returns:
        The current score. This value should either be minimized or maximized, depending on the score function.

    - #### getIteration

          public int getIteration()

      Specified by:
        `getIteration` in interface `EvolutionaryAlgorithm`
      Returns:
        The current iteration number. Also sometimes referred to as generation or epoch.

    - #### getMaxIndividualSize

          public int getMaxIndividualSize()

      Specified by:
        `getMaxIndividualSize` in interface `EvolutionaryAlgorithm`
      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:
        `getMaxTries` in interface `EvolutionaryAlgorithm`
      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:
        `getOperators` in interface `EvolutionaryAlgorithm`
      Returns:
        The operators.

    - #### getPopulation

          public Population getPopulation()

      Specified by:
        `getPopulation` in interface `EvolutionaryAlgorithm`
      Returns:
        The population.

    - #### getRandomNumberFactory

          public RandomFactory getRandomNumberFactory()

      Returns:
        the randomNumberFactory

    - #### getRules

          public RuleHolder getRules()

      Specified by:
        `getRules` in interface `EvolutionaryAlgorithm`
      Returns:
        the rules

    - #### getScoreAdjusters

          public List<AdjustScore> getScoreAdjusters()

      Specified by:
        `getScoreAdjusters` in interface `EvolutionaryAlgorithm`
      Returns:
        The score adjusters. This allows bonuses and penalties to be applied for desirable or undesirable traits.

    - #### getScoreFunction

          public CalculateScore getScoreFunction()

      Specified by:
        `getScoreFunction` in interface `EvolutionaryAlgorithm`
      Returns:
        The score function.

    - #### getSelection

          public SelectionOperator getSelection()

      Specified by:
        `getSelection` in interface `EvolutionaryAlgorithm`
      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:
        `getSelectionComparator` in interface `EvolutionaryAlgorithm`
      Returns:
        The selection comparator.

    - #### getShouldIgnoreExceptions

          public boolean getShouldIgnoreExceptions()

      Specified by:
        `getShouldIgnoreExceptions` in interface `EvolutionaryAlgorithm`
      Returns:
        True if exceptions that occur during genetic operations should be ignored.

    - #### getSpeciation

          public Speciation getSpeciation()

      Specified by:
        `getSpeciation` in interface `EvolutionaryAlgorithm`
      Returns:
        The speciation method.

    - #### getThreadCount

          public int getThreadCount()

      Specified by:
        `getThreadCount` in interface `MultiThreadable`
      Returns:
        The number of threads to use, 0 to automatically determine based on core count.

    - #### isValidationMode

          public boolean isValidationMode()

      Specified by:
        `isValidationMode` in interface `EvolutionaryAlgorithm`
      Returns:
        True if any genome validators should be applied.

    - #### iteration

          public void iteration()

      Perform a training iteration. Also called generations or epochs.
      Specified by:
        `iteration` in interface `EvolutionaryAlgorithm`

    - #### performShutdownTask

          public void performShutdownTask()

      Specified by:
        `performShutdownTask` in interface `EncogShutdownTask`

    - #### reportError

          public void reportError(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:
        `setBestComparator` in interface `EvolutionaryAlgorithm`
      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:
        `setPopulation` in interface `EvolutionaryAlgorithm`
      Parameters:
        `thePopulation` - The population.

    - #### setRandomNumberFactory

          public void setRandomNumberFactory(RandomFactory randomNumberFactory)

      Parameters:
        `randomNumberFactory` - the randomNumberFactory to set

    - #### setRules

          public void setRules(RuleHolder rules)

      Description copied from interface: `EvolutionaryAlgorithm`
      Set the rules holder to use.
      Specified by:
        `setRules` in interface `EvolutionaryAlgorithm`
      Parameters:
        `rules` - the rules to set

    - #### setSelection

          public void setSelection(SelectionOperator selection)

      Set the selection operator.
      Specified by:
        `setSelection` in interface `EvolutionaryAlgorithm`
      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:
        `setSelectionComparator` in interface `EvolutionaryAlgorithm`
      Parameters:
        `theComparator` - The selection comparator.

    - #### setShouldIgnoreExceptions

          public void setShouldIgnoreExceptions(boolean b)

      Determines if genetic operator exceptions should be ignored.
      Specified by:
        `setShouldIgnoreExceptions` in interface `EvolutionaryAlgorithm`
      Parameters:
        `b` - True if exceptions should be ignored.

    - #### setSpeciation

          public void setSpeciation(Speciation speciation)

      Set the speciation method.
      Specified by:
        `setSpeciation` in interface `EvolutionaryAlgorithm`
      Parameters:
        `speciation` - The speciation method.

    - #### setThreadCount

          public void setThreadCount(int numThreads)

      Set the number of threads to use.
      Specified by:
        `setThreadCount` in interface `MultiThreadable`
      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:
        `setValidationMode` in interface `EvolutionaryAlgorithm`
      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

Copyright © 2014. All Rights Reserved.