Skip to content

Commit

Permalink
Replace lambda by partial in GP examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd-ntrf committed May 5, 2015
1 parent 70a0b8b commit 185d600
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/gp/adf_symbreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import numpy

from functools import partial

from deap import base
from deap import creator
from deap import gp
Expand Down Expand Up @@ -69,7 +71,7 @@ def protectedDiv(left, right):
pset.addPrimitive(operator.neg, 1)
pset.addPrimitive(math.cos, 1)
pset.addPrimitive(math.sin, 1)
pset.addEphemeralConstant("rand101", lambda: random.randint(-1, 1))
pset.addEphemeralConstant("rand101", partial(random.randint, -1, 1))
pset.addADF(adfset0)
pset.addADF(adfset1)
pset.addADF(adfset2)
Expand Down
4 changes: 3 additions & 1 deletion examples/gp/spambase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import numpy

from functools import partial

from deap import algorithms
from deap import base
from deap import creator
Expand Down Expand Up @@ -64,7 +66,7 @@ def if_then_else(input, output1, output2):
pset.addPrimitive(if_then_else, [bool, float, float], float)

# terminals
pset.addEphemeralConstant("rand100", lambda: random.random() * 100, float)
pset.addEphemeralConstant("rand100", partial(random.uniform, 0, 100), float)
pset.addTerminal(False, bool)
pset.addTerminal(True, bool)

Expand Down
4 changes: 3 additions & 1 deletion examples/gp/symbreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import numpy

from functools import partial

from deap import algorithms
from deap import base
from deap import creator
Expand All @@ -40,7 +42,7 @@ def protectedDiv(left, right):
pset.addPrimitive(operator.neg, 1)
pset.addPrimitive(math.cos, 1)
pset.addPrimitive(math.sin, 1)
pset.addEphemeralConstant("rand101", lambda: random.randint(-1,1))
pset.addEphemeralConstant("rand101", partial(random.randint, -1, 1))
pset.renameArguments(ARG0='x')

creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
Expand Down
4 changes: 3 additions & 1 deletion examples/gp/symbreg_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import numpy

from functools import partial

from deap import algorithms
from deap import base
from deap import creator
Expand All @@ -44,7 +46,7 @@ def protectedDiv(left, right):
pset.addPrimitive(numpy.negative, 1, name="vneg")
pset.addPrimitive(numpy.cos, 1, name="vcos")
pset.addPrimitive(numpy.sin, 1, name="vsin")
pset.addEphemeralConstant("rand101", lambda: random.randint(-1,1))
pset.addEphemeralConstant("rand101", partial(random.randint, -1, 1))
pset.renameArguments(ARG0='x')

creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
Expand Down

0 comments on commit 185d600

Please sign in to comment.