Skip to content

Commit

Permalink
Fix PEP8 warnings about under-indented lines.
Browse files Browse the repository at this point in the history
Verified with diff -w (no change).
  • Loading branch information
bje- committed May 4, 2015
1 parent 3682d0a commit 600aa7d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion deap/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def varOr(population, toolbox, lambda_, cxpb, mutpb):
1 - *cxpb* - *mutpb*.
"""
assert (cxpb + mutpb) <= 1.0, ("The sum of the crossover and mutation "
"probabilities must be smaller or equal to 1.0.")
"probabilities must be smaller or equal to 1.0.")

offspring = []
for _ in xrange(lambda_):
Expand Down
22 changes: 11 additions & 11 deletions deap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ class Fitness(object):
def __init__(self, values=()):
if self.weights is None:
raise TypeError("Can't instantiate abstract %r with abstract "
"attribute weights." % (self.__class__))
"attribute weights." % (self.__class__))

if not isinstance(self.weights, Sequence):
raise TypeError("Attribute weights of %r must be a sequence."
% self.__class__)
% self.__class__)

if len(values) > 0:
self.values = values
Expand All @@ -186,19 +186,19 @@ def setValues(self, values):
except TypeError:
_, _, traceback = sys.exc_info()
raise TypeError, ("Both weights and assigned values must be a "
"sequence of numbers when assigning to values of "
"%r. Currently assigning value(s) %r of %r to a fitness with "
"weights %s."
% (self.__class__, values, type(values), self.weights)), traceback
"sequence of numbers when assigning to values of "
"%r. Currently assigning value(s) %r of %r to a fitness with "
"weights %s."
% (self.__class__, values, type(values), self.weights)), traceback

def delValues(self):
self.wvalues = ()

values = property(getValues, setValues, delValues,
("Fitness values. Use directly ``individual.fitness.values = values`` "
"in order to set the fitness and ``del individual.fitness.values`` "
"in order to clear (invalidate) the fitness. The (unweighted) fitness "
"can be directly accessed via ``individual.fitness.values``."))
("Fitness values. Use directly ``individual.fitness.values = values`` "
"in order to set the fitness and ``del individual.fitness.values`` "
"in order to clear (invalidate) the fitness. The (unweighted) fitness "
"can be directly accessed via ``individual.fitness.values``."))

def dominates(self, other, obj=slice(None)):
"""Return true if each objective of *self* is not strictly worse than
Expand Down Expand Up @@ -261,4 +261,4 @@ def __str__(self):
def __repr__(self):
"""Return the Python code to build a copy of the object."""
return "%s.%s(%r)" % (self.__module__, self.__class__.__name__,
self.values if self.valid else tuple())
self.values if self.valid else tuple())
28 changes: 14 additions & 14 deletions deap/cma.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ def update(self, population):

# Cumulation : update evolution path
self.ps = (1 - self.cs) * self.ps \
+ sqrt(self.cs * (2 - self.cs) * self.mueff) / self.sigma \
* numpy.dot(self.B, (1. / self.diagD)
* numpy.dot(self.B.T, c_diff))
+ sqrt(self.cs * (2 - self.cs) * self.mueff) / self.sigma \
* numpy.dot(self.B, (1. / self.diagD)
* numpy.dot(self.B.T, c_diff))

hsig = float((numpy.linalg.norm(self.ps) /
sqrt(1. - (1. - self.cs) ** (2. * (self.update_count + 1.))) / self.chiN
< (1.4 + 2. / (self.dim + 1.))))
sqrt(1. - (1. - self.cs) ** (2. * (self.update_count + 1.))) / self.chiN
< (1.4 + 2. / (self.dim + 1.))))

self.update_count += 1

self.pc = (1 - self.cc) * self.pc + hsig \
* sqrt(self.cc * (2 - self.cc) * self.mueff) / self.sigma \
* c_diff
* sqrt(self.cc * (2 - self.cc) * self.mueff) / self.sigma \
* c_diff

