Skip to content

Commit

Permalink
Round two of flake8 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bje- committed Apr 24, 2023
1 parent 8aa17a0 commit 2a90a05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
19 changes: 19 additions & 0 deletions deap/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def ackley(individual):
return 20 - 20 * exp(-0.2*sqrt(1.0/N * sum(x**2 for x in individual))) \
+ e - exp(1.0/N * sum(cos(2*pi*x) for x in individual)),


def bohachevsky(individual):
r"""Bohachevsky test objective function.
Expand All @@ -200,6 +201,7 @@ def bohachevsky(individual):
return sum(x**2 + 2*x1**2 - 0.3*cos(3*pi*x) - 0.4*cos(4*pi*x1) + 0.7
for x, x1 in zip(individual[:-1], individual[1:])),


def griewank(individual):
r"""Griewank test objective function.
Expand All @@ -223,6 +225,7 @@ def griewank(individual):
return 1.0/4000.0 * sum(x**2 for x in individual) - \
reduce(mul, (cos(x/sqrt(i+1.0)) for i, x in enumerate(individual)), 1) + 1,


def rastrigin(individual):
r"""Rastrigin test objective function.
Expand All @@ -245,6 +248,7 @@ def rastrigin(individual):
return 10 * len(individual) + sum(gene * gene - 10 * \
cos(2 * pi * gene) for gene in individual),


def rastrigin_scaled(individual):
r"""Scaled Rastrigin test objective function.
Expand All @@ -256,6 +260,7 @@ def rastrigin_scaled(individual):
return 10*N + sum((10**(i/(N-1))*x)**2 -
10*cos(2*pi*10**(i/(N-1))*x) for i, x in enumerate(individual)),


def rastrigin_skew(individual):
r"""Skewed Rastrigin test objective function.
Expand Down Expand Up @@ -294,6 +299,7 @@ def schaffer(individual):
return sum((x**2+x1**2)**0.25 * ((sin(50*(x**2+x1**2)**0.1))**2+1.0)
for x, x1 in zip(individual[:-1], individual[1:])),


def schwefel(individual):
r"""Schwefel test objective function.
Expand Down Expand Up @@ -344,6 +350,7 @@ def himmelblau(individual):
return (individual[0] * individual[0] + individual[1] - 11)**2 + \
(individual[0] + individual[1] * individual[1] - 7)**2,


def shekel(individual, a, c):
r"""The Shekel multimodal function can have any number of maxima. The number
of maxima is given by the length of any of the arguments *a* or *c*, *a*
Expand All @@ -366,6 +373,7 @@ def shekel(individual, a, c):
"""
return sum((1. / (c[i] + sum((individual[j] - aij)**2 for j, aij in enumerate(a[i])))) for i in range(len(c))),


# Multiobjectives
def kursawe(individual):
r"""Kursawe multiobjective function.
Expand Down Expand Up @@ -394,6 +402,7 @@ def schaffer_mo(individual):
"""
return individual[0] ** 2, (individual[0] - 2) ** 2


def zdt1(individual):
r"""ZDT1 multiobjective function.
Expand All @@ -408,6 +417,7 @@ def zdt1(individual):
f2 = g * (1 - sqrt(f1/g))
return f1, f2


def zdt2(individual):
r"""ZDT2 multiobjective function.
Expand All @@ -424,6 +434,7 @@ def zdt2(individual):
f2 = g * (1 - (f1/g)**2)
return f1, f2


def zdt3(individual):
r"""ZDT3 multiobjective function.
Expand All @@ -440,6 +451,7 @@ def zdt3(individual):
f2 = g * (1 - sqrt(f1/g) - f1/g * sin(10*pi*f1))
return f1, f2


def zdt4(individual):
r"""ZDT4 multiobjective function.
Expand All @@ -455,6 +467,7 @@ def zdt4(individual):
f2 = g * (1 - sqrt(f1/g))
return f1, f2


