|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectec.Species
ec.vector.VectorSpecies
ec.vector.IntegerVectorSpecies
ec.gp.ge.GESpecies
public class GESpecies
GESpecies generates GPIndividuals from GEIndividuals through the application of a grammar parse graph computed by the GrammarParser.
GESpecies uses a GrammarParser to do its dirty work. This parser's job is to take a grammar (in the form of a BufferedReader) and convert it to a tree of GrammarNodes which define the parse graph of the grammar. The GESpecies then interprets his parse graph according to the values in the GEIndividual to produce the equivalent GPIndividual, which is then evaluated.
To do this, GESpecies relies on a subsidiary GPSpecies which defines the GPIndividual and various GPFunctionSets from which to build the parser. This is a grand hack -- the GPSpecies does not know it's being used this way, and so we must provide various dummy parameters to keep the GPSpecies happy even though they'll never be used.
If you are daring, you can replace the GrammarParser with one of your own to customize the parse structure and grammar.
ECJ's Default GE Grammar GE traditionally can use any grammar, and builds parse graphs from that. For simplicity, and in order to remain as compatable as possible with ECJ's existing GP facilities (and GP tradition), ECJ only uses a single Lisp-like grammar which generates standard ECJ trees. This doesn't lose much in generality as the grammar is quite genral.
The grammar assumes that expansion points are enclosed in <> and functions are enclosed in (). For example:
# This is a comment
<prog> ::= <op>
<op> ::= (if-food-ahead <op> <op>)
<op> ::= (progn2 <op> <op>)
<op> ::= (progn3 <op> <op> <op>)
<op> ::= (left) | (right) | (move)
alternatively the grammar could also be writen in the following format:
<prog> ::= <op>
<op> ::= (if-food-ahead <op> <op>) | (progn2 <op> <op>) | (progn3 <op> <op> <op>) | (left) | (right) | (move)
Note that you can use several lines to define the same grammar rule: for example, <op> was defined by several lines when it could have consisted of several elements separated by vertical pipes ( | ). Either way is fine, or a combination of both.
GPNodes are included in the grammar by using their name. This includes ERCs, ADFs, ADMs, and ADFArguments, which should all work just fine. For example, since most ERC GPNodes are simply named "ERC", if you have only one ERC GPNode in your function set, you can just use (ERC) in your grammar.
Once the gammar file has been created and setup has been run trees can the be created using the genome (chromosome) of a GEIndividual. A genome of an individual is an array of random integers each of which are one byte long. These numbers are used when a decision point (a rule having more that one choice) is reached within the grammar. Once a particular gene (index) in the genome has been used it will not be used again (this may change) when creating the tree.
For example:
number of chromosomes used = 0
genome = {23, 654, 86}
the current rule we are considering is <op>.
%lt;op> can map into one of the following: (if-food-ahead <op> <op>) | (progn2 <op> <op>) | (progn3 <op> <op> <op>)
| (left) | (right) | (move)
Since the rule <op> has more than one choice that it can map to, we must consult the genome to decide which choice to take. In this case
the number of chromosomes used is 0 so genome[0] is used and number of chromosomes used is incremented. Since values in the genome can
be negitive values they are offset by 128 (max negitive of a byte) giving us a value from 0-255. A modulus is performed on this resulting
number by the number of choices present for the given rule. In the above example since we are using genome[0] the resulting operation would
look like: 23+128=151, number of choices for <op> = 6, 151%6=1 so we use choices[1] which is: (progn2 <op> <op>). If all the genes
in a genome are used and the tree is still incompete an invalid tree error is returned.
Each node in the tree is a GPNode and trees are constructed depth first.
Parameters
base.file String |
(the file is where the rules of the gammar are stored) |
base.gp-species classname, inherits and != ec.gp.GPSpecies |
(the GPSpecies subservient to the GESpecies) |
base.parser classname, inherits and != ec.gp.ge.GrammarParser |
(the GrammarParser used by the GESpecies) |
Default Base
ec.gp.ge.GESpecies
Field Summary | |
---|---|
static int |
BIG_TREE_ERROR
|
java.util.HashMap |
ERCBank
All the ERCs created so far. |
GPSpecies |
gpspecies
The GPSpecies subsidiary to GESpecies. |
GrammarRuleNode[] |
grammar
The parsed grammars. |
static java.lang.String |
P_FILE
|
static java.lang.String |
P_GESPECIES
|
static java.lang.String |
P_GPSPECIES
|
static java.lang.String |
P_PARSER
|
GrammarParser |
parser_prototype
The prototypical parser used to parse the grammars. |
Fields inherited from class ec.vector.IntegerVectorSpecies |
---|
maxGenes, minGenes, P_MAXGENE, P_MINGENE, P_NUM_SEGMENTS, P_SEGMENT, P_SEGMENT_END, P_SEGMENT_START, P_SEGMENT_TYPE |
Fields inherited from class ec.Species |
---|
f_prototype, i_prototype, P_FITNESS, P_INDIVIDUAL, P_PIPE, pipe_prototype |
Constructor Summary | |
---|---|
GESpecies()
|
Method Summary | |
---|---|
java.lang.Object |
clone()
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context. |
int |
consumed(EvolutionState state,
GEIndividual ind,
int threadnum)
Returns the number of elements consumed from the GEIndividual array to produce the tree, else returns -1 if an error occurs, specifically if all elements were consumed and the tree had still not been completed. |
Parameter |
defaultBase()
Returns the default base for this prototype. |
int |
makeTree(EvolutionState state,
GEIndividual ind,
GPTree tree,
int position,
int treeNum,
int threadnum)
makeTree, edits the tree that its given by adding a root (and all subtrees attached) |
int |
makeTrees(EvolutionState state,
GEIndividual ind,
GPTree[] trees,
int threadnum)
creates all of an individual's trees |
GPIndividual |
map(EvolutionState state,
GEIndividual ind,
int threadnum)
Returns a dummy GPIndividual with a single tree which was built by mapping over the elements of the given GEIndividual. |
GPNode |
obtainERC(EvolutionState state,
int key,
byte[] genome,
int threadnum,
GPNode node)
Loads an ERC from the ERCBank given the value in the genome. |
void |
setup(EvolutionState state,
Parameter base)
The default version of setup(...) loads requested pipelines and calls setup(...) on them and normalizes their probabilities. |
Methods inherited from class ec.vector.IntegerVectorSpecies |
---|
inNumericalTypeRange, maxGene, minGene |
Methods inherited from class ec.vector.VectorSpecies |
---|
newIndividual, warnAboutGene |
Methods inherited from class ec.Species |
---|
newIndividual, newIndividual |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String P_GESPECIES
public static final java.lang.String P_FILE
public static final java.lang.String P_GPSPECIES
public static final java.lang.String P_PARSER
public static final int BIG_TREE_ERROR
public GPSpecies gpspecies
public java.util.HashMap ERCBank
public GrammarRuleNode[] grammar
public GrammarParser parser_prototype
Constructor Detail |
---|
public GESpecies()
Method Detail |
---|
public void setup(EvolutionState state, Parameter base)
Species
setup
in interface Prototype
setup
in interface Setup
setup
in class IntegerVectorSpecies
Prototype.setup(EvolutionState,Parameter)
public int makeTrees(EvolutionState state, GEIndividual ind, GPTree[] trees, int threadnum)
state
- Evolution statetrees
- array of trees for the individualind
- the GEIndividualthreadnum
- tread number
public int makeTree(EvolutionState state, GEIndividual ind, GPTree tree, int position, int treeNum, int threadnum)
state
- ind
- tree
- position
- treeNum
- threadnum
-
public GPNode obtainERC(EvolutionState state, int key, byte[] genome, int threadnum, GPNode node)
public java.lang.Object clone()
Prototype
Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:
Implementations.
public Object clone()
{
try
{
return super.clone();
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
public Object clone()
{
try
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
}
catch ((CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
return myobj;
}
public Object clone()
{
MyObject myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
return myobj;
}
clone
in interface Prototype
clone
in class Species
public Parameter defaultBase()
Prototype
defaultBase
in interface Prototype
defaultBase
in class VectorSpecies
public int consumed(EvolutionState state, GEIndividual ind, int threadnum)
public GPIndividual map(EvolutionState state, GEIndividual ind, int threadnum)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |