|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.groovyj.jgprog.World
World is the main engine class of the Groovy Java Genetic Programming system. This class is abstract and should be subclassed so that you can provide specifics about your own genetic programming problem (or "world").
In the constructor of your subclass, you should set the values of the various genetic programming runtime parameters. The defaults are:
Once you have determined your world's parameters, you must provide a function which
evaluates the absolute fitness of a given Individual
.
The adjusted fitness of an individual is a value between 0 and 1 inclusive, with
larger values indicating fitter individuals. Koza[1992] uses the adjusted
fitness formula 1/(1+s),
where s is the standardized fitness whose value is between 0 and infinity,
with smaller values indicating fitter individuals, and 0 indicating a perfect
individual. While the use of the Koza formula is not required, it does have the
advantage of exaggerating the difference between highly and closely fit individuals.
If you do not use the Koza formula, some other fitness function must be used such
that higher values indicate fitter individuals.
The next step is to create
the world. You will need to know the population size,
the number of chromosome
s per individual, the return type of each chromosome,
the number of arguments and their types for each chromosome, and the types of
nodes (functions and terminals) each chromosome is allowed to have.
With this release of JGProg, the only types allowed are Boolean, Integer, Long, Float, Double, and Void.
Also with this release of JGProg, the following terminals are available (note, this list is currently out of date -- there are more functions):
and the following functions are available:
Add
ADF
And
Cosine
Divide
Equals
Exponential
GreaterThan
If
LessThan
Multiply
NaturalLogarithm
Not
Or
Sine
Subtract
ADF could actually be a terminal if it refers to a chromosome which takes no arguments.
Creating the world will generate the initial population according to the ramped half-and-half method described in Koza[1992]. The create method evaluates each individual by calling your fitness method.
After create returns, you can evolve the population by calling
nextGeneration
.
This method performs the reproduce and crossover operations described in Koza[1992].
The individuals chosen for these operations are selected using the
selectionMethod
you chose. The default selection method is
fitness-proportionate.
You can call nextGeneration as many times as you want. A new run can be started by calling the create method again.
Got a comment about this class? Found a bug? Got an enhancement? Just want to say hi? Visit the Groovy Java Genetic Programming Project Home Page.
Visit the Groovy Java Home Page for information about other Groovy Java open source projects.
Copyright (c) 2000 Robert Baruch. This code is released under the GNU General Public License (GPL).
Field Summary | |
protected static CrossMethod |
crossMethod
|
protected static float |
crossoverProb
The probability that a crossover operation is chosen during evolution. |
protected static int |
maxChromosomes
|
protected static int |
maxCrossoverDepth
The maximum depth of an individual resulting from crossover. |
protected static int |
maxInitDepth
The maximum depth of an individual when the world is created. |
protected static int |
maxSize
|
static java.util.Random |
random
The random number generator used by every random event. |
protected static float |
reproductionProb
The probability that a reproduction operation is chosen during evolution. |
protected static SelectionMethod |
selectionMethod
The method of choosing an individual to perform an evolution operation on. |
Constructor Summary | |
World()
Constructs a world. |
Method Summary | |
void |
addGPListener(GPListener l)
|
abstract float |
computeFitness(Individual individual)
Computes the adjusted fitness of the given individual. |
void |
create(int popSize,
Type[] types,
Type[][] argTypes,
Function[][] nodeSets)
Creates the initial population for the world and computes the fitnesses of all the individuals in the initial population. |
Individual |
getBestIndividual()
Gets the most fit individual from the current population. |
Population |
getPopulation()
Gets the population. |
float |
getTotalFitness()
Gets the sum of the adjusted fitnesses of all individuals in the population. |
Individual |
getWorstIndividual()
Gets the least fit individual from the current population. |
void |
nextGeneration()
Evolve the population by one generation. |
void |
removeGPListener(GPListener l)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static SelectionMethod selectionMethod
FitnessProportionateSelection
.protected static CrossMethod crossMethod
protected static float crossoverProb
protected static float reproductionProb
protected static int maxCrossoverDepth
protected static int maxInitDepth
protected static int maxChromosomes
protected static int maxSize
public static java.util.Random random
Constructor Detail |
public World() throws java.io.IOException
Method Detail |
public void create(int popSize, Type[] types, Type[][] argTypes, Function[][] nodeSets)
Implementation note: the arguments of a chromosome, if any, are treated as
Variable
s of name "ARG"+argnum
(ARG0, ARG1, etc). These variables
are automatically saved, loaded before a call to the chromosome (via
ADF
),
and restored after the call.
popSize
- the number of individuals in the populationtypes
- the type of each chromosome, the length is
the number of chromosomesargTypes
- the types of the arguments to each chromosome, must be an array
of arrays, the first dimension of which is the number of chromosomes and the
second dimension of which is the number of arguments to the chromosome.nodeSets
- the nodes which are allowed to be used by each chromosome, must
be an array of arrays, the first dimension of which is the number of chromosomes
and the second dimension of which is the number of nodes. Note that it is not necessary
to include the arguments of a chromosome as terminals in the chromosome's node set.
This is done automatically for you.public abstract float computeFitness(Individual individual)
individual
- the Individual to evaulatepublic float getTotalFitness()
public Population getPopulation()
public void nextGeneration()
public Individual getBestIndividual()
public Individual getWorstIndividual()
public void addGPListener(GPListener l)
public void removeGPListener(GPListener l)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |