Skip to content

Commit

Permalink
Merge pull request DEAP#588 from bje-/whitespace-fixes
Browse files Browse the repository at this point in the history
Remove trailing whitespace from *.py
  • Loading branch information
fmder authored Nov 13, 2021
2 parents 1f1c9d2 + f26c776 commit bfd3af8
Show file tree
Hide file tree
Showing 69 changed files with 548 additions and 548 deletions.
2 changes: 1 addition & 1 deletion deap/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def eaGenerateUpdate(toolbox, ngen, halloffame=None, stats=None,
This function expects :meth:`toolbox.generate` and :meth:`toolbox.evaluate` aliases to be
registered in the toolbox.
.. [Colette2010] Collette, Y., N. Hansen, G. Pujol, D. Salazar Aponte and
R. Le Riche (2010). On Object-Oriented Programming of Optimizers -
Examples in Scilab. In P. Breitkopf and R. F. Coelho, eds.:
Expand Down
138 changes: 69 additions & 69 deletions deap/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rand(individual):
- :math:`f(\mathbf{x}) = \\text{\\texttt{random}}(0,1)`
"""
return random.random(),

def plane(individual):
"""Plane test objective function.
Expand Down Expand Up @@ -79,7 +79,7 @@ def sphere(individual):

def cigar(individual):
"""Cigar test objective function.
.. list-table::
:widths: 10 50
:stub-columns: 1
Expand Down Expand Up @@ -110,7 +110,7 @@ def rosenbrock(individual):
- :math:`x_i = 1, \\forall i \in \\lbrace 1 \\ldots N\\rbrace`, :math:`f(\mathbf{x}) = 0`
* - Function
- :math:`f(\\mathbf{x}) = \\sum_{i=1}^{N-1} (1-x_i)^2 + 100 (x_{i+1} - x_i^2 )^2`
.. plot:: code/benchmarks/rosenbrock.py
:width: 67 %
"""
Expand Down Expand Up @@ -163,14 +163,14 @@ def ackley(individual):
* - Function
- :math:`f(\\mathbf{x}) = 20 - 20\exp\left(-0.2\sqrt{\\frac{1}{N} \
\\sum_{i=1}^N x_i^2} \\right) + e - \\exp\\left(\\frac{1}{N}\sum_{i=1}^N \\cos(2\pi x_i) \\right)`
.. plot:: code/benchmarks/ackley.py
:width: 67 %
"""
N = len(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):
"""Bohachevsky test objective function.
Expand All @@ -187,7 +187,7 @@ def bohachevsky(individual):
* - Function
- :math:`f(\mathbf{x}) = \sum_{i=1}^{N-1}(x_i^2 + 2x_{i+1}^2 - \
0.3\cos(3\pi x_i) - 0.4\cos(4\pi x_{i+1}) + 0.7)`
.. plot:: code/benchmarks/bohachevsky.py
:width: 67 %
"""
Expand All @@ -196,7 +196,7 @@ def bohachevsky(individual):

def griewank(individual):
"""Griewank test objective function.
.. list-table::
:widths: 10 50
:stub-columns: 1
Expand All @@ -216,7 +216,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):
"""Rastrigin test objective function.
Expand All @@ -241,7 +241,7 @@ def rastrigin(individual):

def rastrigin_scaled(individual):
"""Scaled Rastrigin test objective function.
:math:`f_{\\text{RastScaled}}(\mathbf{x}) = 10N + \sum_{i=1}^N \
\left(10^{\left(\\frac{i-1}{N-1}\\right)} x_i \\right)^2 x_i)^2 - \
10\cos\\left(2\\pi 10^{\left(\\frac{i-1}{N-1}\\right)} x_i \\right)`
Expand All @@ -252,9 +252,9 @@ def rastrigin_scaled(individual):

def rastrigin_skew(individual):
"""Skewed Rastrigin test objective function.
:math:`f_{\\text{RastSkew}}(\mathbf{x}) = 10N \sum_{i=1}^N \left(y_i^2 - 10 \\cos(2\\pi x_i)\\right)`
:math:`\\text{with } y_i = \
\\begin{cases} \
10\\cdot x_i & \\text{ if } x_i > 0,\\\ \
Expand All @@ -266,7 +266,7 @@ def rastrigin_skew(individual):
- 10*cos(2*pi*(10*x if x > 0 else x)) for x in individual),
def schaffer(individual):
"""Schaffer test objective function.
.. list-table::
:widths: 10 50
:stub-columns: 1
Expand Down Expand Up @@ -343,18 +343,18 @@ def shekel(individual, a, c):
of maxima is given by the length of any of the arguments *a* or *c*, *a*
is a matrix of size :math:`M\\times N`, where *M* is the number of maxima
and *N* the number of dimensions and *c* is a :math:`M\\times 1` vector.
:math:`f_\\text{Shekel}(\mathbf{x}) = \\sum_{i = 1}^{M} \\frac{1}{c_{i} +
\\sum_{j = 1}^{N} (x_{j} - a_{ij})^2 }`
The following figure uses
:math:`\\mathcal{A} = \\begin{bmatrix} 0.5 & 0.5 \\\\ 0.25 & 0.25 \\\\
0.25 & 0.75 \\\\ 0.75 & 0.25 \\\\ 0.75 & 0.75 \\end{bmatrix}` and
:math:`\\mathbf{c} = \\begin{bmatrix} 0.002 \\\\ 0.005 \\\\ 0.005
\\\\ 0.005 \\\\ 0.005 \\end{bmatrix}`, thus defining 5 maximums in
:math:`\\mathbb{R}^2`.
.. plot:: code/benchmarks/shekel.py
:width: 67 %
"""
Expand All @@ -363,9 +363,9 @@ def shekel(individual, a, c):
# Multiobjectives
def kursawe(individual):
"""Kursawe multiobjective function.
:math:`f_{\\text{Kursawe}1}(\\mathbf{x}) = \\sum_{i=1}^{N-1} -10 e^{-0.2 \\sqrt{x_i^2 + x_{i+1}^2} }`
:math:`f_{\\text{Kursawe}2}(\\mathbf{x}) = \\sum_{i=1}^{N} |x_i|^{0.8} + 5 \\sin(x_i^3)`
.. plot:: code/benchmarks/kursawe.py
Expand All @@ -381,20 +381,20 @@ def schaffer_mo(individual):
From: J. D. Schaffer, "Multiple objective optimization with vector
evaluated genetic algorithms", in Proceedings of the First International
Conference on Genetic Algorithms, 1987.
:math:`f_{\\text{Schaffer}1}(\\mathbf{x}) = x_1^2`
:math:`f_{\\text{Schaffer}2}(\\mathbf{x}) = (x_1-2)^2`
"""
return individual[0] ** 2, (individual[0] - 2) ** 2

def zdt1(individual):
"""ZDT1 multiobjective function.
:math:`g(\\mathbf{x}) = 1 + \\frac{9}{n-1}\\sum_{i=2}^n x_i`
:math:`f_{\\text{ZDT1}1}(\\mathbf{x}) = x_1`
:math:`f_{\\text{ZDT1}2}(\\mathbf{x}) = g(\\mathbf{x})\\left[1 - \\sqrt{\\frac{x_1}{g(\\mathbf{x})}}\\right]`
"""
g = 1.0 + 9.0*sum(individual[1:])/(len(individual)-1)
Expand All @@ -404,20 +404,20 @@ def zdt1(individual):

def zdt2(individual):
"""ZDT2 multiobjective function.
:math:`g(\\mathbf{x}) = 1 + \\frac{9}{n-1}\\sum_{i=2}^n x_i`
:math:`f_{\\text{ZDT2}1}(\\mathbf{x}) = x_1`
:math:`f_{\\text{ZDT2}2}(\\mathbf{x}) = g(\\mathbf{x})\\left[1 - \\left(\\frac{x_1}{g(\\mathbf{x})}\\right)^2\\right]`
"""

g = 1.0 + 9.0*sum(individual[1:])/(len(individual)-1)
f1 = individual[0]
f2 = g * (1 - (f1/g)**2)
return f1, f2

def zdt3(individual):
"""ZDT3 multiobjective function.
Expand All @@ -436,28 +436,28 @@ def zdt3(individual):

def zdt4(individual):
"""ZDT4 multiobjective function.
:math:`g(\\mathbf{x}) = 1 + 10(n-1) + \\sum_{i=2}^n \\left[ x_i^2 - 10\\cos(4\\pi x_i) \\right]`
:math:`f_{\\text{ZDT4}1}(\\mathbf{x}) = x_1`
:math:`f_{\\text{ZDT4}2}(\\mathbf{x}) = g(\\mathbf{x})\\left[ 1 - \\sqrt{x_1/g(\\mathbf{x})} \\right]`
"""
g = 1 + 10*(len(individual)-1) + sum(xi**2 - 10*cos(4*pi*xi) for xi in individual[1:])
f1 = individual[0]
f2 = g * (1 - sqrt(f1/g))
return f1, f2

