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()
           
 double getParamActivationMutationRate()
           
 double getParamChanceAddLink()
           
 double getParamChanceAddNode()
           
 double getParamChanceAddRecurrentLink()
           
 double getParamCompatibilityThreshold()
           
 double getParamCrossoverRate()
           
 double getParamMaxActivationPerturbation()
           
 int getParamMaxNumberOfSpecies()
           
 double getParamMaxPermittedNeurons()
           
 double getParamMaxWeightPerturbation()
           
 double getParamMutationRate()
           
 int getParamNumAddLinkAttempts()
           
 int getParamNumGensAllowedNoImprovement()
           
 int getParamNumTrysToFindLoopedLink()
           
 int getParamNumTrysToFindOldLink()
           
 double getParamProbabilityWeightReplaced()
           
 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 setParamActivationMutationRate(double paramActivationMutationRate)
          Set the activation mutation rate.
 void setParamChanceAddLink(double paramChanceAddLink)
          Set the chance to add a link.
 void setParamChanceAddNode(double paramChanceAddNode)
          Set the chance to add a node.
 void setParamChanceAddRecurrentLink(double paramChanceAddRecurrentLink)
          Set the chance to add a recurrent link.
 void setParamCompatibilityThreshold(double paramCompatibilityThreshold)
          Set the compatibility threshold for species.
 void setParamCrossoverRate(double paramCrossoverRate)
          Set the cross over rate.
 void setParamMaxActivationPerturbation(double paramMaxActivationPerturbation)
          Set the max activation perturbation.
 void setParamMaxNumberOfSpecies(int paramMaxNumberOfSpecies)
          Set the maximum number of species.
 void setParamMaxPermittedNeurons(double paramMaxPermittedNeurons)
          Set the max permitted neurons.
 void setParamMaxWeightPerturbation(double paramMaxWeightPerturbation)
          Set the max weight perturbation.
 void setParamMutationRate(double paramMutationRate)
          Set the mutation rate.
 void setParamNumAddLinkAttempts(int paramNumAddLinkAttempts)
          Set the number of attempts to add a link.
 void setParamNumGensAllowedNoImprovement(int paramNumGensAllowedNoImprovement)
          Set the number of no-improvement generations allowed.
 void setParamNumTrysToFindLoopedLink(int paramNumTrysToFindLoopedLink)
          Set the number of tries to create a looped link.
 void setParamNumTrysToFindOldLink(int paramNumTrysToFindOldLink)
          Set the number of tries to try an old link.
 void setParamProbabilityWeightReplaced(double paramProbabilityWeightReplaced)
          Set the probability to replace a weight.
 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.

getParamActivationMutationRate

public double getParamActivationMutationRate()
Returns:
The mutation rate.

getParamChanceAddLink

public double getParamChanceAddLink()
Returns:
The chance that we will add a link.

getParamChanceAddNode

public double getParamChanceAddNode()
Returns:
The chance that we will add a node.

getParamChanceAddRecurrentLink

public double getParamChanceAddRecurrentLink()
Returns:
The chance we will add a recurrent link.

getParamCompatibilityThreshold

public double getParamCompatibilityThreshold()
Returns:
The compatibility threshold for a species.

getParamCrossoverRate

public double getParamCrossoverRate()
Returns:
The crossover rate.

getParamMaxActivationPerturbation

public double getParamMaxActivationPerturbation()
Returns:
THe maximum activation perturbation.

getParamMaxNumberOfSpecies

public int getParamMaxNumberOfSpecies()
Returns:
The maximum number of species.

getParamMaxPermittedNeurons

public double getParamMaxPermittedNeurons()
Returns:
THe maximum neurons.

getParamMaxWeightPerturbation

public double getParamMaxWeightPerturbation()
Returns:
THe max weight perturbation.

getParamMutationRate

public double getParamMutationRate()
Returns:
The mutation rate.

getParamNumAddLinkAttempts

public int getParamNumAddLinkAttempts()
Returns:
The number of attempts to add a link.

getParamNumGensAllowedNoImprovement

