geneticWedge.gp
Class Population

java.lang.Object
  extended by geneticWedge.gp.AbstractPopulation
      extended by geneticWedge.gp.Population
Direct Known Subclasses:
DemicPopulation, PopulationV

public class Population
extends AbstractPopulation

Population is the standard Population class. A Population contains a number of Individuals and holds information about the population as a whole such as average fitness. A Population may be evolved by calling the evolve() method.


Nested Class Summary
static class Population.PerformanceFunction
          PerformanceFunctions are used to create multi-objective evaluation functions.
 
Nested classes/interfaces inherited from class geneticWedge.gp.AbstractPopulation
AbstractPopulation.FitnessFunction, AbstractPopulation.SelectionMethod
 
Field Summary
protected  int evolutionNumber
           
protected  boolean printInfo
           
 
Fields inherited from class geneticWedge.gp.AbstractPopulation
allFitnesses, aurocSampleSize, averageTrainFitness, averageValidationFitness, bestIndex, bestTrainFitness, bestTrainFitnessSoFar, bestValidationFitness, bestValidationFitnessSoFar, fitnessFunction, generationNumber, maxGenerations, popDescriptor, popSize, recFitnessFunction, startingPopSize, tournamentSize
 
Constructor Summary
Population(int populationSize, PopulationDescriptor descriptor)
          The Population constructor takes the population size and a PopulationDescriptor as variables.
 
Method Summary
 void collectTransmissionInfo(boolean collect)
          If set to true, information concerning the relationship between parents and offspring will be saved.
 boolean evolve(boolean steadyState, AbstractPopulation.SelectionMethod selectMethod, double[][] inputs, double[] targetOutputs, double[][] validationInputs, double[] validationTargetOutputs, StoppingCriterion stopCriterion)
          If this method is called in steadyState mode with a selectMethod that uses roulette wheel selection (FITNESS_PROPORTIONAL, RANK or FUSS), elitist selection will not occur, even if an elite size has been set.
 boolean evolve(boolean steadyState, double[][] inputs, double[] targetOutputs, double[][] validationInputs, double[] validationTargetOutputs, StoppingCriterion stopCriterion)
          If this method is called, the selection method will be deduced from the value of steadyState.
protected  void evolveOneGeneration(boolean steadyState, AbstractPopulation.SelectionMethod selectMethod, double[][] inputs, double[] targetOutputs)
           
 java.util.Vector<double[]> getAllCutDepthCorrelations()
          This method may be used if transmission information has been collected.
 double[][] getAllSquaredDistances(boolean recalculate)
          Returns a 2-D array containing the 'distances' between pairs of Individuals, in the 'upper right' sector (above the leading diagonal).
 double getAverageComplexity()
          Returns the average function complexity of all Individuals within the population.
 double[] getAverageCutDepthCorrelation()
          This method may be used if transmission information has been collected.
 double getAverageFitness(double[][] inputs, double[] targetOutputs, boolean recalculateValues)
          Returns the average fitness of all Individual on the data provided.
 double getAverageIndividualLength()
          Returns the average length (number of nodes) of all Individuals in this Population.
 double getAverageSquaredDistance(Individual ind)
          Obtains the average distance between ind and the Population's current members
 double getAverageSquaredDistance(int index)
          Returns the average squared distance between the Individual denoted by index and all other members of the population.
 double getAverageSquaredDistance(int index, Individual newInd)
          Obtains the average distance that would occur if the new Individual were to replace the Individual currently at index index.
 double getAverageTrainingFitness()
          Returns the average fitness of all Individuals on the training data.
 double getAverageValidationFitness()
          Returns the average fitness of all Individuals on the validation data.
 Individual getBestIndividual()
          Returns the best Individual on the training data.
 double getBestTrainingFitness()
          Returns the fitness of the best Individual on the training data.
 Individual getBestValidatedIndividual()
          This method will return null if no evolution has occurred (because no validation has been performed) or if a validation set was not provided or a validation criterion was not used.
 double getBestValidationFitness()
          Returns the fitness of the best Individual on the validation data.
 boolean getBroodUse()
          If set to true, brood recombination will be used during crossover
 Crossover getCrossover()
          Returns the Crossover object to be used by this Population.
 double getDiversity()
          getDiversity() counts the number of different Individuals in the Population, subtracts 1 and divides by (population size - 1).
 double[] getFitnesses()
          This method should only be called after evolving the population.
 AbstractPopulation.FitnessFunction getFitnessFunction()
          Returns the FitnessFunction used to evaluate Individuals within this Population.
 FitnessShare getFitnessShare()
          Returns the fitness share object.
 Individual[] getIndividuals()
           
 boolean getKeepDominated()
          If set to true, the Population size will be maintained when using a multi-objective evaluation function (PerformanceFunctions).
 int getMaximumIndividualDepth()
          Retruns the maximum depth of an Individual created by crossover or mutation.
 int getMaximumIndividualLength()
          Returns the maximum length of an Individual created by crossover or mutation.
 boolean getMultiObjective()
          If true, and PerformanceFunctions have been applied, multi-objective (Pareto-style) selection will occur.
 Mutation getMutation()
          Returns the Mutation object to be used by this Population.
 Population.PerformanceFunction[] getPerformanceFunctions()
          Returns an array of the PerformanceFunctions used in selecting Individuals.
 double getRankGradient()
          Returns the rank gradient to be used during RANK selection.
 FitnessShare.ShareType getShareType()
          Returns the fitness type.
 double[] getShareWeightings()
          Returns the share weightings.
 double[][] getSquaredDistances(int[] indices, boolean recalculate)
          Returns the distances between selected Individuals in the Population, denoted by their indices, and all other members of the Population.
 java.util.Vector<java.util.Vector<double[]>> getTransmissionInfo()
          Returns a vector containing transmission information concerning the relationships between parents and offspring
 boolean hasNoDiversity()
           
