org.encog.ml.prg.generator
Class AbstractPrgGenerator
- java.lang.Object
-
- org.encog.ml.prg.generator.AbstractPrgGenerator
-
- All Implemented Interfaces:
- PopulationGenerator, PrgGenerator, MultiThreadable
- Direct Known Subclasses:
- PrgFullGenerator, PrgGrowGenerator, RampedHalfAndHalf
public abstract class AbstractPrgGenerator extends java.lang.Object implements PrgGenerator, MultiThreadable
The abstract base for Full and Grow program generation.
-
-
Constructor Summary
Constructors Constructor and Description AbstractPrgGenerator(EncogProgramContext theContext, int theMaxDepth)Construct the generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddPopulationMember(PrgPopulation population, EncogProgram prg)Add a population member from one of the threads.EncogProgramattemptCreateGenome(java.util.Random rnd, Population pop)Attempt to create a genome.ProgramNodecreateRandomNode(java.util.Random rnd, EncogProgram program, int depthRemaining, java.util.List<ValueType> types, boolean includeTerminal, boolean includeFunction)Create a random note according to the specified paramaters.ProgramNodecreateTerminalNode(java.util.Random rnd, EncogProgram program, java.util.List<ValueType> types)Create a terminal node.intdetermineMaxDepth(java.util.Random rnd)EncogProgramgenerate(java.util.Random rnd)Generate a random genome.voidgenerate(java.util.Random rnd, Population pop)Generate a random population.ProgramExtensionTemplategenerateRandomOpcode(java.util.Random rnd, java.util.List<ProgramExtensionTemplate> opcodes)Generate a random opcode.EncogProgramContextgetContext()doublegetMaxConst()intgetMaxDepth()intgetMaxGenerationErrors()doublegetMinConst()RandomFactorygetRandomFactory()CalculateScoregetScore()intgetThreadCount()booleanisHasEnum()voidsetMaxConst(double maxConst)voidsetMaxGenerationErrors(int maxGenerationErrors)Set the maximum errors to allow during generation.voidsetMinConst(double minConst)voidsetRandomFactory(RandomFactory randomFactory)voidsetScore(CalculateScore score)voidsetThreadCount(int numThreads)Set the number of threads to use.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.encog.ml.prg.generator.PrgGenerator
createNode
-
-
-
-
Constructor Detail
-
AbstractPrgGenerator
public AbstractPrgGenerator(EncogProgramContext theContext, int theMaxDepth)
Construct the generator.- Parameters:
theContext- The context that is to be used for generation.theMaxDepth- The maximum depth to generate to.
-
-
Method Detail
-
addPopulationMember
public void addPopulationMember(PrgPopulation population, EncogProgram prg)
Add a population member from one of the threads.- Parameters:
population- The population to add to.prg- The program to add.
-
attemptCreateGenome
public EncogProgram attemptCreateGenome(java.util.Random rnd, Population pop)
Attempt to create a genome. Cycle the specified number of times if an error occurs.- Parameters:
rnd- The random number generator.pop- The population.- Returns:
- The generated genome.
-
createRandomNode
public ProgramNode createRandomNode(java.util.Random rnd, EncogProgram program, int depthRemaining, java.util.List<ValueType> types, boolean includeTerminal, boolean includeFunction)
Create a random note according to the specified paramaters.- Parameters:
rnd- A random number generator.program- The program to generate for.depthRemaining- The depth remaining to generate.types- The types to generate.includeTerminal- Should we include terminal nodes.includeFunction- Should we include function nodes.- Returns:
- The generated program node.
-
createTerminalNode
public ProgramNode createTerminalNode(java.util.Random rnd, EncogProgram program, java.util.List<ValueType> types)
Create a terminal node.- Parameters:
rnd- A random number generator.program- The program to generate for.types- The types that we might generate.- Returns:
- The terminal program node.
-
determineMaxDepth
public int determineMaxDepth(java.util.Random rnd)
-
generate
public EncogProgram generate(java.util.Random rnd)
Generate a random genome.- Specified by:
generatein interfacePopulationGenerator- Parameters:
rnd- A random number generator.- Returns:
- A random genome.
-
generate
public void generate(java.util.Random rnd, Population pop)Generate a random population.- Specified by:
generatein interfacePopulationGenerator- Parameters:
rnd- Random number generator.pop- The population to generate into.
-
generateRandomOpcode
public ProgramExtensionTemplate generateRandomOpcode(java.util.Random rnd, java.util.List<ProgramExtensionTemplate> opcodes)
Generate a random opcode.- Parameters:
rnd- Random number generator.opcodes- The opcodes to choose from.- Returns:
- The selected opcode.
-
getContext
public EncogProgramContext getContext()
- Returns:
- the context
-
getMaxConst
public double getMaxConst()
- Returns:
- the maxConst
-
getMaxDepth
public int getMaxDepth()
- Returns:
- the maxDepth
-
getMaxGenerationErrors
public int getMaxGenerationErrors()
- Specified by:
getMaxGenerationErrorsin interfacePrgGenerator- Returns:
- the maxGenerationErrors
-
getMinConst
public double getMinConst()
- Returns:
- the minConst
-
getRandomFactory
public RandomFactory getRandomFactory()
- Returns:
- the randomFactory
-
getScore
public CalculateScore getScore()
- Returns:
- the score
-
getThreadCount
public int getThreadCount()
- Specified by:
getThreadCountin interfaceMultiThreadable- Returns:
- The desired number of threads.
-
isHasEnum
public boolean isHasEnum()
- Returns:
- the hasEnum
-
setMaxConst
public void setMaxConst(double maxConst)
- Parameters:
maxConst- the maxConst to set
-
setMaxGenerationErrors
public void setMaxGenerationErrors(int maxGenerationErrors)
Description copied from interface:PrgGeneratorSet the maximum errors to allow during generation.- Specified by:
setMaxGenerationErrorsin interfacePrgGenerator- Parameters:
maxGenerationErrors- the maxGenerationErrors to set
-
setMinConst
public void setMinConst(double minConst)
- Parameters:
minConst- the minConst to set
-
setRandomFactory
public void setRandomFactory(RandomFactory randomFactory)
- Parameters:
randomFactory- the randomFactory to set
-
setScore
public void setScore(CalculateScore score)
- Parameters:
score- the score to set
-
setThreadCount
public void setThreadCount(int numThreads)
Description copied from interface:MultiThreadableSet the number of threads to use.- Specified by:
setThreadCountin interfaceMultiThreadable- Parameters:
numThreads- The desired thread count.
-
-
DMelt 3.0 © DataMelt by jWork.ORG