org.encog.neural.neat.training
Class NEATTraining

java.lang.Object
  extended by org.encog.ml.genetic.GeneticAlgorithm
      extended by org.encog.neural.neat.training.NEATTraining
All Implemented Interfaces:
MLTrain, MultiThreadable

public class NEATTraining
extends GeneticAlgorithm
implements MLTrain

Implements NEAT genetic training. NeuroEvolution of Augmenting Topologies (NEAT) is a genetic algorithm for the generation of evolving artificial neural networks. It was developed by Ken Stanley while at The University of Texas at Austin. http://www.cs.ucf.edu/~kstanley/


Constructor Summary
NEATTraining(CalculateScore calculateScore, int inputCount, int outputCount, int populationSize)
          Construct a neat trainer with a new population.
NEATTraining(CalculateScore calculateScore, Population population)
          Construct neat training with an existing population.
 
Method Summary
 void addNeuronID(long nodeID, List<Long> vec)
          Add a neuron.
 void addStrategy(Strategy strategy)
          Not supported, will throw an error.
 void adjustCompatibilityThreshold()
          Adjust the species compatibility threshold.
 void adjustSpeciesScore()
          Adjust each species score.
 boolean canContinue()
           
 NEATGenome crossover(NEATGenome mom, NEATGenome dad)
          Perform the crossover.
 void finishTraining()
          Called when training is done.
 double getError()
          return The error for the best genome.
 TrainingImplementationType getImplementationType()
           
 NEATInnovationList getInnovations()
           
 int getInputCount()
           
 int getIteration()
           
 MLMethod getMethod()
          Get the current best machine learning method from the training.
 int getOutputCount()
           
 List<Strategy> getStrategies()
          Returns an empty list, strategies are not supported.
 MLDataSet getTraining()
          Returns null, does not use a training set, rather uses a score function.
 boolean isSnapshot()
           
 boolean isTrainingDone()
           
 void iteration()
          Perform one training iteration.
 void iteration(int count)
          Perform the specified number of training iterations.
 TrainingContinuation pause()
          Pause the training to continue later.
 void resetAndKill()
          Reset for an iteration.
 void resume(TrainingContinuation state)
          Resume training.
 void setError(double error)
          Not used.
 void setIteration(int iteration)
          Set the current training iteration.
 void setSnapshot(boolean snapshot)
          Set if we are using snapshot mode.
 void sortAndRecord()
          Sort the genomes.
 void speciateAndCalculateSpawnLevels()
          Determine the species.
 NEATGenome tournamentSelection(int numComparisons)
          Select a gene using a tournament.
 
Methods inherited from class org.encog.ml.genetic.GeneticAlgorithm
addSpeciesMember, calculateScore, getCalculateScore, getComparator, getCrossover, getMatingPopulation, getMutate, getMutationPercent, getPercentToMate, getPopulation, getThreadCount, setCalculateScore, setComparator, setCrossover, setMatingPopulation, setMutate, setMutationPercent, setPercentToMate, setPopulation, setThreadCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NEATTraining

public NEATTraining(CalculateScore calculateScore,
                    int inputCount,
                    int outputCount,
                    int populationSize)
Construct a neat trainer with a new population. The new population is created from the specified parameters.

Parameters:
calculateScore - The score calculation object.
inputCount - The input neuron count.
outputCount - The output neuron count.
populationSize - The population size.

NEATTraining

public NEATTraining(CalculateScore calculateScore,
                    Population population)
Construct neat training with an existing population.

Parameters:
calculateScore - The score object to use.
population - The population to use.
Method Detail

addNeuronID

public void addNeuronID(long nodeID,
                        List<Long> vec)
Add a neuron.

Parameters:
nodeID - The neuron id.
vec - THe list of id's used.

addStrategy

public void addStrategy(Strategy strategy)
Not supported, will throw an error.

Specified by:
addStrategy in interface MLTrain
Parameters:
strategy - Not used.

adjustCompatibilityThreshold

public void adjustCompatibilityThreshold()
Adjust the species compatibility threshold. This prevents us from having too many species.


adjustSpeciesScore

public void adjustSpeciesScore()
Adjust each species score.


canContinue

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

crossover

public NEATGenome crossover(NEATGenome mom,
                            NEATGenome dad)
Perform the crossover.

Parameters:
mom - The mother.
dad - The father.
Returns:
The child.

finishTraining

public void finishTraining()
Called when training is done.

Specified by:
finishTraining in interface MLTrain

getError

public double getError()
return The error for the best genome.

Specified by:
getError in interface MLTrain
Returns:
Returns the training error. This value is calculated as the training data is evaluated by the iteration function. This has two important ramifications. First, the value returned by getError() is meaningless prior to a call to iteration. Secondly, the error is calculated BEFORE training is applied by the call to iteration. The timing of the error calculation is done for performance reasons.

getImplementationType

public TrainingImplementationType getImplementationType()
Specified by:
getImplementationType in interface MLTrain
Returns:
The training implementation type.

getInnovations

public NEATInnovationList getInnovations()
Returns:
The innovations.

getInputCount

public int getInputCount()
Returns:
The input count.

getIteration

public int getIteration()
Specified by:
getIteration in interface MLTrain
Returns:
The current training iteration.

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.

getOutputCount

public int getOutputCount()
Returns:
The number of output neurons.

getStrategies

public List<Strategy> getStrategies()
Returns an empty list, strategies are not supported.

Specified by:
getStrategies in interface MLTrain
Returns:
The strategies in use(none).

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.

isSnapshot

public boolean isSnapshot()
Returns:
Are we using snapshot mode.

isTrainingDone

public boolean isTrainingDone()
Specified by:
isTrainingDone in interface MLTrain
Returns:
True if training can progress no further.

iteration

public void iteration()
Perform one training iteration.

Specified by:
iteration in interface MLTrain
Specified by:
iteration in class GeneticAlgorithm

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()
Description copied from interface: MLTrain
Pause the training to continue later.

Specified by:
pause in interface MLTrain
Returns:
A training continuation object.

resetAndKill

public void resetAndKill()
Reset for an iteration.


resume

public void resume(TrainingContinuation state)
Description copied from interface: MLTrain
Resume training.

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

setError

public void setError(double error)
Not used.

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

setIteration

public void setIteration(int iteration)
Description copied from interface: MLTrain
Set the current training iteration.

Specified by:
setIteration in interface MLTrain
Parameters:
iteration - Iteration.

setSnapshot

public void setSnapshot(boolean snapshot)
Set if we are using snapshot mode.

Parameters:
snapshot - True if we are using snapshot mode.

sortAndRecord

public void sortAndRecord()
Sort the genomes.


speciateAndCalculateSpawnLevels

public void speciateAndCalculateSpawnLevels()
Determine the species.


tournamentSelection

public NEATGenome tournamentSelection(int numComparisons)
Select a gene using a tournament.

Parameters:
numComparisons - The number of compares to do.
Returns:
The chosen genome.


Copyright © 2012. All Rights Reserved.