Skip to content

Commit

Permalink
Corrected some docstrings of the cma module
Browse files Browse the repository at this point in the history
--HG--
branch : dev
  • Loading branch information
fmder committed Nov 1, 2012
1 parent 03a92f9 commit c055c48
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions deap/cma.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Strategy(object):
:param centroid: An iterable object that indicates where to start the
evolution.
:param sigma: The list of initial standard deviations of the distribution,
it shall be the same length than the centroid.
:param sigma: The initial standard deviation of the distribution.
:param parameter: One or more parameter to pass to the strategy as
described in the following table, optional.
Expand Down Expand Up @@ -74,6 +73,7 @@ class Strategy(object):
| | mueff) / ((N + 2)^2 + | update. |
| | mueff)`` | |
+----------------+---------------------------+----------------------------+
"""
def __init__(self, centroid, sigma, **kargs):
self.params = kargs
Expand Down Expand Up @@ -115,11 +115,11 @@ def generate(self, ind_init):
return map(ind_init, arz)

def update(self, population):
"""Update the current covariance matrix strategy and *population*.
"""Update the current covariance matrix strategy from the
*population*.
:param population: A list of individuals from which to update the
parameters and where the new population will be
placed.
parameters.
"""
population.sort(key=lambda ind: ind.fitness, reverse=True)

Expand Down Expand Up @@ -200,6 +200,15 @@ def computeParams(self, params):
self.damps = params.get("damps", self.damps)

class StrategyOnePlusLambda(object):
"""
A CMA-ES strategy that uses the :math:`1 + \lambda` paradigme.
:param parent: An iterable object that indicates where to start the
evolution. The parent requires a fitness attribute.
:param sigma: The initial standard deviation of the distribution.
:param parameter: One or more parameter to pass to the strategy as
described in the following table, optional.
"""
def __init__(self, parent, sigma, **kargs):
self.parent = parent
self.sigma = sigma
Expand All @@ -214,6 +223,11 @@ def __init__(self, parent, sigma, **kargs):
self.psucc = self.ptarg

def computeParams(self, params):
"""Computes the parameters depending on *lambda_*. It needs to be
called again if *lambda_* changes during evolution.
:param params: A dictionary of the manually set parameters.
"""
# Selection :
self.lambda_ = params.get("lambda_", 1)

Expand All @@ -228,12 +242,25 @@ def computeParams(self, params):
self.pthresh = params.get("pthresh", 0.44)

def generate(self, ind_init):
"""Generate a population from the current strategy using the
centroid individual as parent.
:param ind_init: A function object that is able to initialize an
individual from a list.
:returns: A list of individuals.
"""
# self.y = numpy.dot(self.A, numpy.random.standard_normal(self.dim))
arz = numpy.random.standard_normal((self.lambda_, self.dim))
arz = self.parent + self.sigma * numpy.dot(arz, self.A.T)
return map(ind_init, arz)

def update(self, population):
"""Update the current covariance matrix strategy from the
*population*.
:param population: A list of individuals from which to update the
parameters.
"""
population.sort(key=lambda ind: ind.fitness, reverse=True)
lambda_succ = sum(self.parent.fitness <= ind.fitness for ind in population)
p_succ = float(lambda_succ) / self.lambda_
Expand Down

0 comments on commit c055c48

Please sign in to comment.