protected  void removeDominatedIndividuals()
           
protected  void removeDuplicatedIndividuals()
           
protected  void savePopulation()
           
 void setBroodUse(boolean useBrood)
          If set to true, brood recombination will be used during crossover
 void setCrossover(Crossover newCross)
          Sets the Crossover object to be used by this Population.
 void setFitnessFunction(AbstractPopulation.FitnessFunction func)
          Sets the FitnessFunction used to evaluate Individuals within this Population.
 void setFitnessShare(FitnessShare fitnessShare, FitnessShare.ShareType shareType)
          Fitness sharing aims to prevent Individuals within a small niche from dominating the Population.
 void setKeepDominated(boolean keepDominated)
          If set to true, the Population size will be maintained when using a multi-objective evaluation function (PerformanceFunctions).
 void setMaximumIndividualDepth(int maxDepth)
          Setting a low maximumIndividualDepth is a way of controlling bloat.
 void setMaximumIndividualLength(int maxLength)
          Setting a low maximumIndividualLength is a way of controlling bloat.
 void setMutation(Mutation newMut)
          Sets the Mutation object to be used by this Population.
 void setPerformanceFunctions(Population.PerformanceFunction[] perfFuncs, boolean isMultiObjective)
          Sets the PerformanceFunctions used to evaluate Individuals within this Population.
 void setPrintStatus(boolean status)
          If printInfo is set to true, Population will print information concerning it's current status to the 'out' stream during evolution.
 void setRankGradient(double gradient)
          Sets the rank gradient to be used during RANK selection.
 void setShareWeightings(double[] weightings, boolean isMultiObjectivelyShared)
          Sets the share weightings.
 boolean setSingleObjectiveRatio(double[] ratio)
          Sets the weightings of performanceFunctions.
 void setTransmissionWritingParameters(int frequency, java.lang.String transmissionInfoFile)
          Sets parameters for saving transmission information (if used).
 void setTruncationParameters(boolean includeParentsInPool, int numberOfParents, int numberOfOffspring)
          Sets parameters to be used during TRUNCATION selection.
 java.lang.Object[] ShellSortIndividuals()
          This method returns an Object array.
 java.lang.Object[] ShellSortIndividuals(double[] objectiveData, boolean sortAscending)
          This method returns an Object array.
static java.lang.Object[] ShellSortIndividuals(Individual[] individuals, double[] allFitnesses, AbstractPopulation.FitnessFunction fitnessFunction)
          This method uses the Shell sort algorithm to order an array of Individuals according to theoir fitness.
static java.lang.Object[] ShellSortIndividuals(Individual[] individuals, double[] allFitnesses, boolean sortAscending)
          This method uses the Shell sort algorithm to order an array of Individuals according to theoir fitness.
 
Methods inherited from class geneticWedge.gp.AbstractPopulation
getAUROCSampleSize, getGenerationNumber, getInitialPopulationSize, getMaxGenerations, getPopulationDescriptor, getPopulationSize, getRECFitnessFunction, getTournamentSize, setAUROCSampleSize, setMaxGenerations, setRECFitnessFunction, setTournamentSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printInfo

protected boolean printInfo

evolutionNumber

protected int evolutionNumber
Constructor Detail

Population

public Population(int populationSize,
                  PopulationDescriptor descriptor)
The Population constructor takes the population size and a PopulationDescriptor as variables.

Method Detail

setPrintStatus

public void setPrintStatus(boolean status)
If printInfo is set to true, Population will print information concerning it's current status to the 'out' stream during evolution.


getIndividuals

public Individual[] getIndividuals()

evolve

public boolean evolve(boolean steadyState,
                      double[][] inputs,
                      double[] targetOutputs,
                      double[][] validationInputs,
                      double[] validationTargetOutputs,
                      StoppingCriterion stopCriterion)
If this method is called, the selection method will be deduced from the value of steadyState. If true, the selection method will be set to TOURNAMENT. If false the selection method will be set to FITNESS_PROPORTIONAL.


evolve

public boolean evolve(boolean steadyState,
                      AbstractPopulation.SelectionMethod selectMethod,
                      double[][] inputs,
                      double[] targetOutputs,
                      double[][] validationInputs,
                      double[] validationTargetOutputs,
                      StoppingCriterion stopCriterion)
If this method is called in steadyState mode with a selectMethod that uses roulette wheel selection (FITNESS_PROPORTIONAL, RANK or FUSS), elitist selection will not occur, even if an elite size has been set. In order to acieve elitist selection with these methods, generational evolution must be applied.


evolveOneGeneration

protected void evolveOneGeneration(boolean steadyState,
                                   AbstractPopulation.SelectionMethod selectMethod,
                                   double[][] inputs,
                                   double[] targetOutputs)

collectTransmissionInfo

public void collectTransmissionInfo(boolean collect)
If set to true, information concerning the relationship between parents and offspring will be saved.


setTransmissionWritingParameters

public void setTransmissionWritingParameters(int frequency,
                                             java.lang.String transmissionInfoFile)
Sets parameters for saving transmission information (if used).

Parameters:
frequency - The frequency with which transmission information is saved (in number of evaluations)
transmissionInfoFile - A pathname describing the file to which transmission information should be written

getTransmissionInfo

public java.util.Vector<java.util.Vector<double[]>> getTransmissionInfo()
Returns a vector containing transmission information concerning the relationships between parents and offspring


getAverageCutDepthCorrelation

public double[] getAverageCutDepthCorrelation()
This method may be used if transmission information has been collected. It returns the average correlation between the depth at which crossover occurs and the log of the ratio of the parent and offspring fitnesses.


getAllCutDepthCorrelations

public java.util.Vector<double[]> getAllCutDepthCorrelations()
This method may be used if transmission information has been collected. It returns the correlations between the depth at which crossover occurs and the log of the ratio of the parent and offspring fitnesses.


ShellSortIndividuals

public java.lang.Object[] ShellSortIndividuals()
This method returns an Object array. The first element in the array is a copy of this Population's Individuals, sorted into order from better to worse fitness. The second element is an array containing the corresponding training fitnesses. The third array contains the original indices of the Individuals


ShellSortIndividuals

public java.lang.Object[] ShellSortIndividuals(double[] objectiveData,
                                               boolean sortAscending)
This method returns an Object array. The first element in the array is a copy of this Population's Individuals, sorted into order from better to worse fitness. The second element is an array containing the corresponding training fitnesses. The third array contains the original indices of the Individuals


ShellSortIndividuals

public static java.lang.Object[] ShellSortIndividuals(Individual[] individuals,
                                                      double[] allFitnesses,
                                                      AbstractPopulation.FitnessFunction fitnessFunction)
This method uses the Shell sort algorithm to order an array of Individuals according to theoir fitness. The Object array returned contains 3 arrays: the Individuals in the correct order, the corresponding fitnesses and the indices of the original array in order of fitness (best to worst). Note: individuals, popSize and allFitnesses are LOCAL variables, allowing the sorting of any Individual[].


ShellSortIndividuals

public static java.lang.Object[] ShellSortIndividuals(Individual[] individuals,
                                                      double[] allFitnesses,
                                                      boolean sortAscending)
This method uses the Shell sort algorithm to order an array of Individuals according to theoir fitness. The Object array returned contains 3 arrays: the Individuals in the correct order, the corresponding fitnesses and the indices of the original array in order of fitness. Note: individuals, popSize and allFitnesses are LOCAL variables, allowing the sorting of any Individual[].

Parameters:
sortAscending - If true, the Individuals will be sorted from low to high fitness, if false they will be sorted from high to low. The value chosen for sortAscending may be different for different fitness functions: for some fitness functions low fitnesses are preferrred; for others high fitnesses are preferred.

getBestTrainingFitness