def zdt6(individual):
"""ZDT6 multiobjective function.
:math:`g(\\mathbf{x}) = 1 + 9 \\left[ \\left(\\sum_{i=2}^n x_i\\right)/(n-1) \\right]^{0.25}`
:math:`f_{\\text{ZDT6}1}(\\mathbf{x}) = 1 - \\exp(-4x_1)\\sin^6(6\\pi x_1)`
:math:`f_{\\text{ZDT6}2}(\\mathbf{x}) = g(\\mathbf{x}) \left[ 1 - (f_{\\text{ZDT6}1}(\\mathbf{x})/g(\\mathbf{x}))^2 \\right]`
"""
g = 1 + 9 * (sum(individual[1:]) / (len(individual)-1))**0.25
f1 = 1 - exp(-4*individual[0]) * sin(6*pi*individual[0])**6
Expand All @@ -473,19 +473,19 @@ def dtlz1(individual, obj):
:math:`g(\\mathbf{x}_m) = 100\\left(|\\mathbf{x}_m| + \sum_{x_i \in \\mathbf{x}_m}\\left((x_i - 0.5)^2 - \\cos(20\pi(x_i - 0.5))\\right)\\right)`
:math:`f_{\\text{DTLZ1}1}(\\mathbf{x}) = \\frac{1}{2} (1 + g(\\mathbf{x}_m)) \\prod_{i=1}^{m-1}x_i`
:math:`f_{\\text{DTLZ1}2}(\\mathbf{x}) = \\frac{1}{2} (1 + g(\\mathbf{x}_m)) (1-x_{m-1}) \\prod_{i=1}^{m-2}x_i`
:math:`\\ldots`
:math:`f_{\\text{DTLZ1}m-1}(\\mathbf{x}) = \\frac{1}{2} (1 + g(\\mathbf{x}_m)) (1 - x_2) x_1`
:math:`f_{\\text{DTLZ1}m}(\\mathbf{x}) = \\frac{1}{2} (1 - x_1)(1 + g(\\mathbf{x}_m))`
Where :math:`m` is the number of objectives and :math:`\\mathbf{x}_m` is a
vector of the remaining attributes :math:`[x_m~\\ldots~x_n]` of the
individual in :math:`n > m` dimensions.
"""
g = 100 * (len(individual[obj-1:]) + sum((xi-0.5)**2 - cos(20*pi*(xi-0.5)) for xi in individual[obj-1:]))
f = [0.5 * reduce(mul, individual[:obj-1], 1) * (1 + g)]
Expand All @@ -497,17 +497,17 @@ def dtlz2(individual, obj):
The individual must have at least *obj* elements.
From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable Multi-Objective
Optimization Test Problems. CEC 2002, p. 825 - 830, IEEE Press, 2002.
:math:`g(\\mathbf{x}_m) = \\sum_{x_i \in \\mathbf{x}_m} (x_i - 0.5)^2`
:math:`f_{\\text{DTLZ2}1}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\prod_{i=1}^{m-1} \\cos(0.5x_i\pi)`
:math:`f_{\\text{DTLZ2}2}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\sin(0.5x_{m-1}\pi ) \\prod_{i=1}^{m-2} \\cos(0.5x_i\pi)`
:math:`\\ldots`
:math:`f_{\\text{DTLZ2}m}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\sin(0.5x_{1}\pi )`
Where :math:`m` is the number of objectives and :math:`\\mathbf{x}_m` is a
vector of the remaining attributes :math:`[x_m~\\ldots~x_n]` of the
individual in :math:`n > m` dimensions.
Expand All @@ -525,17 +525,17 @@ def dtlz3(individual, obj):
The individual must have at least *obj* elements.
From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable Multi-Objective
Optimization Test Problems. CEC 2002, p. 825 - 830, IEEE Press, 2002.
:math:`g(\\mathbf{x}_m) = 100\\left(|\\mathbf{x}_m| + \sum_{x_i \in \\mathbf{x}_m}\\left((x_i - 0.5)^2 - \\cos(20\pi(x_i - 0.5))\\right)\\right)`
:math:`f_{\\text{DTLZ3}1}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\prod_{i=1}^{m-1} \\cos(0.5x_i\pi)`
:math:`f_{\\text{DTLZ3}2}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\sin(0.5x_{m-1}\pi ) \\prod_{i=1}^{m-2} \\cos(0.5x_i\pi)`
:math:`\\ldots`
:math:`f_{\\text{DTLZ3}m}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\sin(0.5x_{1}\pi )`
Where :math:`m` is the number of objectives and :math:`\\mathbf{x}_m` is a
vector of the remaining attributes :math:`[x_m~\\ldots~x_n]` of the
individual in :math:`n > m` dimensions.
Expand All @@ -554,17 +554,17 @@ def dtlz4(individual, obj, alpha):
x_i^\\alpha`, the authors suggest :math:`\\alpha = 100`.
From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable Multi-Objective
Optimization Test Problems. CEC 2002, p. 825 - 830, IEEE Press, 2002.
:math:`g(\\mathbf{x}_m) = \\sum_{x_i \in \\mathbf{x}_m} (x_i - 0.5)^2`
:math:`f_{\\text{DTLZ4}1}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\prod_{i=1}^{m-1} \\cos(0.5x_i^\\alpha\pi)`
:math:`f_{\\text{DTLZ4}2}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\sin(0.5x_{m-1}^\\alpha\pi ) \\prod_{i=1}^{m-2} \\cos(0.5x_i^\\alpha\pi)`
:math:`\\ldots`
:math:`f_{\\text{DTLZ4}m}(\\mathbf{x}) = (1 + g(\\mathbf{x}_m)) \\sin(0.5x_{1}^\\alpha\pi )`
Where :math:`m` is the number of objectives and :math:`\\mathbf{x}_m` is a
vector of the remaining attributes :math:`[x_m~\\ldots~x_n]` of the
individual in :math:`n > m` dimensions.
Expand All @@ -584,10 +584,10 @@ def dtlz5(ind, n_objs):
"""
g = lambda x: sum([(a - 0.5)**2 for a in x])
gval = g(ind[n_objs-1:])