def zdt6(individual):
r"""ZDT6 multiobjective function.
Expand All @@ -470,6 +483,7 @@ def zdt6(individual):
f2 = g * (1 - (f1/g)**2)
return f1, f2


def dtlz1(individual, obj):
r"""DTLZ1 multiobjective function. It returns a tuple of *obj* values.
The individual must have at least *obj* elements.
Expand Down Expand Up @@ -498,6 +512,7 @@ def dtlz1(individual, obj):
f.extend(0.5 * reduce(mul, individual[:m], 1) * (1 - individual[m]) * (1 + g) for m in reversed(range(obj-1)))
return f


def dtlz2(individual, obj):
r"""DTLZ2 multiobjective function. It returns a tuple of *obj* values.
The individual must have at least *obj* elements.
Expand Down Expand Up @@ -526,6 +541,7 @@ def dtlz2(individual, obj):

return f


def dtlz3(individual, obj):
r"""DTLZ3 multiobjective function. It returns a tuple of *obj* values.
The individual must have at least *obj* elements.
Expand Down Expand Up @@ -553,6 +569,7 @@ def dtlz3(individual, obj):
f.extend((1.0+g) * reduce(mul, (cos(0.5*xi*pi) for xi in xc[:m]), 1) * sin(0.5*xc[m]*pi) for m in range(obj-2, -1, -1))
return f


def dtlz4(individual, obj, alpha):
r"""DTLZ4 multiobjective function. It returns a tuple of *obj* values. The
individual must have at least *obj* elements. The *alpha* parameter allows
Expand Down Expand Up @@ -582,6 +599,7 @@ def dtlz4(individual, obj, alpha):
f.extend((1.0+g) * reduce(mul, (cos(0.5*xi**alpha*pi) for xi in xc[:m]), 1) * sin(0.5*xc[m]**alpha*pi) for m in range(obj-2, -1, -1))
return f


def dtlz5(ind, n_objs):
r"""DTLZ5 multiobjective function. It returns a tuple of *obj* values. The
individual must have at least *obj* elements.
Expand Down Expand Up @@ -677,6 +695,7 @@ def poloni(individual):
B_2 = 1.5 * sin(x_1) - cos(x_1) + 2 * sin(x_2) - 0.5 * cos(x_2)
return 1 + (A_1 - B_1)**2 + (A_2 - B_2)**2, (x_1 + 3)**2 + (x_2 + 1)**2


def dent(individual, lambda_ = 0.85):
r"""Test problem Dent. Two-objective problem with a "dent". *individual* has
two attributes that take values in [-1.5, 1.5].
Expand Down
1 change: 1 addition & 0 deletions deap/tests/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def teardown_func():
creator.__dict__.pop(CNAME)



@with_setup(None, teardown_func)
def test_create():
creator.create(CNAME, list)
Expand Down
1 change: 0 additions & 1 deletion deap/tests/test_logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_multi_chapters(self):
test={'avg' : 1.0, 'max' : 20})
print(self.logbook.stream)


def test_one_chapter(self):
self.logbook.record(gen=0, evals=100, fitness={'avg' : 1.0, 'max' : 10})
self.logbook.record(gen=0, evals=100, fitness={'avg' : 1.0, 'max' : 10})
Expand Down
1 change: 0 additions & 1 deletion deap/tools/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,3 @@ def valid(individual):
ind1 = creator.Individual((-5.6468535666e-01,2.2483050478e+00,-1.1087909644e+00,-1.2710112861e-01,1.1682438733e+00,-1.3642007438e+00,-2.1916417835e-01,-5.9137308999e-01,-1.0870160336e+00,6.0515070232e-01,2.1532075914e+00,-2.6164718271e-01,1.5244071578e+00,-1.0324305612e+00,1.2858152343e+00,-1.2584683962e+00,1.2054392372e+00,-1.7429571973e+00,-1.3517256013e-01,-2.6493429355e+00,-1.3051320798e-01,2.2641961090e+00,-2.5027232340e+00,-1.2844874148e+00,1.9955852925e+00,-1.2942218834e+00,3.1340109155e+00,1.6440111097e+00,-1.7750105857e+00,7.7610242710e-01))
print(toolbox.evaluate(ind1))
print("Individuals is valid: %s" % ("True" if valid(ind1) else "False"))

0 comments on commit 2a90a05

Please sign in to comment.