public double getBestTrainingFitness()
Returns the fitness of the best Individual on the training data.

Specified by:
getBestTrainingFitness in class AbstractPopulation

getBestValidationFitness

public double getBestValidationFitness()
Returns the fitness of the best Individual on the validation data.

Specified by:
getBestValidationFitness in class AbstractPopulation

getAverageTrainingFitness

public double getAverageTrainingFitness()
Returns the average fitness of all Individuals on the training data.

Specified by:
getAverageTrainingFitness in class AbstractPopulation

getAverageValidationFitness

public double getAverageValidationFitness()
Returns the average fitness of all Individuals on the validation data.

Specified by:
getAverageValidationFitness in class AbstractPopulation

getAverageFitness

public double getAverageFitness(double[][] inputs,
                                double[] targetOutputs,
                                boolean recalculateValues)
                         throws InvalidInputSizeException
Returns the average fitness of all Individual on the data provided. If recalculateValues is false this method simply returns the average training fitness.

Throws:
InvalidInputSizeException

setMaximumIndividualLength

public void setMaximumIndividualLength(int maxLength)
Setting a low maximumIndividualLength is a way of controlling bloat. However, if a very low value is set, there may be too much bias towards small programs, leading to loss of diversity. The default value is 250 nodes.


getMaximumIndividualLength

public int getMaximumIndividualLength()
Returns the maximum length of an Individual created by crossover or mutation. Setting a low maximumIndividualLength is a way of controlling bloat. However, if a very low value is set, there may be too much bias towards small programs, leading to loss of diversity. The default value is 250 nodes.


setMaximumIndividualDepth

public void setMaximumIndividualDepth(int maxDepth)
Setting a low maximumIndividualDepth is a way of controlling bloat. However, if a very low value is set, there may be too much bias towards small programs, leading to loss of diversity. The default value is 17.


getMaximumIndividualDepth

public int getMaximumIndividualDepth()
Retruns the maximum depth of an Individual created by crossover or mutation. Setting a low maximumIndividualDepth is a way of controlling bloat. However, if a very low value is set, there may be too much bias towards small programs, leading to loss of diversity. The default value is 17.


getAverageIndividualLength

public double getAverageIndividualLength()
Returns the average length (number of nodes) of all Individuals in this Population.


getDiversity

public double getDiversity()
getDiversity() counts the number of different Individuals in the Population, subtracts 1 and divides by (population size - 1). This results in a diversity of 1.0 if all Individuals are different and a diversity of 0.0 if all Individuals are the same.


hasNoDiversity

public boolean hasNoDiversity()

getBestIndividual

public Individual getBestIndividual()
Returns the best Individual on the training data. This method should only be called after evolving the Population. Otherwise, the best Individual will not have been calculated.


getBestValidatedIndividual

public Individual getBestValidatedIndividual()
This method will return null if no evolution has occurred (because no validation has been performed) or if a validation set was not provided or a validation criterion was not used.


setRankGradient

public void setRankGradient(double gradient)
Sets the rank gradient to be used during RANK selection. A higher gradient will lead to a greater probability of selecting fitter Individuals. The default gradient is 1.0.


getRankGradient

public double getRankGradient()
Returns the rank gradient to be used during RANK selection. A higher gradient will lead to a greater probability of selecting fitter Individuals. The default gradient is 1.0.


setBroodUse

public void setBroodUse(boolean useBrood)
If set to true, brood recombination will be used during crossover


getBroodUse

public boolean getBroodUse()
If set to true, brood recombination will be used during crossover


setKeepDominated

public void setKeepDominated(boolean keepDominated)
If set to true, the Population size will be maintained when using a multi-objective evaluation function (PerformanceFunctions). Individuals will be selected on the basis of dominance ranking, i.e. a count of the number of other Individuals by which a particular Individual is dominated. If false, all non-dominated Individuals will be kept in a Population, leading to fluctuations in Population size.


getKeepDominated

public boolean getKeepDominated()
If set to true, the Population size will be maintained when using a multi-objective evaluation function (PerformanceFunctions). Individuals will be selected on the basis of dominance ranking, i.e. a count of the number of other Individuals by which a particular Individual is dominated. If false, all non-dominated Individuals will be kept in a Population, leading to fluctuations in Population size.


setTruncationParameters

public void setTruncationParameters(boolean includeParentsInPool,
                                    int numberOfParents,
                                    int numberOfOffspring)
Sets parameters to be used during TRUNCATION selection.


getFitnesses

public double[] getFitnesses()
This method should only be called after evolving the population. Otherwise, fitness values will not have been calculated.


