Class GeneticProgram
java.lang.Object
org.episteme.core.mathematics.optimization.evolutionary.geneticprogramming.GeneticProgram
Genetic program implementation.
- Version:
- 0.1
- Author:
- Levent Bayindir
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int"Full" generation methodstatic final int"Grow" generation methodstatic final int"Ramped Half and Half" generation methodstatic final int"Fitness-Proportionate" seleciton methodstatic final int"Tournament" selection method -
Constructor Summary
ConstructorsConstructorDescriptionGeneticProgram(int populationSize, FitnessFunction fitnessFunction, Terminal[] terminalSet, Function[] functionSet) Creates a genetic program with given parameters.GeneticProgram(int populationSize, FitnessFunction fitnessFunction, Terminal[] terminalSet, Function[] functionSet, int generationMethod, int selectionMethod) Creates a genetic program with given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateArgumentsForFunction(Function function, int allowableDepth, boolean fullP) Creates arguments for the given functioncreateIndividualProgram(int allowableDepth, boolean topNodeP, boolean fullP) Creates an individual randomly with given pramatersvoidCreates the initial populationProgram[]Produces two new individuals by crossing over two parents.voidevolve()Evolves the population for one generationFinds an individual based on selection criteria used in this genetic programfindIndividualUsingFitnessProportionateSelection(double afterThisFitness) Finds an individual using fitness proportionate selectionFinds an individual using tournament selectiondoubleReturns the average adjusted fitness of the current generationdoubleReturns the average normalized fitness of the current generationdoubleReturns the average standardized fitness of the current generationReturns the best individual over all generationsReturns the best individual in the current generationdoubleReturns propability of crossover operationReturn fitness function used in this genetic programFunction[]Returns function set of this genetic programintReturns generation method used in this genetic programintReturns current generation numberintReturns the genereation number of the best individual over all generationsintReturns the maximum depth for the new individuals created by crossover operationintReturns the maximum depth for the new individualsintReturns the maximum depth for the new subtree created by mutation operationdoubleReturn propability of mutation operationReturns the individuals in the populationintReturns size of the populationReturns the random number generator used in this genetic programdoubleReturn propability of reproduction operationintReturns the selection method used in this genetic programTerminal[]Returns terminal set of this genetic programstatic booleanisFunction(Program program) Returns whether the given program is a function or notstatic booleanTeset a given argument is a program or notintmaxDepthOfTree(Program tree) Returns the depth of the deepest branch of the given tree.Mutates a given programSelects a function from terminal set randomlySelects a terminal from terminal set randomlyvoidsetBestIndividual(int individualNo) Changes the best individual of this populationvoidsetBestIndividualInCurrentGeneration(int individualNo) Changes the best individual of the current generationvoidsetCrossoverFraction(double newValue) Changes propability of crossover operationvoidsetFitnessFunction(FitnessFunction function) Changes the best individual of the current generationvoidsetFunctionSet(Function[] newSet) Changes function set of this genetic programvoidsetGenerationMethod(int newMethod) Changes generation method used in this genetic programvoidsetGenerationOfBestIndividual(int generation) Changes the generation number of the best individualvoidsetMaxDepthForIndividualAfterCrossover(int newDepth) Changes the maximum depth for the new individuals created by crossover operationvoidsetMaxDepthForNewIndividual(int newDepth) Changes the maximum depth for the new individualsvoidsetMaxDepthForNewSubtreeInMutant(int newDepth) Changes the maximum depth for the new subtree created by mutation operationvoidsetMutationFraction(double newValue) Changes propability of mutation operationvoidsetPopulationSize(int newSize) Changes the size of the populationvoidsetRandomNumberGenerator(Random randGenerator) Changes the random number generator used in this genetic programvoidsetReproductionFraction(double newValue) Changes the size of the populationvoidsetSelectionMethod(int newMethod) Changes selection method used in this genetic programvoidsetTerminalSet(Terminal[] newSet) Changes terminal set of this genetic program
-
Field Details
-
GENERATION_FULL
public static final int GENERATION_FULL"Full" generation method- See Also:
-
GENERATION_GROW
public static final int GENERATION_GROW"Grow" generation method- See Also:
-
GENERATION_RAMPED_HALF_AND_HALF
public static final int GENERATION_RAMPED_HALF_AND_HALF"Ramped Half and Half" generation method- See Also:
-
SELECTION_TOURNAMENT
public static final int SELECTION_TOURNAMENT"Tournament" selection method- See Also:
-
SELECTION_FITNESS_PROPORTIONATE
public static final int SELECTION_FITNESS_PROPORTIONATE"Fitness-Proportionate" seleciton method- See Also:
-
-
Constructor Details
-
GeneticProgram
public GeneticProgram(int populationSize, FitnessFunction fitnessFunction, Terminal[] terminalSet, Function[] functionSet, int generationMethod, int selectionMethod) Creates a genetic program with given parameters.- Parameters:
populationSize- size of the populationfitnessFunction- fitness function that will be used in this genetic programterminalSet- terminal set of this genetic programfunctionSet- function set of this genetic programgenerationMethod- generation method used in this genetic programselectionMethod- selection method used in this genetic program
-
GeneticProgram
public GeneticProgram(int populationSize, FitnessFunction fitnessFunction, Terminal[] terminalSet, Function[] functionSet) Creates a genetic program with given parameters.- Parameters:
populationSize- size of the populationfitnessFunction- fitness function that will be used in this genetic programterminalSet- terminal set of this genetic programfunctionSet- function set of this genetic program
-
-
Method Details
-
selectTerminal
Selects a terminal from terminal set randomly- Returns:
- selected terminal
-
selectFunction
Selects a function from terminal set randomly- Returns:
- selected function
-
createArgumentsForFunction
Creates arguments for the given function- Parameters:
function- function to create argumentsallowableDepth- remaining depth of the tree we can create when we hit zero we will only select terminals.fullP- indicates whether this individual is to be a full tree
-
createIndividualProgram
Creates an individual randomly with given pramaters- Parameters:
allowableDepth- remaining depth of the tree we can create when we hit zero we will only select terminals.topNodeP- is ture only when we are being called as the top node in the tree. This allows us to make sure that we always put a function at the top of the tree.fullP- indicates whether this individual is to be a full tree- Returns:
- created individual
-
createPopulation
public void createPopulation()Creates the initial population -
mutate
-
crossover
-
maxDepthOfTree
Returns the depth of the deepest branch of the given tree.- Parameters:
tree- tree to calculate the depth of the maximum branch- Returns:
- DOCUMENT ME!
-
findIndividual
Finds an individual based on selection criteria used in this genetic program- Returns:
- individual selected
-
findIndividualUsingTournamentSelection
Finds an individual using tournament selection- Returns:
- individual selected
-
findIndividualUsingFitnessProportionateSelection
Finds an individual using fitness proportionate selection- Parameters:
afterThisFitness- DOCUMENT ME!- Returns:
- individual selected
-
evolve
public void evolve()Evolves the population for one generation -
isProgram
Teset a given argument is a program or not- Parameters:
program- program to test whether it is a function or not- Returns:
- true if given argument is a program
-
isFunction
Returns whether the given program is a function or not- Parameters:
program- program to test whether it is a function or not- Returns:
- true if the given program is a function, else returns false
-
getBestIndividual
Returns the best individual over all generations- Returns:
- best individual so far
-
getGenerationOfBestIndividual
public int getGenerationOfBestIndividual()Returns the genereation number of the best individual over all generations- Returns:
- index of the generation that best individual over all generations.
-
getBestIndividualInCurrentGeneration
Returns the best individual in the current generation- Returns:
- best individual in the current generation
-
getAverageStandardizedFitnessOfCurrentGeneration
public double getAverageStandardizedFitnessOfCurrentGeneration()Returns the average standardized fitness of the current generation- Returns:
- average standardized fitness of the current generation
-
getAverageAdjustedFitnessOfCurrentGeneration
public double getAverageAdjustedFitnessOfCurrentGeneration()Returns the average adjusted fitness of the current generation- Returns:
- average adjusted fitness of the current generation
-
getAverageNormalizedFitnessOfCurrentGeneration
public double getAverageNormalizedFitnessOfCurrentGeneration()Returns the average normalized fitness of the current generation- Returns:
- average normalized fitness of the current generation
-
getRandomNumberGenerator
Returns the random number generator used in this genetic program- Returns:
- random number generator used in this genetic program
-
setRandomNumberGenerator
Changes the random number generator used in this genetic program- Parameters:
randGenerator- new random number generator
-
getPopulation
-
getGenerationNo
public int getGenerationNo()Returns current generation number- Returns:
- current generation number
-
getPopulationSize
public int getPopulationSize()Returns size of the population- Returns:
- size of the population
-
setPopulationSize
public void setPopulationSize(int newSize) Changes the size of the population- Parameters:
newSize- new size of the population
-
getMaxDepthForNewIndividual
public int getMaxDepthForNewIndividual()Returns the maximum depth for the new individuals- Returns:
- maximum depth for the new individuals
-
setMaxDepthForNewIndividual
public void setMaxDepthForNewIndividual(int newDepth) Changes the maximum depth for the new individuals- Parameters:
newDepth- new depth for the new individuals
-
getMaxDepthForIndividualAfterCrossover
public int getMaxDepthForIndividualAfterCrossover()Returns the maximum depth for the new individuals created by crossover operation- Returns:
- depth for the new individuals created by crossover operation
-
setMaxDepthForIndividualAfterCrossover
public void setMaxDepthForIndividualAfterCrossover(int newDepth) Changes the maximum depth for the new individuals created by crossover operation- Parameters:
newDepth- new value for the new individuals created by crossover operation
-
getMaxDepthForNewSubtreeInMutant
public int getMaxDepthForNewSubtreeInMutant()Returns the maximum depth for the new subtree created by mutation operation- Returns:
- maximum depth for the new subtree created by mutation operation
-
setMaxDepthForNewSubtreeInMutant
public void setMaxDepthForNewSubtreeInMutant(int newDepth) Changes the maximum depth for the new subtree created by mutation operation- Parameters:
newDepth- new value for the maximum depth for the new subtree created by mutation operation
-
getCrossoverFraction
public double getCrossoverFraction()Returns propability of crossover operation- Returns:
- propability of crossover operation
-
setCrossoverFraction
public void setCrossoverFraction(double newValue) Changes propability of crossover operation- Parameters:
newValue- new value for the propability of crossover operation
-
getMutationFraction
public double getMutationFraction()Return propability of mutation operation- Returns:
- propability of mutation operation
-
setMutationFraction
public void setMutationFraction(double newValue) Changes propability of mutation operation- Parameters:
newValue- new value for the propability of mutation operation
-
getReproductionFraction
public double getReproductionFraction()Return propability of reproduction operation- Returns:
- propability of reproduction operation
-
setReproductionFraction
public void setReproductionFraction(double newValue) Changes the size of the population- Parameters:
newValue- fraction for the reproduction genetic operator
-
getGenerationMethod
public int getGenerationMethod()Returns generation method used in this genetic program- Returns:
- generation method used in this genetic program
-
setGenerationMethod
public void setGenerationMethod(int newMethod) Changes generation method used in this genetic program- Parameters:
newMethod- new value of generation method used in this genetic program
-
getSelectionMethod
public int getSelectionMethod()Returns the selection method used in this genetic program- Returns:
- selection method used in this genetic program
-
setSelectionMethod
public void setSelectionMethod(int newMethod) Changes selection method used in this genetic program- Parameters:
newMethod- new selection method used in this genetic program
-
getTerminalSet
Returns terminal set of this genetic program- Returns:
- terminal set
-
setTerminalSet
Changes terminal set of this genetic program- Parameters:
newSet- new terminal set for the genetic program
-
getFunctionSet
Returns function set of this genetic program- Returns:
- function set
-
setFunctionSet
Changes function set of this genetic program- Parameters:
newSet- new function set for this genetic program
-
setBestIndividual
public void setBestIndividual(int individualNo) Changes the best individual of this population- Parameters:
individualNo- index of the best individual in the current population
-
setGenerationOfBestIndividual
public void setGenerationOfBestIndividual(int generation) Changes the generation number of the best individual- Parameters:
generation- generation of best individual
-
setBestIndividualInCurrentGeneration
public void setBestIndividualInCurrentGeneration(int individualNo) Changes the best individual of the current generation- Parameters:
individualNo- index of the best individual in the current population
-
getFitnessFunction
Return fitness function used in this genetic program- Returns:
- fitness function
-
setFitnessFunction
Changes the best individual of the current generation- Parameters:
function- new fitness function
-