Skip to content

Commit

Permalink
Merge.
Browse files Browse the repository at this point in the history
--HG--
branch : dev
  • Loading branch information
cmd-ntrf authored and felix.antoine.fortin committed Jun 19, 2013
2 parents d9ea368 + 8edc235 commit 12645bb
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 130 deletions.
14 changes: 7 additions & 7 deletions deap/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def varAnd(population, toolbox, cxpb, mutpb):
fitness invalidated. The individuals are cloned so returned population is
independent of the input population.
:param population: A list of individuals to variate.
:param population: A list of individuals to vary.
:param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution
operators.
:param cxpb: The probability of mating two individuals.
:param mutpb: The probability of mutating an individual.
:returns: A list of varied individuals that are independent of their
parents.
The variator goes as follow. First, the parental population
The variation goes as follow. First, the parental population
:math:`P_\mathrm{p}` is duplicated using the :meth:`toolbox.clone` method
and the result is put into the offspring population :math:`P_\mathrm{o}`.
A first loop over :math:`P_\mathrm{o}` is executed to mate consecutive
Expand Down Expand Up @@ -147,7 +147,7 @@ def eaSimple(population, toolbox, cxpb, mutpb, ngen, stats=None,
# Select the next generation individuals
offspring = toolbox.select(population, len(population))

# Variate the pool of individuals
# Vary the pool of individuals
offspring = varAnd(offspring, toolbox, cxpb, mutpb)

# Evaluate the individuals with an invalid fitness
Expand Down Expand Up @@ -177,7 +177,7 @@ def varOr(population, toolbox, lambda_, cxpb, mutpb):
their fitness invalidated. The individuals are cloned so returned
population is independent of the input population.
:param population: A list of individuals to variate.
:param population: A list of individuals to vary.
:param toolbox: A :class:`~deap.base.Toolbox` that contains the evolution
operators.
:param lambda\_: The number of children to produce
Expand All @@ -186,7 +186,7 @@ def varOr(population, toolbox, lambda_, cxpb, mutpb):
:returns: A list of varied individuals that are independent of their
parents.
The variator goes as follow. On each of the *lambda_* iteration, it
The variation goes as follow. On each of the *lambda_* iteration, it
selects one of the three operations; crossover, mutation or reproduction.
In the case of a crossover, two individuals are selected at random from
the parental population :math:`P_\mathrm{p}`, those individuals are cloned
Expand Down Expand Up @@ -283,7 +283,7 @@ def eaMuPlusLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,

# Begin the generational process
for gen in range(1, ngen+1):
# Variate the population
# Vary the population
offspring = varOr(population, toolbox, lambda_, cxpb, mutpb)

# Evaluate the individuals with an invalid fitness
Expand Down Expand Up @@ -366,7 +366,7 @@ def eaMuCommaLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen,

# Begin the generational process
for gen in range(1, ngen+1):
# Variate the population
# Vary the population
offspring = varOr(population, toolbox, lambda_, cxpb, mutpb)

# Evaluate the individuals with an invalid fitness
Expand Down
104 changes: 1 addition & 103 deletions deap/tools/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,108 +151,6 @@ def genealogy(index, depth):
genealogy(individual.history_index, 0)
return gtree


class Checkpoint(object):
"""A checkpoint is a file containing the state of any object that has been
hooked. While initializing a checkpoint, add the objects that you want to
be dumped by appending keyword arguments to the initializer or using the
:meth:`add`.
In order to use efficiently this module, you must understand properly the
assignment principles in Python. This module uses the *pointers* you passed
to dump the object, for example the following won't work as desired ::
>>> my_object = [1, 2, 3]
>>> cp = Checkpoint()
>>> cp.add("my_object", my_object)
>>> my_object = [3, 5, 6]
>>> cp.dump(open("example.ecp", "w"))
>>> cp.load(open("example.ecp", "r"))
>>> cp["my_object"]
[1, 2, 3]
In order to dump the new value of ``my_object`` it is needed to change its
internal values directly and not touch the *label*, as in the following ::
>>> my_object = [1, 2, 3]
>>> cp = Checkpoint()
>>> cp.add("my_object", my_object)
>>> my_object[:] = [3, 5, 6]
>>> cp.dump(open("example.ecp", "w"))
>>> cp.load(open("example.ecp", "r"))
>>> cp["my_object"]
[3, 5, 6]
"""
def __init__(self):
self.objects = {}
self.keys = {}
self.values = {}

def add(self, name, object, key=identity):
"""Add an object to the list of objects to be dumped. The object is
added under the name specified by the argument *name*, the object
added is *object*, and the *key* argument allow to specify a subpart
of the object that should be dumped (*key* defaults to an identity key
that dumps the entire object).
:param name: The name under which the object will be dumped.
:param object: The object to register for dumping.
:param key: A function access the subcomponent of the object to dump,
optional.
The following illustrates how to use the key.
::
>>> from operator import itemgetter
>>> my_object = [1, 2, 3]
>>> cp = Checkpoint()
>>> cp.add("item0", my_object, key=itemgetter(0))
>>> cp.dump(open("example.ecp", "w"))
>>> cp.load(open("example.ecp", "r"))
>>> cp["item0"]
1
"""
self.objects[name] = object
self.keys[name] = partial(key, object)

def remove(self, *args):
"""Remove objects with the specified name from the list of objects to
be dumped.
:param name: The name of one or more object to remove from dumping.
"""
for element in args:
del self.objects[element]
del self.keys[element]
del self.values[element]

def __getitem__(self, value):
return self.values.get(value)

def dump(self, file):
"""Dump the current registered object values in the provided
*filestream*.
:param filestream: A stream in which write the data.
"""
self.values = dict.fromkeys(self.objects.iterkeys())
for name, key in self.keys.iteritems():
self.values[name] = key()
pickle.dump(self.values, file)

def load(self, file):
"""Load a checkpoint from the provided *filestream* retrieving the
dumped object values, it is not safe to load a checkpoint file in a
checkpoint object that contains references as all conflicting names
will be updated with the new values.
:param filestream: A stream from which to read a checkpoint.
"""
self.values.update(pickle.load(file))

class Statistics(object):
"""Object that compiles statistics on a list of arbitrary objects.
When created the statistics object receives a *key* argument that
Expand Down Expand Up @@ -653,7 +551,7 @@ def update(self, population):
if not is_dominated and not has_twin:
self.insert(ind)

__all__ = ['HallOfFame', 'ParetoFront', 'History', 'Statistics', 'MultiStatistics', 'Logbook', 'Checkpoint']
__all__ = ['HallOfFame', 'ParetoFront', 'History', 'Statistics', 'MultiStatistics', 'Logbook']

if __name__ == "__main__":
doctest.run_docstring_examples(Statistics.register, globals())
Expand Down
12 changes: 0 additions & 12 deletions doc/api/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,6 @@ Hall-Of-Fame
.. .. autoattribute:: deap.tools.EvolutionLogger.output
Checkpoint
----------
.. autoclass:: deap.tools.Checkpoint()

.. automethod:: deap.tools.Checkpoint.dump(filestream)

.. automethod:: deap.tools.Checkpoint.load(filestream)

.. automethod:: deap.tools.Checkpoint.add(name, object[, key])

.. automethod:: deap.tools.Checkpoint.remove(name[, ...])

History
-------
.. autoclass:: deap.tools.History
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/advanced/benchmarking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ to the :func:`main` function). The single line that is related to the provided
algorithm in the call to the :func:`main` function.

.. literalinclude:: /code/examples/bbob.py
:lines: 26,27,28,89-135
:lines: 26,27,28,90-137

Once these experiments are done, the data contained in the :file:`ouput`
directory can be used to build the results document. See the `BBOB
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/basic/part1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ objective and single objective fitnesses can be treated the same way. A
:lines: 9

rendering a fitness that minimize the first objective and maximize the
second one. The weights can also be used to variate the importance of each
second one. The weights can also be used to vary the importance of each
objective one against another. This means that the weights can be any real
number and only the sign is used to determine if a maximization or
minimization is done. An example of where the weights can be useful is in the
Expand Down
2 changes: 1 addition & 1 deletion examples/bbob.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main(func, dim, maxfuncevals, ftarget=None):
return best

return best

if __name__ == "__main__":
# Maximum number of restart for an algorithm that detects stagnation
maxrestarts = 1000
Expand Down
2 changes: 1 addition & 1 deletion examples/coev/coop_adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main(extended=True, verbose=True):
# Initialize a container for the next generation representatives
next_repr = [None] * len(species)
for i, s in enumerate(species):
# Variate the species individuals
# Vary the species individuals
s = algorithms.varAnd(s, toolbox, 0.6, 1.0)

r = representatives[:i] + representatives[i+1:]
Expand Down
2 changes: 1 addition & 1 deletion examples/coev/coop_evol.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def main(extended=True, verbose=True):
# Initialize a container for the next generation representatives
next_repr = [None] * len(species)
for (i, s), j in zip(enumerate(species), species_index):
# Variate the species individuals
# Vary the species individuals
s = algorithms.varAnd(s, toolbox, 0.6, 1.0)

# Get the representatives excluding the current species
Expand Down
2 changes: 1 addition & 1 deletion examples/coev/coop_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main(extended=True, verbose=True):
# Initialize a container for the next generation representatives
next_repr = [None] * len(species)
for i, s in enumerate(species):
# Variate the species individuals
# Vary the species individuals
s = algorithms.varAnd(s, toolbox, 0.6, 1.0)

# Get the representatives excluding the current species
Expand Down
2 changes: 1 addition & 1 deletion examples/coev/coop_niche.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main(extended=True, verbose=True):
# Initialize a container for the next generation representatives
next_repr = [None] * len(species)
for i, s in enumerate(species):
# Variate the species individuals
# Vary the species individuals
s = algorithms.varAnd(s, toolbox, 0.6, 1.0)

# Get the representatives excluding the current species
Expand Down
2 changes: 1 addition & 1 deletion examples/ga/nsga2.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main(seed=None):

# Begin the generational process
for gen in range(1, NGEN):
# Variate the population
# Vary the population
offspring = tools.selTournamentDCD(pop, len(pop))
offspring = [toolbox.clone(ind) for ind in offspring]

Expand Down

0 comments on commit 12645bb

Please sign in to comment.