Class gpjpp.GPVariables
All Packages Class Hierarchy This Package Previous Next Index
Class gpjpp.GPVariables
java.lang.Object
|
+----gpjpp.GPObject
|
+----gpjpp.GPVariables
- public class GPVariables
- extends GPObject
Holds all global configuration parameters for a genetic programming
run. All parameters have default values as described below.
The GPRun class also
automatically reads a configuration file in Java property or
Windows .ini format which can be used to set configuration
parameters without recompiling an application.
It is common to create a user subclass of GPVariables in order to
add problem-specific configuration parameters. Examples include the
size and filename for an ant trail, or the number of address lines
that form the input to a boolean multiplexer. In other cases it
may be useful to add non-configuration variables to a subclass of
GPVariables. gpjpp passes a reference to the global variables to all
methods that are likely to need them, including the
evaluate()
method of GP and all of the printOn() methods. Examples that
add to GPVariables in this way include the ant "automaton" that
responds to command functions and eats food, and the set of
data and address inputs for the multiplexer problem.
- Version:
- 1.0
-
AddBestToNewPopulation
- Determines whether the best individual is automatically
added to the next generation, when SteadyState is false.
-
CheckpointGens
- The number of generations between checkpoints saved by
GPRun.
-
ComplexityAffectsFitness
- A boolean that can be tested by the user evaluate() function
to determine whether to incorporate complexity into the
fitness calculation.
-
CreationProbability
- Percent probability that a creation operation will occur
while evolving
a new generation.
-
CreationStr
- An array of strings used to detect and print the creation
type in configuration files and status reports.
-
CreationType
- The strategy used to
create
generation 0.
-
CrossoverProbability
- Percent probability that a crossover operation will occur
while evolving
a new generation.
-
DemeSize
- The number of individuals in each demetic group, if
DemeticGrouping
is true.
-
DemeticGrouping
- Determines whether
demetic migration is performed.
-
DemeticMigProbability
- Percent probability that demetic migration will occur
for each demetic group, if
DemeticGrouping
is true.
-
GoodRuns
- GPRun does multiple runs
until this many of them terminate with the best individual's
fitness below TerminationFitness.
-
GPGREEDYSELECTION
- A fitness-based selection type that uses greedy
over-selection.
-
GPGROW
- A tree creation type that makes every node but those on the
bottom level a function and that builds every tree to
MaximumDepthForCreation.
-
GPPROBABILISTICSELECTION
- A fitness-based selection type that uses a roulette
algorithm.
-
GPRAMPEDGROW
- A tree creation type that is like GPGROW but starts with
a tree depth of two and increases the depth by one for each
tree until it reaches MaximumDepthForCreation, at which point
it cycles back to two.
-
GPRAMPEDHALF
- A tree creation type that builds alternating trees using
the GPRAMPEDVARIABLE and GPRAMPEDGROW methods.
-
GPRAMPEDVARIABLE
- A tree creation type that is like GPVARIABLE but starts with
a tree depth of two and increases the depth by one for each
tree until it reaches MaximumDepthForCreation, at which point
it cycles back to two.
-
GPTOURNAMENTSELECTION
- A fitness-based selection type that uses a tournament
algorithm.
-
GPVARIABLE
- A tree creation type that selects each non-root node with a
50:50 chance of becoming a function or terminal and that
continues building every tree to
MaximumDepthForCreation.
-
MaximumComplexity
- The largest complexity (number of nodes) allowed in any
individual GP, including the main branch and all ADFs.
-
MaximumDepthForCreation
- The largest depth allowed for newly created trees.
-
MaximumDepthForCrossover
- The largest depth allowed for trees after
crossover.
-
NumberOfGenerations
- The maximum number of generations in a run.
-
PopulationSize
- The number of individuals (GP instances) in a population.
-
PrintDetails
- Determines whether a detail file is generated by GPRun.
-
PrintExpression
- Determines whether the detail file shows the s-expression for
each selected individual after each generation.
-
PrintPopulation
- Determines whether the detail file includes every individual
in the population (PrintPopulation = true) or just the best
and worst individuals in the population (PrintPopulation =
false).
-
PrintTree
- Determines whether the statistics file shows a pseudo-graphic
tree for the best individual of each run.
-
SelectionStr
- An array of strings used to detect and print the selection
type in configuration files and status reports.
-
SelectionType
- The strategy used to select individuals with a probability
related to their fitness.
-
ShrinkMutationProbability
- Percent probability that
shrink mutation
will occur for each individual added to a new generation.
-
SteadyState
- Determines whether each new generation is created in
isolation from the previous generation (SteadyState = false) or
is created by replacing the weaker individuals one by one
(SteadyState = true).
-
SwapMutationProbability
- Percent probability that
swap mutation
will occur for each individual added to a new generation.
-
TerminationFitness
- A run terminates if the best individual in any generation
has standardized fitness below this level.
-
TestDiversity
- Determines whether gpjpp tests the diversity of genetic
populations.
-
TournamentSize
- Number of randomly selected individuals forming a "tournament"
when SelectionType is
GPTOURNAMENTSELECTION.
-
TreeFontSize
- The font size in points used to draw the text in graphic
trees enabled by PrintTree.
-
UseADFs
- A boolean that can be tested by user functions to determine
whether to add ADFs to the branch definition and whether to
evaluate them in fitness functions.
-
GPVariables()
- Public null constructor used to create a set of variables
with default values and also during stream loading.
-
GPVariables(GPVariables)
- A constructor that can be called to clone GPVariables.
-
clone()
- Implements the Cloneable interface.
-
equals(Object)
- Determines whether this set of variables equals another object.
-
getBoolean(Properties, String, boolean)
- An internal routine used to convert a property string
to a boolean.
-
getCreationType(Properties, String, int)
- An internal routine that calls getEnumerated type to convert
a property string to the int value for a creation type.
-
getDouble(Properties, String, double)
- An internal routine used to convert a property string
to a double.
-
getEnumeratedType(Properties, String[], String, int)
- An internal routine used to convert a property string
to an enumerated type with int values.
-
getInt(Properties, String, int)
- An internal routine used to convert a property string
to an int.
-
getSelectionType(Properties, String, int)
- An internal routine that calls getEnumerated type to convert
a property string to the int value for a selection type.
-
isA()
- Returns a code identifying the class in a stream file.
-
load(DataInputStream)
- Loads the GPVariables from the specified stream.
-
load(Properties)
- Loads the values from a Properties container (read from a
configuration file) into the GPVariables fields.
-
printOn(PrintStream, GPVariables)
- Writes the GPVariables fields in the format of a
Properties text file.
-
save(DataOutputStream)
- Writes the GPVariables to the specified stream.
GPVARIABLE
public final static int GPVARIABLE
- A tree creation type that selects each non-root node with a
50:50 chance of becoming a function or terminal and that
continues building every tree to
MaximumDepthForCreation.
GPGROW
public final static int GPGROW
- A tree creation type that makes every node but those on the
bottom level a function and that builds every tree to
MaximumDepthForCreation.
GPRAMPEDHALF
public final static int GPRAMPEDHALF
- A tree creation type that builds alternating trees using
the GPRAMPEDVARIABLE and GPRAMPEDGROW methods. The default
method.
GPRAMPEDVARIABLE
public final static int GPRAMPEDVARIABLE
- A tree creation type that is like GPVARIABLE but starts with
a tree depth of two and increases the depth by one for each
tree until it reaches MaximumDepthForCreation, at which point
it cycles back to two. Note that if
TestDiversity
is enabled many of the shallow trees are duplicates, so the
distribution is skewed toward deeper trees than one might expect.
GPRAMPEDGROW
public final static int GPRAMPEDGROW
- A tree creation type that is like GPGROW but starts with
a tree depth of two and increases the depth by one for each
tree until it reaches MaximumDepthForCreation, at which point
it cycles back to two. Note that if TestDiversity is enabled
many of the shallow trees are duplicates, so the distribution
is skewed toward deeper trees than one might expect.
CreationStr
protected final static String CreationStr[]
- An array of strings used to detect and print the creation
type in configuration files and status reports. The values
are "Variable", "Grow", "RampedHalf", "RampedVariable",
and "RampedGrow".
GPPROBABILISTICSELECTION
public final static int GPPROBABILISTICSELECTION
- A fitness-based selection type that uses a roulette
algorithm. The default method.
- See Also:
- probabilisticSelection
GPTOURNAMENTSELECTION
public final static int GPTOURNAMENTSELECTION
- A fitness-based selection type that uses a tournament
algorithm.
- See Also:
- tournamentSelection
GPGREEDYSELECTION
public final static int GPGREEDYSELECTION
- A fitness-based selection type that uses greedy
over-selection. When this type is enabled, demetic
grouping is always disabled.
- See Also:
- greedySelection
SelectionStr
protected final static String SelectionStr[]
- An array of strings used to detect and print the selection
type in configuration files and status reports. The values
are "Probabilistic", "Tournament", and "Greedy".
PopulationSize
public int PopulationSize
- The number of individuals (GP instances) in a population.
If SteadyState is false, two populations of this size are
created and filled. If SteadyState is true, only one
population is created, and weaker individuals are replaced by
new individuals as they are created. Default 500.
NumberOfGenerations
public int NumberOfGenerations
- The maximum number of generations in a run. If the best
individual's standardized fitness drops below
TerminationFitness, the run will terminate sooner.
Default 51.
CreationType
public int CreationType
- The strategy used to
create
generation 0. Default
GPRAMPEDHALF.
MaximumDepthForCreation
public int MaximumDepthForCreation
- The largest depth allowed for newly created trees.
Default 6. The minimum tree depth is always 2.
MaximumDepthForCrossover
public int MaximumDepthForCrossover
- The largest depth allowed for trees after
crossover.
Default 17. Note that MaximumDepthForCrossover
must always be at least as large as MaximumDepthForCreation.
MaximumComplexity
public int MaximumComplexity
- The largest complexity (number of nodes) allowed in any
individual GP, including the main branch and all ADFs.
Although keeping a tight rein on complexity can speed
the algorithm and cut memory requirements, be cautious
not to limit the complexity too much. This can lead to
lack of diversity in the population and to wasted time
attempting to create and evolve new individuals.
Default 200.
- See Also:
- create
SelectionType
public int SelectionType
- The strategy used to select individuals with a probability
related to their fitness. Default
GPPROBABILISTICSELECTION.
TournamentSize
public int TournamentSize
- Number of randomly selected individuals forming a "tournament"
when SelectionType is
GPTOURNAMENTSELECTION. Default 7.
CrossoverProbability
public double CrossoverProbability
- Percent probability that a crossover operation will occur
while evolving
a new generation. Default 90.0.
CreationProbability
public double CreationProbability
- Percent probability that a creation operation will occur
while evolving
a new generation. Default 0.0.
SwapMutationProbability
public double SwapMutationProbability
- Percent probability that
swap mutation
will occur for each individual added to a new generation.
Default 0.0.
ShrinkMutationProbability
public double ShrinkMutationProbability
- Percent probability that
shrink mutation
will occur for each individual added to a new generation.
Default 0.0.
TerminationFitness
public double TerminationFitness
- A run terminates if the best individual in any generation
has standardized fitness below this level. Default 0.0.
Because fitness must always be non-negative, the default
value will never cause a run to stop before NumberOfGenerations.
GoodRuns
public int GoodRuns
- GPRun does multiple runs
until this many of them terminate with the best individual's
fitness below TerminationFitness. Set it to 0 if you want just
a single run regardless of results. Default 5.
UseADFs
public boolean UseADFs
- A boolean that can be tested by user functions to determine
whether to add ADFs to the branch definition and whether to
evaluate them in fitness functions. Provides a convenient
way to test performance without recompiling. This
configuration variable is not used by gpjpp itself.
Default false.
TestDiversity
public boolean TestDiversity
- Determines whether gpjpp tests the diversity of genetic
populations. If true, gpjpp guarantees that there are no
duplicate individuals in generation 0 and then tracks
and reports the diversity of succeeding generations. If
false, gpjpp does not verify or measure diversity.
Default true.
ComplexityAffectsFitness
public boolean ComplexityAffectsFitness
- A boolean that can be tested by the user evaluate() function
to determine whether to incorporate complexity into the
fitness calculation. When this is done, solutions tend to
be parsimonious and average population complexity
tends to remain lower. Provides a convenient way to test
population statistics without recompiling. This
configuration variable is not used by gpjpp itself.
Default true.
CheckpointGens
public int CheckpointGens
- The number of generations between checkpoints saved by
GPRun. If zero,
checkpointing is not performed at all, in which case runs
cannot be restarted after a crash or system shutdown. If
one, a checkpoint is saved after every generation.
Default 0.
DemeticGrouping
public boolean DemeticGrouping
- Determines whether
demetic migration is performed. If true,
the overall population is subdivided into groups of size
DemeSize.
These groups are isolated for the purpose of fitness-based
selection. After all the demetic groups of a new
generation are created, one individual from each group is
fitness-selected and swapped with a fitness-selected individual
from the next group, with each swap controlled by the
probability
DemeticMigProbability. Default false.
DemeSize
public int DemeSize
- The number of individuals in each demetic group, if
DemeticGrouping
is true.
PopulationSize must be an exact integer multiple of DemeSize.
Default 100.
DemeticMigProbability
public double DemeticMigProbability
- Percent probability that demetic migration will occur
for each demetic group, if
DemeticGrouping
is true. Default 100.0.
AddBestToNewPopulation
public boolean AddBestToNewPopulation
- Determines whether the best individual is automatically
added to the next generation, when SteadyState is false.
Default false.
- See Also:
- generate
SteadyState
public boolean SteadyState
- Determines whether each new generation is created in
isolation from the previous generation (SteadyState = false) or
is created by replacing the weaker individuals one by one
(SteadyState = true). Steady state operation reduces
peak memory usage by a factor of two. Default false.
- See Also:
- generate
PrintDetails
public boolean PrintDetails
- Determines whether a detail file is generated by GPRun.
The detail file includes the population index, heritage,
fitness, complexity, depth, and optionally the s-expression
for individuals after each generation. Default false.
PrintPopulation
public boolean PrintPopulation
- Determines whether the detail file includes every individual
in the population (PrintPopulation = true) or just the best
and worst individuals in the population (PrintPopulation =
false). Default false.
PrintExpression
public boolean PrintExpression
- Determines whether the detail file shows the s-expression for
each selected individual after each generation. Also determines
whether the statistics file includes the s-expression for
the best individual of each run. Default true.
- See Also:
- showGeneration
PrintTree
public boolean PrintTree
- Determines whether the statistics file shows a pseudo-graphic
tree for the best individual of each run. Also determines
whether gif files are created showing the best individual
of each run in true graphic format. Default true.
- See Also:
- showFinalGeneration
TreeFontSize
public int TreeFontSize
- The font size in points used to draw the text in graphic
trees enabled by PrintTree. The typeface is always Courier,
a monospaced font. Default 12.
GPVariables
public GPVariables()
- Public null constructor used to create a set of variables
with default values and also during stream loading.
GPVariables
public GPVariables(GPVariables gpo)
- A constructor that can be called to clone GPVariables. Normally
not used.
clone
protected synchronized Object clone()
- Implements the Cloneable interface.
This clones GPVariables but is normally not used.
- Returns:
- the cloned object.
- Overrides:
- clone in class GPObject
isA
public byte isA()
- Returns a code identifying the class in a stream file.
- Returns:
- the ID code VARIABLESID.
- Overrides:
- isA in class GPObject
equals
public boolean equals(Object obj)
- Determines whether this set of variables equals another object.
It returns true if obj is not null, is an instance of GPVariables
(or a descendant), and contains the same field values.
This function is called when a checkpoint is loaded by GPRun,
to determine whether the program and the checkpoint are
consistent. One can think of various harmless changes
made to GPVariables that would still allow a checkpoint to
continue (increasing the number of generations, for example),
but this is not allowed here.
- Parameters:
- obj - any Java object reference, including null.
- Returns:
- true if this and obj are equivalent.
- Overrides:
- equals in class Object
getInt
protected int getInt(Properties props,
String proStr,
int def)
- An internal routine used to convert a property string
to an int. If the numeric conversion fails, the default
value is used.
getBoolean
protected boolean getBoolean(Properties props,
String proStr,
boolean def)
- An internal routine used to convert a property string
to a boolean. Acceptable boolean values in a configuration
file are 0/non-zero, false/true, and FALSE/TRUE. If the
conversion fails, the default value is used.
getDouble
protected double getDouble(Properties props,
String proStr,
double def)
- An internal routine used to convert a property string
to a double. If the numeric conversion fails, the default
value is used.
getEnumeratedType
protected int getEnumeratedType(Properties props,
String EnumStr[],
String proStr,
int def)
- An internal routine used to convert a property string
to an enumerated type with int values. Either the integer
value or the string representation is acceptable, and string
matching is not case sensitive. If the conversion fails,
the default value is used.
getCreationType
protected int getCreationType(Properties props,
String proStr,
int def)
- An internal routine that calls getEnumerated type to convert
a property string to the int value for a creation type.
- See Also:
- CreationStr
getSelectionType
protected int getSelectionType(Properties props,
String proStr,
int def)
- An internal routine that calls getEnumerated type to convert
a property string to the int value for a selection type.
- See Also:
- SelectionStr
load
public synchronized void load(Properties props)
- Loads the values from a Properties container (read from a
configuration file) into the GPVariables fields. If the
property strings are invalid, default values for the affected
fields remain unchanged. If props is null, nothing happens.
- See Also:
- getInt, getBoolean, getDouble, getCreationType, getSelectionType
load
protected synchronized void load(DataInputStream is) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException
- Loads the GPVariables from the specified stream.
- Throws: ClassNotFoundException
- if the class indicated by the stream's ID code
is not registered with GPObject.
- Throws: InstantiationException
- if an error occurs while calling new or the null
constructor of the specified class.
- Throws: IllegalAccessException
- if the specified class or its null constructor is
not public.
- Throws: IOException
- if an error occurs while reading the stream.
- Throws: RuntimeException
- if the ID code read next in the stream doesn't
match the ID code returned by isA().
- Overrides:
- load in class GPObject
save
protected void save(DataOutputStream os) throws IOException
- Writes the GPVariables to the specified stream.
- Throws: IOException
- if an error occurs while writing the stream.
- Overrides:
- save in class GPObject
printOn
public void printOn(PrintStream os,
GPVariables cfg)
- Writes the GPVariables fields in the format of a
Properties text file.
- Overrides:
- printOn in class GPObject
All Packages Class Hierarchy This Package Previous Next Index