Skip to content

Commit

Permalink
Added info on staticLimit example
Browse files Browse the repository at this point in the history
  • Loading branch information
fmder committed Nov 1, 2014
1 parent 5253905 commit 85fd8dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions doc/examples/gp_symbreg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ method (a tournament of size 3), the mate method (one point crossover with
uniform probability over all the nodes), the mutation method (an uniform
probability mutation which may append a new full sub-tree to a node).

We decorate the mate and mutate method to limit the depth of generated individuals
to be 50.
Then, we decorate the mate and mutate method to limit the height of generated
individuals. This is done to avoid an important draw back of genetic
programming : bloat. Koza in his book on genetic programming suggest to use a
max depth of 17.

At this point, any structure with an access to the toolbox instance will also
have access to all of those registered parameters. Of course, the user could
Expand Down
4 changes: 2 additions & 2 deletions examples/gp/symbreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def evalSymbReg(individual, points):
toolbox.register("expr_mut", gp.genFull, min_=0, max_=2)
toolbox.register("mutate", gp.mutUniform, expr=toolbox.expr_mut, pset=pset)

toolbox.decorate("mate", gp.staticLimit(key=operator.attrgetter('height'), max_value=50))
toolbox.decorate("mutate", gp.staticLimit(key=operator.attrgetter('height'), max_value=50))
toolbox.decorate("mate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17))
toolbox.decorate("mutate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17))

def main():
random.seed(318)
Expand Down

0 comments on commit 85fd8dd

Please sign in to comment.