org.jscience.computing.ai.evolutionary.geneticprogramming
Class GeneticProgram

java.lang.Object
  extended by org.jscience.computing.ai.evolutionary.geneticprogramming.GeneticProgram

public class GeneticProgram
extends java.lang.Object

Genetic program implementation.


Field Summary
static int GENERATION_FULL
          "Full" generation method
static int GENERATION_GROW
          "Grow" generation method
static int GENERATION_RAMPED_HALF_AND_HALF
          "Ramped Half and Half" generation method
static int SELECTION_FITNESS_PROPORTIONATE
          "Fitness-Proportionate" seleciton method
static int SELECTION_TOURNAMENT
          "Tournament" selection method
 
Constructor Summary
GeneticProgram(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
 void createArgumentsForFunction(Function function, int allowableDepth, boolean fullP)
          Creates arguments for the given function
 Program createIndividualProgram(int allowableDepth, boolean topNodeP, boolean fullP)
          Creates an individual randomly with given pramaters
 void createPopulation()
          Creates the initial population
 Program[] crossover(Program male, Program female)
          Produces two new individuals by crossing over two parents.
 void evolve()
          Evolves the population for one generation
 Individual findIndividual()
          Finds an individual based on selection criteria used in this genetic program
 Individual findIndividualUsingFitnessProportionateSelection(double afterThisFitness)
          Finds an individual using fitness proportionate selection
 Individual findIndividualUsingTournamentSelection()
          Finds an individual using tournament selection
 double getAverageAdjustedFitnessOfCurrentGeneration()
          Returns the average adjusted fitness of the current generation
 double getAverageNormalizedFitnessOfCurrentGeneration()
          Returns the average normalized fitness of the current generation
 double getAverageStandardizedFitnessOfCurrentGeneration()
          Returns the average standardized fitness of the current generation
 Individual getBestIndividual()
          Returns the best individual over all generations
 Individual getBestIndividualInCurrentGeneration()
          Returns the best individual in the current generation
 double getCrossoverFraction()
          Returns propability of crossover operation
 FitnessFunction getFitnessFunction()
          Return fitness function used in this genetic program
 Function[] getFunctionSet()
          Returns function set of this genetic program
 int getGenerationMethod()
          Returns generation method used in this genetic program
 int getGenerationNo()
          Returns current generation number
 int getGenerationOfBestIndividual()
          Returns the genereation number of the best individual over all generations
 int getMaxDepthForIndividualAfterCrossover()
          Returns the maximum depth for the new individuals created by crossover operation
 int getMaxDepthForNewIndividual()
          Returns the maximum depth for the new individuals
 int getMaxDepthForNewSubtreeInMutant()
          Returns the maximum depth for the new subtree created by mutation operation
 double getMutationFraction()
          Return propability of mutation operation
 Individual[] getPopulation()
          Returns the individuals in the population
 int getPopulationSize()
          Returns size of the population
 java.util.Random getRandomNumberGenerator()
          Returns the random number generator used in this genetic program
 double getReproductionFraction()
          Return propability of reproduction operation
 int getSelectionMethod()
          Returns the selection method used in this genetic program
 Terminal[] getTerminalSet()
          Returns terminal set of this genetic program
static boolean isFunction(Program program)
          Returns whether the given program is a function or not
static boolean isProgram(Program program)
          Teset a given argument is a program or not
 int maxDepthOfTree(Program tree)
          Returns the depth of the deepest branch of the given tree.
 Program mutate(Program program)
          Mutates a given program
 Function selectFunction()
          Selects a function from terminal set randomly
 Terminal selectTerminal()
          Selects a terminal from terminal set randomly
 void setBestIndividual(int individualNo)
          Changes the best individual of this population
 void setBestIndividualInCurrentGeneration(int individualNo)
          Changes the best individual of the current generation
 void setCrossoverFraction(double newValue)
          Changes propability of crossover operation
 void setFitnessFunction(FitnessFunction function)
          Changes the best individual of the current generation
 void setFunctionSet(Function[] newSet)
          Changes function set of this genetic program
 void setGenerationMethod(int newMethod)
          Changes generation method used in this genetic program
 void setGenerationOfBestIndividual(int generation)
          Changes the generation number of the best individual
 void setMaxDepthForIndividualAfterCrossover(int newDepth)
          Changes the maximum depth for the new individuals created by crossover operation
 void setMaxDepthForNewIndividual(int newDepth)
          Changes the maximum depth for the new individuals
 void setMaxDepthForNewSubtreeInMutant(int newDepth)
          Changes the maximum depth for the new subtree created by mutation operation
 void setMutationFraction(double newValue)
          Changes propability of mutation operation
 void setPopulationSize(int newSize)
          Changes the size of the population
 void setRandomNumberGenerator(java.util.Random randGenerator)
          Changes the random number generator used in this genetic program
 void setReproductionFraction(double newValue)
          Changes the size of the population
 void setSelectionMethod(int newMethod)
          Changes selection method used in this genetic program
 void setTerminalSet(Terminal[] newSet)
          Changes terminal set of this genetic program
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERATION_FULL

public static final int GENERATION_FULL
"Full" generation method

See Also:
Constant Field Values

GENERATION_GROW

public static final int GENERATION_GROW
"Grow" generation method

See Also:
Constant Field Values

GENERATION_RAMPED_HALF_AND_HALF

public static final int GENERATION_RAMPED_HALF_AND_HALF
"Ramped Half and Half" generation method

See Also:
Constant Field Values

SELECTION_TOURNAMENT

public static final int SELECTION_TOURNAMENT
"Tournament" selection method

See Also:
Constant Field Values

SELECTION_FITNESS_PROPORTIONATE

public static final int SELECTION_FITNESS_PROPORTIONATE
"Fitness-Proportionate" seleciton method

See Also:
Constant Field Values
Constructor Detail

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 population
fitnessFunction - fitness function that will be used in this genetic program
terminalSet - terminal set of this genetic program
functionSet - function set of this genetic program
generationMethod - generation method used in this genetic program
selectionMethod - 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 population
fitnessFunction - fitness function that will be used in this genetic program
terminalSet - terminal set of this genetic program
functionSet - function set of this genetic program
Method Detail

selectTerminal

public Terminal selectTerminal()
Selects a terminal from terminal set randomly

Returns:
selected terminal

selectFunction

public Function selectFunction()
Selects a function from terminal set randomly

Returns:
selected function

createArgumentsForFunction

public void createArgumentsForFunction(Function function,
                                       int allowableDepth,
                                       boolean fullP)
Creates arguments for the given function

Parameters:
function - function to create arguments
allowableDepth - 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

public Program createIndividualProgram(int allowableDepth,
                                       boolean topNodeP,
                                       boolean fullP)
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

public Program mutate(Program program)
Mutates a given program

Parameters:
program - program to mutate
Returns:
mutated program

crossover

public Program[] crossover(Program male,
                           Program female)
Produces two new individuals by crossing over two parents.

Parameters:
male - first parent program
female - second parent program
Returns:
offsprings

maxDepthOfTree

public int maxDepthOfTree(Program tree)
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

public Individual findIndividual()
Finds an individual based on selection criteria used in this genetic program

Returns:
individual selected

findIndividualUsingTournamentSelection

public Individual findIndividualUsingTournamentSelection()
Finds an individual using tournament selection

Returns:
individual selected

findIndividualUsingFitnessProportionateSelection

public Individual findIndividualUsingFitnessProportionateSelection(double afterThisFitness)
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

public static boolean isProgram(Program program)
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

public static boolean isFunction(Program program)
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

public Individual 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

public Individual 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

public java.util.Random getRandomNumberGenerator()
Returns the random number generator used in this genetic program

Returns:
random number generator used in this genetic program

setRandomNumberGenerator

public void setRandomNumberGenerator(java.util.Random randGenerator)
Changes the random number generator used in this genetic program

Parameters:
randGenerator - new random number generator

getPopulation

public Individual[] getPopulation()
Returns the individuals in the population

Returns:
individuals

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

public Terminal[] getTerminalSet()
Returns terminal set of this genetic program

Returns:
terminal set

setTerminalSet

public void setTerminalSet(Terminal[] newSet)
Changes terminal set of this genetic program

Parameters:
newSet - new terminal set for the genetic program

getFunctionSet

public Function[] getFunctionSet()
Returns function set of this genetic program

Returns:
function set

setFunctionSet

public void setFunctionSet(Function[] newSet)
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

public FitnessFunction getFitnessFunction()
Return fitness function used in this genetic program

Returns:
fitness function

setFitnessFunction

public void setFitnessFunction(FitnessFunction function)
Changes the best individual of the current generation

Parameters:
function - new fitness function