ec.gp.koza
Class HalfBuilder

java.lang.Object
  |
  +--ec.gp.GPNodeBuilder
        |
        +--ec.gp.koza.HalfBuilder

public class HalfBuilder
extends GPNodeBuilder

HalfBuilder is a GPNodeBuilder which approximately implements the RAMPED HALF-AND-HALF tree building method described in Koza I/II.

RAMPED HALF-AND-HALF works by choosing a random integer d between minDepth and maxDepth, inclusive. It then grows a tree of depth 1 to d inclusive. (1-pickGrowProbability) of the time (by default, 0.5) it grows a tree using the FULL method, which generates full trees of exactly depth d. (pickGrowProbability) of the time, it grows a tree using the GROW method, which may generate trees of any size between 1 and d inclusive.

Actually, claiming to implement the Koza I/II approach is a bit of a fib -- Koza's original code is somewhat ad-hoc. It uses an odd mechanism for determining d, going round-robin from minDepth to maxDepth, inclusive, rather than choosing one at random. Further, it's not legal to create trees consisting of a single terminal in the Koza approach; this means Koza's trees tend to be slightly bigger. This also makes strongly-typed implementations unecessarily restrictive in function options. Lastly, in Koza's approach the mindepth is hard-set to 2.

This implementation instead follows lil-gp's approach, which is to choose d at random from between minDepth and maxDepth, inclusive, and to allow trees consisting of single terminals.

Note that the Koza I/II implementations solely use GROW for subtree mutations.

This algorithm ignores requestedSize, so no pipelines can ask it to grow a tree of a specific fixed size. The algorithm also ignores any user-provided size distributions.

The common value for pickGrowProbability is 0.5.

Common maxDepth values:

Common minDepth values:

Parameters
base.growp
0.0 <= float <= 1.0
(the likelihood of choosing GROW (as opposed to FULL)>
base.min-depth
int >= 1
(smallest "maximum" depth the builder may use for building a tree. 2 is the default.)
base.max-depth
int >= base.min-depth
(largest "maximum" depth the builder may use for building a tree. 6 is the default.)

Default Base
gp.koza.half

See Also:
Serialized Form

Field Summary
 int maxDepth
          The largest maximum tree depth RAMPED HALF-AND-HALF can specify.
 int minDepth
          The smallest maximum tree depth RAMPED HALF-AND-HALF can specify.
static java.lang.String P_HALFBUILDER
           
static java.lang.String P_MAXDEPTH
           
static java.lang.String P_MINDEPTH
           
static java.lang.String P_PICKGROWPROBABILITY
           
 float pickGrowProbability
          The likelihood of using GROW over FULL.
 
Fields inherited from class ec.gp.GPNodeBuilder
CHECK_BOUNDARY, maxSize, minSize, NOSIZEGIVEN, P_MAXSIZE, P_MINSIZE, P_NUMSIZES, P_SIZE, sizeDistribution
 
Constructor Summary
HalfBuilder()
           
 
Method Summary
 Parameter defaultBase()
          Returns the default base for this prototype.
 GPNode newRootedTree(EvolutionState state, GPType type, int thread, GPNodeParent parent, GPFunctionSet set, int argposition, int requestedSize)
           
 void setup(EvolutionState state, Parameter base)
          Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
 
Methods inherited from class ec.gp.GPNodeBuilder
canPick, pickSize, protoClone, protoCloneSimple
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

P_HALFBUILDER

public static final java.lang.String P_HALFBUILDER

P_MAXDEPTH

public static final java.lang.String P_MAXDEPTH

P_MINDEPTH

public static final java.lang.String P_MINDEPTH

P_PICKGROWPROBABILITY

public static final java.lang.String P_PICKGROWPROBABILITY

maxDepth

public int maxDepth
The largest maximum tree depth RAMPED HALF-AND-HALF can specify.

minDepth

public int minDepth
The smallest maximum tree depth RAMPED HALF-AND-HALF can specify.

pickGrowProbability

public float pickGrowProbability
The likelihood of using GROW over FULL.
Constructor Detail

HalfBuilder

public HalfBuilder()
Method Detail

defaultBase

public Parameter defaultBase()
Description copied from interface: Prototype
Returns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...).

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from interface: Prototype
Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.

Overrides:
setup in class GPNodeBuilder

newRootedTree

public GPNode newRootedTree(EvolutionState state,
                            GPType type,
                            int thread,
                            GPNodeParent parent,
                            GPFunctionSet set,
                            int argposition,
                            int requestedSize)
                     throws java.lang.CloneNotSupportedException
Overrides:
newRootedTree in class GPNodeBuilder