|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--gap.GPPopulation
A population of GPPrograms.
| Field Summary | |
static int |
ADF_EXCL
Used in methods with a "mask" argument. |
GPProgram |
bestOfRun
Best individual since the creation of the population. |
double |
bestOfRunFitness
Fitness of the individual since the creation of the population. |
static int |
EMPTY_MASK
Used in methods with a "mask" argument. |
double[] |
fitness
The adjusted fitness for each individual. |
Evaluator |
judge
The fitness evaluator. |
LogBook |
lb
A log book. |
boolean |
open
Flag, true after actions which invalidate the current state of the population. |
protected float |
overSelBoundary
Percent of the population in which to apply over-selection. |
protected boolean |
overSelection
Flag for over-selection. |
GPParams |
params
The parameters shared by all the individuals. |
float |
pMutation
Probability of mutation. |
GPProgram[] |
pop
The population. |
float |
pXOver
Probability of crossover. |
static int |
REPLACE_BRANCH
Replacing method. |
static int |
REPLACE_PROGRAM
Default replacing method. |
static int |
REPLACE_TREE
Replacing method. |
int |
size
Number of individuals. |
double |
totFitness
The sum of all the adjusted fitnesses. |
| Constructor Summary | |
|
GPPopulation(int size,
GPParams params,
Evaluator judge)
Create a brand new population. |
protected |
GPPopulation(int size,
GPParams params,
Evaluator judge,
int internal)
Create a void population. |
| Method Summary | |
int |
addADF(int type,
int[] ct,
java.lang.Class[] fSet,
java.lang.Class[] tSet,
int[] links)
Add an ADF to the function set. |
void |
addArg(int type)
Add an argument. |
void |
addFunction(java.lang.Class f)
Add a function to the function set. |
void |
addTerminal(java.lang.Class t)
Add a terminal to the terminal set. |
protected static void |
allign(GPFunction f,
int[] perm,
int[] specPerm)
Allign the indices of a subtree. |
protected static void |
allign(GPProgram ind,
int[] perm,
int[] specPerm,
int[][] adfPerm,
int[][] adfSpecPerm)
Allign the indices of an individual. |
protected void |
clearBestOfRun()
Clear the BestOfRun data after a change of the parameters. |
void |
closeLogBook()
Stop using a log book. |
void |
closePopulation()
Do what must be done after changes in the parameters and before evaluation. |
void |
eval()
Evaluate the fitness by mean of an Evaluator, transforms the standarized- in the adjusted fitness, sort the individuals and print the results. |
protected int |
fitnessDependentChoice()
Select an individual. |
double |
getBestFitness()
Return the fitness of the best individual. |
GPProgram |
getBestIndividual()
Return the best individual. |
protected java.lang.String |
getMethodName(int method)
Return the name of a replacing method. |
boolean |
getOverSelection()
Return true if the over-selection option is on. |
float |
getOverSelectionBoundary()
Return the over-selected percentual of the population, or -1 if the over-selection option is off. |
int |
getSize()
Return the number of individuals. |
static GPPopulation |
load(java.io.File f)
Load a population. |
static GPPopulation |
load(java.lang.String filename)
Load a population. |
static GPPopulation |
merge(GPPopulation[] p,
GPParams mparams,
Evaluator judge,
int size,
double prc)
Merge some populations. |
protected static GPProgram |
mergeChooseProgram(GPPopulation cp)
Choose a program from a population (while merging). |
protected GPProgram |
modifyProgram(GPProgram progr,
int method,
java.util.ArrayList refs,
java.util.ArrayList adfRefList)
Modify an individual. |
protected GPProgram |
newIndividual()
Create a new individual. |
void |
nextGeneration()
Create a new generation. |
protected void |
quickSortByFitness(int b,
int t)
Sort the population by fitness, in decreasing order. |
void |
removeADF(int adfNo,
int method)
Remove an ADF. |
void |
removeArg(int argNo,
int method)
Remove an argument. |
void |
removeFunction(java.lang.Class func,
int method)
Remove a function. |
void |
removeFunction(int funcNo,
int method)
Remove a function. |
void |
removeTerminal(java.lang.Class term,
int method)
Remove a terminal. |
void |
removeTerminal(int termNo,
int method)
Remove a terminal. |
void |
save(java.io.File f)
Save the population. |
void |
save(java.lang.String filename)
Save the population. |
void |
setLogBook(LogBook lb)
Set the log book. |
void |
setOverSelection(float boundary)
Set the over-selection option on. |
void |
stopOverSelection()
Set the over-selection option off. |
protected static void |
verifyParamsComp(GPParams p,
GPParams mp,
int[] perm,
int[] specPerm,
int[][] adfPerm,
int[][] adfSpecPerm,
int mask)
Verify that two parameters are equivalent. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public GPProgram[] pop
public GPParams params
public Evaluator judge
public transient LogBook lb
public boolean open
public double[] fitness
The adjusted fitness is 0.0 for the worst individual, 1.0 for the best. The adjusted fitness is 1.0/(1.0+standarized_fitness).
public double totFitness
public GPProgram bestOfRun
public double bestOfRunFitness
public int size
public float pXOver
public float pMutation
protected boolean overSelection
protected float overSelBoundary
public static final int EMPTY_MASK
public static final int ADF_EXCL
public static final int REPLACE_PROGRAM
public static final int REPLACE_TREE
public static final int REPLACE_BRANCH
| Constructor Detail |
public GPPopulation(int size,
GPParams params,
Evaluator judge)
throws ParametersNotProperlySetException
size - The number of individuals.params - The parameters shared by all the individuals.judge - The fitness evaluator.
protected GPPopulation(int size,
GPParams params,
Evaluator judge,
int internal)
size - The number of individuals.params - The parameters shared by all the individuals.judge - The fitness evaluator.| Method Detail |
public void setLogBook(LogBook lb)
public void closeLogBook()
public int getSize()
public void setOverSelection(float boundary)
boundary - The over selection boundary. If <0.0 or >0.5, an
automatical choice following the empirical rule 320.0/#individuals
will be made.public void stopOverSelection()
public boolean getOverSelection()
public float getOverSelectionBoundary()
protected void clearBestOfRun()
protected GPProgram newIndividual()
throws ParametersNotProperlySetException
public static GPPopulation merge(GPPopulation[] p,
GPParams mparams,
Evaluator judge,
int size,
double prc)
throws ParametersNotProperlySetException
In each population choose 1/(no. populations)*size*prc individuals and put a clone in the new population. The selection is weighted by the fitness, overselection allowed.
Warning: if the fitness of the populations to merge isn't uptodate, the populations are going to be evaluated.
p - The populations to merge.mparams - The parameters of the new population.judge - The evaluator of the new population.size - The size of the new population.prc - The percent of the population that is not created ex novo (<1.0).ParametersNotProperlySetException - If the parameters of the source
populations aren't compatible with those of the new population.overSelectionprotected static GPProgram mergeChooseProgram(GPPopulation cp)
protected static void verifyParamsComp(GPParams p,
GPParams mp,
int[] perm,
int[] specPerm,
int[][] adfPerm,
int[][] adfSpecPerm,
int mask)
throws ParametersNotProperlySetException
protected static void allign(GPProgram ind,
int[] perm,
int[] specPerm,
int[][] adfPerm,
int[][] adfSpecPerm)
protected static void allign(GPFunction f,
int[] perm,
int[] specPerm)
public void eval()
judgepublic double getBestFitness()
public GPProgram getBestIndividual()
protected void quickSortByFitness(int b,
int t)
public void closePopulation()
public void nextGeneration()
throws ParametersNotProperlySetException
The pXOver per cent of the new population is the result of cross-overs, another pMutation per cent is generated by mutation, and the rest is breeded by simple reproduction. In all the genetic operations the individual are selected in a fitness-dependent way.
If the population is open, it is closed and the individuals are evaluated.
pXOver,
pMutation,
fitnessDependentChoice()protected int fitnessDependentChoice()
The selection is weighted by the fitness. If the overselection option is set, the 80% of the selected individuals are under the overselection boundary.
overSelection
public void removeADF(int adfNo,
int method)
throws RemoveFailureException
adfNo - The number of the ADF to be removed.method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCH
public void removeFunction(java.lang.Class func,
int method)
throws RemoveFailureException
func - Class of the function to remove.method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCH
public void removeFunction(int funcNo,
int method)
throws RemoveFailureException
method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCH
public void removeTerminal(java.lang.Class term,
int method)
throws RemoveFailureException
term - Class of the terminal to remove.method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCH
public void removeTerminal(int termNo,
int method)
throws RemoveFailureException
method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCH
public void removeArg(int argNo,
int method)
throws RemoveFailureException
method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCH
protected GPProgram modifyProgram(GPProgram progr,
int method,
java.util.ArrayList refs,
java.util.ArrayList adfRefList)
throws RemoveFailureException
progr - The program to modify.method - REPLACE_PROGRAM, REPLACE_TREE or REPLACE_BRANCH allowed.refs - A list of Refs to invalid points in the main programs.adfRefLis - A list of lists (one for each ADF) to invalid points
in the ADFs.REPLACE_PROGRAM,
REPLACE_TREE,
REPLACE_BRANCHprotected java.lang.String getMethodName(int method)
public int addADF(int type,
int[] ct,
java.lang.Class[] fSet,
java.lang.Class[] tSet,
int[] links)
throws ParametersNotProperlySetException
type - Type of the root of the new ADF.ct - Type of each argument.fSet - A function set. If null, use the function set of
the main program.tSet - A terminal set. If null, use the terminal set of
the main program.links - Links to other ADFs. If null, no link will be
established.
public void addFunction(java.lang.Class f)
throws ParametersNotProperlySetException
f - A subclass of GPFunction.
public void addTerminal(java.lang.Class t)
throws ParametersNotProperlySetException
t - A subclass of GPTerminal.
public void addArg(int type)
throws ParametersNotProperlySetException
type - Type of the new agument.
public void save(java.lang.String filename)
throws java.io.IOException
public void save(java.io.File f)
throws java.io.IOException
public static GPPopulation load(java.lang.String filename)
throws java.io.IOException,
java.lang.ClassNotFoundException
public static GPPopulation load(java.io.File f)
throws java.io.IOException,
java.lang.ClassNotFoundException
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||