org.encog.ml.ea.train.basic

## Class TrainEA

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

- All Implemented Interfaces:
    Serializable, EncogShutdownTask, EvolutionaryAlgorithm, MLTrain, MultiThreadable
  Direct Known Subclasses:
    MLMethodGeneticAlgorithm.MLMethodGeneticAlgorithmHelper

      public class TrainEA
      extends BasicEA
      implements MLTrain

  Provides a MLTrain compatible class that can be used to train genomes.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TrainEA(Population thePopulation, CalculateScore theScoreFunction)` Create a trainer for a score function.
    `TrainEA(Population thePopulation, MLDataSet trainingData)` Create a trainer for training data.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addStrategy(Strategy strategy)` Training strategies can be added to improve the training results.
    `boolean` | `canContinue()`
    `void` | `finishTraining()` Called when training is finished.
    `TrainingImplementationType` | `getImplementationType()`
    `MLMethod` | `getMethod()` Get the current best machine learning method from the training.
    `List<Strategy>` | `getStrategies()`
    `MLDataSet` | `getTraining()` Returns null, does not use a training set, rather uses a score function.
    `boolean` | `isTrainingDone()`
    `void` | `iteration()` Perform a training iteration.
    `void` | `iteration(int count)` Perform the specified number of training iterations.
    `TrainingContinuation` | `pause()` Pause the training to continue later.
    `void` | `postIteration()` Call the strategies after an iteration.
    `void` | `preIteration()` Call the strategies before an iteration.
    `void` | `resume(TrainingContinuation state)` Resume training.
    `void` | `setError(double error)` Not used.

    - ### Methods inherited from class org.encog.ml.ea.train.basic.BasicEA

      `addChild, addOperation, addScoreAdjuster, calculateScore, calculateScoreAdjustment, getBestComparator, getBestGenome, getChampMutation, getCODEC, getEliteRate, getError, getIteration, getMaxIndividualSize, getMaxOperationErrors, getMaxTries, getOldBestGenome, getOperators, getPopulation, getRandomNumberFactory, getRules, getScoreAdjusters, getScoreFunction, getSelection, getSelectionComparator, getShouldIgnoreExceptions, getSpeciation, getThreadCount, isValidationMode, performShutdownTask, reportError, setBestComparator, setChampMutation, setCODEC, setEliteRate, setIteration, setMaxOperationErrors, setMaxTries, setPopulation, setRandomNumberFactory, setRules, setSelection, setSelectionComparator, setShouldIgnoreExceptions, setSpeciation, setThreadCount, setValidationMode`

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

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

    - ### Methods inherited from interface org.encog.ml.train.MLTrain

      `getError, getIteration, setIteration`

- - ### Constructor Detail

    - #### TrainEA

          public TrainEA(Population thePopulation,
                 CalculateScore theScoreFunction)

      Create a trainer for a score function.
      Parameters:
        `thePopulation` - The population.
        `theScoreFunction` - The score function.

    - #### TrainEA

          public TrainEA(Population thePopulation,
                 MLDataSet trainingData)

      Create a trainer for training data.
      Parameters:
        `thePopulation` - The population.
        `trainingData` - The training data.

  - ### Method Detail

    - #### setError

          public void setError(double error)

      Not used.
      Specified by:
        `setError` in interface `MLTrain`
      Parameters:
        `error` - Not used.

    - #### isTrainingDone

          public boolean isTrainingDone()

      Specified by:
        `isTrainingDone` in interface `MLTrain`
      Returns:
        True if training can progress no further.

    - #### getImplementationType

          public TrainingImplementationType getImplementationType()

      Specified by:
        `getImplementationType` in interface `MLTrain`
      Returns:
        The training implementation type.

    - #### iteration

          public void iteration(int count)

      Perform the specified number of training iterations. This is a basic implementation that just calls iteration the specified number of times. However, some training methods, particularly with the GPU, benefit greatly by calling with higher numbers than 1.
      Specified by:
        `iteration` in interface `MLTrain`
      Parameters:
        `count` - The number of training iterations.

    - #### pause

          public TrainingContinuation pause()

      Pause the training to continue later.
      Specified by:
        `pause` in interface `MLTrain`
      Returns:
        A training continuation object.

    - #### resume

          public void resume(TrainingContinuation state)

      Resume training.
      Specified by:
        `resume` in interface `MLTrain`
      Parameters:
        `state` - The training continuation object to use to continue.

    - #### addStrategy

          public void addStrategy(Strategy strategy)

      Training strategies can be added to improve the training results. There are a number to choose from, and several can be used at once.
      Specified by:
        `addStrategy` in interface `MLTrain`
      Parameters:
        `strategy` - The strategy to add.

    - #### canContinue

          public boolean canContinue()

      Specified by:
        `canContinue` in interface `MLTrain`
      Returns:
        True if the training can be paused, and later continued.

    - #### finishTraining

          public void finishTraining()

      Called when training is finished. This allows the EA to properly shut down.
      Specified by:
        `finishTraining` in interface `EvolutionaryAlgorithm`
      Specified by:
        `finishTraining` in interface `MLTrain`
      Overrides:
        `finishTraining` in class `BasicEA`

    - #### getMethod

          public MLMethod getMethod()

      Description copied from interface: `MLTrain`
      Get the current best machine learning method from the training.
      Specified by:
        `getMethod` in interface `MLTrain`
      Returns:
        A network created for the best genome.

    - #### getTraining

          public MLDataSet getTraining()

      Returns null, does not use a training set, rather uses a score function.
      Specified by:
        `getTraining` in interface `MLTrain`
      Returns:
        null, not used.

    - #### getStrategies

          public List<Strategy> getStrategies()

      Specified by:
        `getStrategies` in interface `MLTrain`
      Returns:
        The strategies to use.

    - #### iteration

          public void iteration()

      Description copied from class: `BasicEA`
      Perform a training iteration. Also called generations or epochs.
      Specified by:
        `iteration` in interface `EvolutionaryAlgorithm`
      Specified by:
        `iteration` in interface `MLTrain`
      Overrides:
        `iteration` in class `BasicEA`

    - #### postIteration

          public void postIteration()

      Call the strategies after an iteration.

    - #### preIteration

          public void preIteration()

      Call the strategies before an iteration.

Copyright © 2014. All Rights Reserved.