# Update covariance matrix
artmp = population[0:self.mu] - old_centroid
self.C = (1 - self.ccov1 - self.ccovmu + (1 - hsig)
* self.ccov1 * self.cc * (2 - self.cc)) * self.C \
+ self.ccov1 * numpy.outer(self.pc, self.pc) \
+ self.ccovmu * numpy.dot((self.weights * artmp.T), artmp) \
/ self.sigma ** 2
* self.ccov1 * self.cc * (2 - self.cc)) * self.C \
+ self.ccov1 * numpy.outer(self.pc, self.pc) \
+ self.ccovmu * numpy.dot((self.weights * artmp.T), artmp) \
/ self.sigma ** 2

self.sigma *= numpy.exp((numpy.linalg.norm(self.ps) / self.chiN - 1.)
* self.cs / self.damps)
Expand Down Expand Up @@ -192,13 +192,13 @@ def computeParams(self, params):
self.cs = params.get("cs", (self.mueff + 2.) /
(self.dim + self.mueff + 3.))
self.ccov1 = params.get("ccov1", 2. / ((self.dim + 1.3) ** 2 +
self.mueff))
self.mueff))
self.ccovmu = params.get("ccovmu", 2. * (self.mueff - 2. +
1. / self.mueff) /
((self.dim + 2.) ** 2 + self.mueff))
((self.dim + 2.) ** 2 + self.mueff))
self.ccovmu = min(1 - self.ccov1, self.ccovmu)
self.damps = 1. + 2. * max(0, sqrt((self.mueff - 1.) /
(self.dim + 1.)) - 1.) + self.cs
(self.dim + 1.)) - 1.) + self.cs
self.damps = params.get("damps", self.damps)


Expand Down
60 changes: 30 additions & 30 deletions deap/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ def __setitem__(self, key, val):
if isinstance(key, slice):
if key.start >= len(self):
raise IndexError("Invalid slice object (try to assign a %s"
" in a tree of size %d). Even if this is allowed by the"
" list object slice setter, this should not be done in"
" the PrimitiveTree context, as this may lead to an"
" unpredictable behavior for searchSubtree or evaluate."
% (key, len(self)))
" in a tree of size %d). Even if this is allowed by the"
" list object slice setter, this should not be done in"
" the PrimitiveTree context, as this may lead to an"
" unpredictable behavior for searchSubtree or evaluate."
% (key, len(self)))
total = val[0].arity
for node in val[1:]:
total += node.arity - 1
if total != 0:
raise ValueError("Invalid slice assignation : insertion of"
" an incomplete subtree is not allowed in PrimitiveTree."
" A tree is defined as incomplete when some nodes cannot"
" be mapped to any position in the tree, considering the"
" primitives' arity. For instance, the tree [sub, 4, 5,"
" 6] is incomplete if the arity of sub is 2, because it"
" would produce an orphan node (the 6).")
" an incomplete subtree is not allowed in PrimitiveTree."
" A tree is defined as incomplete when some nodes cannot"
" be mapped to any position in the tree, considering the"
" primitives' arity. For instance, the tree [sub, 4, 5,"
" 6] is incomplete if the arity of sub is 2, because it"
" would produce an orphan node (the 6).")
elif val.arity != self[key].arity:
raise ValueError("Invalid node replacement with a node of a"
" different arity.")
Expand Down Expand Up @@ -332,10 +332,10 @@ def addPrimitive(self, primitive, in_types, ret_type, name=None):
prim = Primitive(name, in_types, ret_type)

assert name not in self.context or \
self.context[name] is primitive, \
"Primitives are required to have a unique name. " \
"Consider using the argument 'name' to rename your "\
"second '%s' primitive." % (name,)
self.context[name] is primitive, \
"Primitives are required to have a unique name. " \
"Consider using the argument 'name' to rename your "\
"second '%s' primitive." % (name,)

self._add(prim)
self.context[prim.name] = primitive
Expand All @@ -359,9 +359,9 @@ def addTerminal(self, terminal, ret_type, name=None):
name = terminal.__name__