getFitnessFunction

public AbstractPopulation.FitnessFunction getFitnessFunction()
Returns the FitnessFunction used to evaluate Individuals within this Population.


setFitnessFunction

public void setFitnessFunction(AbstractPopulation.FitnessFunction func)
Sets the FitnessFunction used to evaluate Individuals within this Population.


setPerformanceFunctions

public void setPerformanceFunctions(Population.PerformanceFunction[] perfFuncs,
                                    boolean isMultiObjective)
Sets the PerformanceFunctions used to evaluate Individuals within this Population. PerformanceFunctions allow the incorporation of additional objectives into the objective function. They include program length, program diversity and program complexity (number of higher order Functions). If isMultiObjective is true, a Pareto approach will be taken in selecting Individuals. If false, a weighted combination of the FitnessFunction and the PerformanceFunctions will be used as a single objective (see setSingleObjectiveRatio).


setSingleObjectiveRatio

public boolean setSingleObjectiveRatio(double[] ratio)
Sets the weightings of performanceFunctions. All values are relative to a value of 1.0 for the FitnessFunction. This ratio will be ignored if isMultiObjective has been set to true by setPerformanceFunction.


getPerformanceFunctions

public Population.PerformanceFunction[] getPerformanceFunctions()
Returns an array of the PerformanceFunctions used in selecting Individuals. If no PerformanceFunctions have been applied this method returns null.


getMultiObjective

public boolean getMultiObjective()
If true, and PerformanceFunctions have been applied, multi-objective (Pareto-style) selection will occur. In other words, selection based on dominance ranking.


setCrossover

public void setCrossover(Crossover newCross)
Sets the Crossover object to be used by this Population.


getCrossover

public Crossover getCrossover()
Returns the Crossover object to be used by this Population.


setMutation

public void setMutation(Mutation newMut)
Sets the Mutation object to be used by this Population.


getMutation

public Mutation getMutation()
Returns the Mutation object to be used by this Population.


getAverageComplexity

public double getAverageComplexity()
Returns the average function complexity of all Individuals within the population. Individuals with a high function complexity are those which contain more 'complex' functions such as exp or pow


getAllSquaredDistances

public final double[][] getAllSquaredDistances(boolean recalculate)
Returns a 2-D array containing the 'distances' between pairs of Individuals, in the 'upper right' sector (above the leading diagonal).


getSquaredDistances

public final double[][] getSquaredDistances(int[] indices,
                                            boolean recalculate)
Returns the distances between selected Individuals in the Population, denoted by their indices, and all other members of the Population. The returned array has dimensions indices.length() - by - popSize.


getAverageSquaredDistance

public double getAverageSquaredDistance(int index)
Returns the average squared distance between the Individual denoted by index and all other members of the population.


getAverageSquaredDistance

public double getAverageSquaredDistance(int index,
                                        Individual newInd)
Obtains the average distance that would occur if the new Individual were to replace the Individual currently at index index.


getAverageSquaredDistance

public double getAverageSquaredDistance(Individual ind)
Obtains the average distance between ind and the Population's current members


setFitnessShare

public void setFitnessShare(FitnessShare fitnessShare,
                            FitnessShare.ShareType shareType)
Fitness sharing aims to prevent Individuals within a small niche from dominating the Population. The fitness of an Individual is deivided by a factor, which is determined by the number of other Individuals within a niche near to that Individual.

Parameters:
fitnessShare - The FitnessSahre object that determines how fitness sharing will operate.
shareType - determines whether fitness sharing will occur over the genotype (tree structural similarity) or the phenotype (fitness)

getFitnessShare

public FitnessShare getFitnessShare()
Returns the fitness share object. Returns null if fitness sharing is not implemented.


getShareType

public FitnessShare.ShareType getShareType()
Returns the fitness type. Returns null if fitness sharing is not implemented.


setShareWeightings

public void setShareWeightings(double[] weightings,
                               boolean isMultiObjectivelyShared)
Sets the share weightings. If sharing and multi-objective performance functions are both implemented, share weightings are used to determine the share factors. Performance functions with a high share weighting will be shared to a greater extent, leading to greater diversity in this functions.


getShareWeightings

public double[] getShareWeightings()
Returns the share weightings. If sharing and multi-objective performance functions are both implemented, share weightings are used to determine the share factors. Performance functions with a high share weighting will be shared to a greater extent, leading to greater diversity in this functions.


removeDominatedIndividuals

protected void removeDominatedIndividuals()

removeDuplicatedIndividuals

protected void removeDuplicatedIndividuals()

savePopulation

protected void savePopulation()