public int getParamNumGensAllowedNoImprovement()
Returns:
The number of generations allowed with no improvement.

getParamNumTrysToFindLoopedLink

public int getParamNumTrysToFindLoopedLink()
Returns:
The number of tries to find a looped link.

getParamNumTrysToFindOldLink

public int getParamNumTrysToFindOldLink()
Returns:
The number of tries to find an old link.

getParamProbabilityWeightReplaced

public double getParamProbabilityWeightReplaced()
Returns:
THe propbability that a weight will be replaced.

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.

setParamActivationMutationRate

public void setParamActivationMutationRate(double paramActivationMutationRate)
Set the activation mutation rate.

Parameters:
paramActivationMutationRate - The mutation rate.

setParamChanceAddLink

public void setParamChanceAddLink(double paramChanceAddLink)
Set the chance to add a link.

Parameters:
paramChanceAddLink - The chance to add a link.

setParamChanceAddNode

public void setParamChanceAddNode(double paramChanceAddNode)
Set the chance to add a node.

Parameters:
paramChanceAddNode - The chance to add a node.

setParamChanceAddRecurrentLink

public void setParamChanceAddRecurrentLink(double paramChanceAddRecurrentLink)
Set the chance to add a recurrent link.

Parameters:
paramChanceAddRecurrentLink - The chance to add a recurrent link.

setParamCompatibilityThreshold

public void setParamCompatibilityThreshold(double paramCompatibilityThreshold)
Set the compatibility threshold for species.

Parameters:
paramCompatibilityThreshold - The threshold.

setParamCrossoverRate

public void setParamCrossoverRate(double paramCrossoverRate)
Set the cross over rate.

Parameters:
paramCrossoverRate - The crossover rate.

setParamMaxActivationPerturbation

public void setParamMaxActivationPerturbation(double paramMaxActivationPerturbation)
Set the max activation perturbation.

Parameters:
paramMaxActivationPerturbation - The max perturbation.

setParamMaxNumberOfSpecies

public void setParamMaxNumberOfSpecies(int paramMaxNumberOfSpecies)
Set the maximum number of species.

Parameters:
paramMaxNumberOfSpecies - The max number of species.

setParamMaxPermittedNeurons

public void setParamMaxPermittedNeurons(double paramMaxPermittedNeurons)
Set the max permitted neurons.

Parameters:
paramMaxPermittedNeurons - The max permitted neurons.

setParamMaxWeightPerturbation

public void setParamMaxWeightPerturbation(double paramMaxWeightPerturbation)
Set the max weight perturbation.

Parameters:
paramMaxWeightPerturbation - The max weight perturbation.

setParamMutationRate

public void setParamMutationRate(double paramMutationRate)
Set the mutation rate.

Parameters:
paramMutationRate - The mutation rate.

setParamNumAddLinkAttempts

public void setParamNumAddLinkAttempts(int paramNumAddLinkAttempts)
Set the number of attempts to add a link.

Parameters:
paramNumAddLinkAttempts - The number of attempts to add a link.

setParamNumGensAllowedNoImprovement

public void setParamNumGensAllowedNoImprovement(int paramNumGensAllowedNoImprovement)
Set the number of no-improvement generations allowed.

Parameters:
paramNumGensAllowedNoImprovement - The number of generations.

setParamNumTrysToFindLoopedLink

public void setParamNumTrysToFindLoopedLink(int paramNumTrysToFindLoopedLink)
Set the number of tries to create a looped link.

Parameters:
paramNumTrysToFindLoopedLink - Number of tries.

setParamNumTrysToFindOldLink

public void setParamNumTrysToFindOldLink(int paramNumTrysToFindOldLink)
Set the number of tries to try an old link.

Parameters:
paramNumTrysToFindOldLink - Number of tries.

setParamProbabilityWeightReplaced

public void setParamProbabilityWeightReplaced(double paramProbabilityWeightReplaced)
Set the probability to replace a weight.

Parameters:
paramProbabilityWeightReplaced - The probability.

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 © 2011. All Rights Reserved.