assert name not in self.context, \
"Terminals are required to have a unique name. " \
"Consider using the argument 'name' to rename your "\
"second %s terminal." % (name,)
"Terminals are required to have a unique name. " \
"Consider using the argument 'name' to rename your "\
"second %s terminal." % (name,)

if name is not None:
self.context[name] = terminal
Expand Down Expand Up @@ -475,10 +475,10 @@ def compile(expr, pset):
except MemoryError:
_, _, traceback = sys.exc_info()
raise MemoryError, ("DEAP : Error in tree evaluation :"
" Python cannot evaluate a tree higher than 90. "
"To avoid this problem, you should use bloat control on your "
"operators. See the DEAP documentation for more information. "
"DEAP will now abort."), traceback
" Python cannot evaluate a tree higher than 90. "
"To avoid this problem, you should use bloat control on your "
"operators. See the DEAP documentation for more information. "
"DEAP will now abort."), traceback


def compileADF(expr, psets):
Expand Down Expand Up @@ -545,7 +545,7 @@ def condition(height, depth):
or when it is randomly determined that a a node should be a terminal.
"""
return depth == height or \
(depth >= min_ and random.random() < pset.terminalRatio)
(depth >= min_ and random.random() < pset.terminalRatio)
return generate(pset, min_, max_, condition, type_)


Expand Down Expand Up @@ -919,8 +919,8 @@ def wrapper(*args, **kwargs):
######################################

def harm(population, toolbox, cxpb, mutpb, ngen,
alpha, beta, gamma, rho, nbrindsmodel=-1, mincutoff=20,
stats=None, halloffame=None, verbose=__debug__):
alpha, beta, gamma, rho, nbrindsmodel=-1, mincutoff=20,
stats=None, halloffame=None, verbose=__debug__):
"""Implement bloat control on a GP evolution using HARM-GP, as defined in
[Gardner2015]. It is implemented in the form of an evolution algorithm
(similar to :func:`~deap.algorithms.eaSimple`).
Expand Down Expand Up @@ -997,7 +997,7 @@ def _genpop(n, pickfrom=[], acceptfunc=lambda s: True, producesizes=False):
if opRandom < cxpb:
# Crossover
aspirant1, aspirant2 = toolbox.mate(*map(toolbox.clone,
toolbox.select(population, 2)))
toolbox.select(population, 2)))
del aspirant1.fitness.values, aspirant2.fitness.values
if acceptfunc(len(aspirant1)):
producedpop.append(aspirant1)
Expand Down Expand Up @@ -1072,10 +1072,10 @@ def _genpop(n, pickfrom=[], acceptfunc=lambda s: True, producesizes=False):

# Compute the target distribution
targetfunc = lambda x: (gamma * len(population) * math.log(2) /
halflifefunc(x)) * math.exp(-math.log(2) *
(x - cutoffsize) / halflifefunc(x))
halflifefunc(x)) * math.exp(-math.log(2) *
(x - cutoffsize) / halflifefunc(x))
targethist = [naturalhist[binidx] if binidx <= cutoffsize else
targetfunc(binidx) for binidx in range(len(naturalhist))]
targetfunc(binidx) for binidx in range(len(naturalhist))]

# Compute the probabilities distribution
probhist = [t / n if n > 0 else t for n, t in zip(naturalhist, targethist)]
Expand All @@ -1085,7 +1085,7 @@ def _genpop(n, pickfrom=[], acceptfunc=lambda s: True, producesizes=False):
# Generate offspring using the acceptance probabilities
# previously computed
offspring = _genpop(len(population), pickfrom=naturalpop,
acceptfunc=acceptfunc, producesizes=False)
acceptfunc=acceptfunc, producesizes=False)

# Evaluate the individuals with an invalid fitness
invalid_ind = [ind for ind in offspring if not ind.fitness.valid]
Expand Down

0 comments on commit 600aa7d

Please sign in to comment.