[deap] 2 new revisions pushed by felix.antoine.fortin on 2014-04-30 20:00 GMT

3 views
Skip to first unread message

de...@googlecode.com

unread,
Apr 30, 2014, 4:00:51 PM4/30/14
to deap-de...@googlegroups.com
2 new revisions:

Revision: 386f14555af2
Branch: dev
Author: felix.antoine.fortin
Date: Wed Apr 30 19:56:51 2014 UTC
Log: Change the generate default type in gp to pset.ret....
http://code.google.com/p/deap/source/detail?r=386f14555af2

Revision: d4d3b7eb53cd
Branch: dev
Author: felix.antoine.fortin
Date: Wed Apr 30 20:00:27 2014 UTC
Log: Merge fixes from default.
http://code.google.com/p/deap/source/detail?r=d4d3b7eb53cd

==============================================================================
Revision: 386f14555af2
Branch: dev
Author: felix.antoine.fortin
Date: Wed Apr 30 19:56:51 2014 UTC
Log: Change the generate default type in gp to pset.ret.

This fixes a problem when a STGP user would forget
to set the type_ argument, the generate function
would request primitive of the type 'object'. The
type_ argument is only to accomodate GP mutations.
It is from now on set to None by default, and
replace by pset.ret if the no other type has been
specified.
http://code.google.com/p/deap/source/detail?r=386f14555af2

Modified:
/deap/gp.py
/examples/gp/spambase.py

=======================================
--- /deap/gp.py Wed Mar 26 21:42:45 2014 UTC
+++ /deap/gp.py Wed Apr 30 19:56:51 2014 UTC
@@ -487,7 +487,7 @@
######################################
# GP Program generation functions #
######################################
-def genFull(pset, min_, max_, type_=__type__):
+def genFull(pset, min_, max_, type_=None):
"""Generate an expression where each leaf has a the same depth
between *min* and *max*.

@@ -503,7 +503,7 @@
return depth == height
return generate(pset, min_, max_, condition, type_)

-def genGrow(pset, min_, max_, type_=__type__):
+def genGrow(pset, min_, max_, type_=None):
"""Generate an expression where each leaf might have a different depth
between *min* and *max*.

@@ -522,7 +522,7 @@
(depth >= min_ and random.random() < pset.terminalRatio)
return generate(pset, min_, max_, condition, type_)

-def genHalfAndHalf(pset, min_, max_, type_=__type__):
+def genHalfAndHalf(pset, min_, max_, type_=None):
"""Generate an expression with a PrimitiveSet *pset*.
Half the time, the expression is generated
with :func:`~deap.gp.genGrow`,
the other half, the expression is generated
with :func:`~deap.gp.genFull`.
@@ -537,7 +537,7 @@
method = random.choice((genGrow, genFull))
return method(pset, min_, max_, type_)

-def genRamped(pset, min_, max_, type_=__type__):
+def genRamped(pset, min_, max_, type_=None):
"""
.. deprecated:: 1.0
The function has been renamed. Use :func:`~deap.gp.genHalfAndHalf`
instead.
@@ -546,7 +546,7 @@
FutureWarning)
return genHalfAndHalf(pset, min_, max_, type_)

-def generate(pset, min_, max_, condition, type_=__type__):
+def generate(pset, min_, max_, condition, type_=None):
"""Generate a Tree as a list of list. The tree is build
from the root to the leaves, and it stop growing when the
condition is fulfilled.
@@ -562,6 +562,8 @@
:returns: A grown tree with leaves at possibly different depths
dependending on the condition function.
"""
+ if type_ is None:
+ type_ = pset.ret
expr = []
height = random.randint(min_, max_)
stack = [(0, type_)]
=======================================
--- /examples/gp/spambase.py Wed Apr 2 13:04:09 2014 UTC
+++ /examples/gp/spambase.py Wed Apr 30 19:56:51 2014 UTC
@@ -71,7 +71,7 @@
creator.create("Individual", gp.PrimitiveTree, fitness=creator.FitnessMax)

toolbox = base.Toolbox()
-toolbox.register("expr", gp.genHalfAndHalf, pset=pset, type_=pset.ret,
min_=1, max_=2)
+toolbox.register("expr", gp.genHalfAndHalf, pset=pset, min_=1, max_=2)
toolbox.register("individual", tools.initIterate, creator.Individual,
toolbox.expr)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
toolbox.register("compile", gp.compile, pset=pset)

==============================================================================
Revision: d4d3b7eb53cd
Branch: dev
Author: felix.antoine.fortin
Date: Wed Apr 30 20:00:27 2014 UTC
Log: Merge fixes from default.
http://code.google.com/p/deap/source/detail?r=d4d3b7eb53cd

Modified:
/deap/__init__.py
/deap/creator.py
/deap/gp.py
/deap/tools/emo.py
/doc/_templates/indexsidebar.html
/examples/speed.txt

=======================================
--- /deap/creator.py Wed Apr 2 12:53:51 2014 UTC
+++ /deap/creator.py Wed Apr 30 20:00:27 2014 UTC
@@ -91,8 +91,8 @@
return (self.__class__, (list(self),), self.__dict__)
class_replacers[array.array] = _array

-def create(classname, baseclass, **kargs):
- """Creates a new class named *classname* inheriting from *baseclass*
in the
+def create(name, base, **kargs):
+ """Creates a new class named *name* inheriting from *base* in the
:mod:`~deap.creator` module. The new class can have attributes defined
by
the subsequent keyword arguments passed to the function create. If the
argument is a class (without the parenthesis), the __init__ function is
@@ -101,8 +101,8 @@
Otherwise, if the argument is not a class, (for example
an :class:`int`),
it is added as a "static" attribute of the class.

- :param classname: The name of the class to create.
- :param baseclass: A base class from which to inherit.
+ :param name: The name of the class to create.
+ :param base: A base class from which to inherit.
:param attribute: One or more attributes to add on instanciation of
this
class, optional.

@@ -140,8 +140,8 @@
dict_cls[obj_name] = obj

# Check if the base class has to be replaced
- if baseclass in class_replacers:
- baseclass = class_replacers[baseclass]
+ if base in class_replacers:
+ base = class_replacers[base]

# A DeprecationWarning is raised when the object inherits from the
# class "object" which leave the option of passing arguments, but
@@ -154,9 +154,9 @@
"""
for obj_name, obj in dict_inst.iteritems():
setattr(self, obj_name, obj())
- if baseclass.__init__ is not object.__init__:
- baseclass.__init__(self, *args, **kargs)
+ if base.__init__ is not object.__init__:
+ base.__init__(self, *args, **kargs)

- objtype = type(str(classname), (baseclass,), dict_cls)
+ objtype = type(str(name), (base,), dict_cls)
objtype.__init__ = initType
- globals()[classname] = objtype
+ globals()[name] = objtype
=======================================
--- /deap/tools/emo.py Sun Apr 6 21:02:24 2014 UTC
+++ /deap/tools/emo.py Wed Apr 30 20:00:27 2014 UTC
@@ -16,7 +16,7 @@
size of *individuals* will be larger than *k* because any individual
present in *individuals* will appear in the returned list at most once.
Having the size of *individuals* equals to *k* will have no effect
other
- than sorting the population according according to their front rank.
The
+ than sorting the population according to their front rank. The
list returned contains references to the input *individuals*. For more
details on the NSGA-II operator see [Deb2002]_.

Reply all
Reply to author
Forward
0 new messages