theta = lambda x: pi / (4.0 * (1 + gval)) * (1 + 2 * gval * x)
fit = [(1 + gval) * cos(pi / 2.0 * ind[0]) * reduce(lambda x,y: x*y, [cos(theta(a)) for a in ind[1:]])]

for m in reversed(range(1, n_objs)):
if m == 1:
fit.append((1 + gval) * sin(pi / 2.0 * ind[0]))
Expand All @@ -604,7 +604,7 @@ def dtlz6(ind, n_objs):
"""
gval = sum([a**0.1 for a in ind[n_objs-1:]])
theta = lambda x: pi / (4.0 * (1 + gval)) * (1 + 2 * gval * x)

fit = [(1 + gval) * cos(pi / 2.0 * ind[0]) *
reduce(lambda x,y: x*y, [cos(theta(a)) for a in ind[1:]])]

Expand Down Expand Up @@ -633,9 +633,9 @@ def fonseca(individual):
multiple constraint handling with evolutionary algorithms -- Part II:
Application example", IEEE Transactions on Systems, Man and Cybernetics,
1998.
:math:`f_{\\text{Fonseca}1}(\\mathbf{x}) = 1 - e^{-\\sum_{i=1}^{3}(x_i - \\frac{1}{\\sqrt{3}})^2}`
:math:`f_{\\text{Fonseca}2}(\\mathbf{x}) = 1 - e^{-\\sum_{i=1}^{3}(x_i + \\frac{1}{\\sqrt{3}})^2}`
"""
f_1 = 1 - exp(-sum((xi - 1/sqrt(3))**2 for xi in individual[:3]))
Expand All @@ -646,17 +646,17 @@ def poloni(individual):
"""Poloni's multiobjective function on a two attribute *individual*. From:
C. Poloni, "Hybrid GA for multi objective aerodynamic shape optimization",
in Genetic Algorithms in Engineering and Computer Science, 1997.
:math:`A_1 = 0.5 \\sin (1) - 2 \\cos (1) + \\sin (2) - 1.5 \\cos (2)`
:math:`A_2 = 1.5 \\sin (1) - \\cos (1) + 2 \\sin (2) - 0.5 \\cos (2)`
:math:`B_1 = 0.5 \\sin (x_1) - 2 \\cos (x_1) + \\sin (x_2) - 1.5 \\cos (x_2)`
:math:`B_2 = 1.5 \\sin (x_1) - cos(x_1) + 2 \\sin (x_2) - 0.5 \\cos (x_2)`
:math:`f_{\\text{Poloni}1}(\\mathbf{x}) = 1 + (A_1 - B_1)^2 + (A_2 - B_2)^2`
:math:`f_{\\text{Poloni}2}(\\mathbf{x}) = (x_1 + 3)^2 + (x_2 + 1)^2`
"""
x_1 = individual[0]
Expand Down
Loading

0 comments on commit bfd3af8

Please sign in to comment.