org.encog.neural.networks.training.neat
Class NEATTraining

java.lang.Object
  extended by org.encog.solve.genetic.GeneticAlgorithm
      extended by org.encog.neural.networks.training.neat.NEATTraining
All Implemented Interfaces:
Train

public class NEATTraining
extends GeneticAlgorithm
implements Train

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 score, BasicNetwork network, Population population)
          Construct a NEAT training object.
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 a predefined 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.
 NEATGenome crossover(NEATGenome mom, NEATGenome dad)
          Perform the crossover.
 void finishTraining()
          Called when training is done.
 EncogCloud getCloud()
           
 double getError()
          return The error for the best genome.
 NEATInnovationList getInnovations()
           
 int getInputCount()
           
 int getIteration()
           
 ActivationFunction getNeatActivationFunction()
           
 BasicNetwork getNetwork()
          Get the current best network from the training.
 ActivationFunction getOutputActivationFunction()
           
 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.
 NeuralDataSet 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.
 void resetAndKill()
          Reset for an iteration.
 void setCloud(EncogCloud cloud)
          Set the Encog cloud to use.
 void setError(double error)
          Not used.
 void setIteration(int iteration)
          Set the current training iteration.
 void setNeatActivationFunction(ActivationFunction neatActivationFunction)
          Set the NEAT activation, used by the NEAT neurons.
 void setOutputActivationFunction(ActivationFunction outputActivationFunction)
          Set the activatoin function for the Encog output layer.
 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.solve.genetic.GeneticAlgorithm
addSpeciesMember, calculateScore, getCalculateScore, getComparator, getCrossover, getMatingPopulation, getMutate, getMutationPercent, getPercentToMate, getPopulation, setCalculateScore, setComparator, setCrossover, setMatingPopulation, setMutate, setMutationPercent, setPercentToMate, setPopulation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NEATTraining

public NEATTraining(CalculateScore score,
                    BasicNetwork network,
                    Population population)
Construct a NEAT training object.

Parameters:
score - The score to calculate from.
network - The network to use as a model.
population - The population to train.

NEATTraining

public NEATTraining(CalculateScore calculateScore,
                    int inputCount,
                    int outputCount,
                    int populationSize)
Construct a neat trainer with a new population.

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 a predefined 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 Train
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.


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 Train

getCloud

public EncogCloud getCloud()
Specified by:
getCloud in interface Train
Returns:
The Encog cloud in use.

getError

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

Specified by:
getError in interface Train
Returns:
The current error.

getInnovations

public NEATInnovationList getInnovations()
Returns:
The innovations.

getInputCount

public int getInputCount()
Returns:
The input count.

getNeatActivationFunction

public ActivationFunction getNeatActivationFunction()
Returns:
The activation function to use with NEAT.

getNetwork

public BasicNetwork getNetwork()
Description copied from interface: Train
Get the current best network from the training.

Specified by:
getNetwork in interface Train
Returns:
A network created for the best genome.

getOutputActivationFunction

public ActivationFunction getOutputActivationFunction()
Returns:
The activation function to use with the Encog output layer.

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 Train
Returns:
The strategies in use(none).

getTraining

public NeuralDataSet getTraining()
Returns null, does not use a training set, rather uses a score function.

Specified by:
getTraining in interface Train
Returns:
null, not used.

isSnapshot

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

iteration

public void iteration()
Perform one training iteration.

Specified by:
iteration in interface Train
Overrides:
iteration in class GeneticAlgorithm

resetAndKill

public void resetAndKill()
Reset for an iteration.


setCloud

public void setCloud(EncogCloud cloud)
Set the Encog cloud to use.

Specified by:
setCloud in interface Train
Parameters:
cloud - The Encog cloud to use.

setError

public void setError(double error)
Not used.

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

setNeatActivationFunction

public void setNeatActivationFunction(ActivationFunction neatActivationFunction)
Set the NEAT activation, used by the NEAT neurons.

Parameters:
neatActivationFunction - The activation function.

setOutputActivationFunction

public void setOutputActivationFunction(ActivationFunction outputActivationFunction)
Set the activatoin function for the Encog output layer.

Parameters:
outputActivationFunction - The activation function.

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.

isTrainingDone

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

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 Train
Parameters:
count - The number of training iterations.

getIteration

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

setIteration

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

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


Copyright © 2011. All Rights Reserved.