Passed
Pull Request — master (#32)
by
unknown
01:05
created

Rastrigin.function()   A

Complexity

Conditions 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 13
rs 9.4285
c 1
b 0
f 1
cc 3
1
"""Implementation of Rastrigin benchmark function.
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \s was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \p was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \e was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \l was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
2
3
Date: 2018
4
5
Authors: Lucija Brezočnik and Iztok Fister Jr.
6
7
License: MIT
8
9
Function: Rastrigin function
10
11
Input domain:
12
    The function can be defined on any input domain but it is usually
13
    evaluated on the hypercube x_i ∈ [-5.12, 5.12], for all i = 1, 2,..., D.
14
15
Global minimum:
16
    f(x*) = 0, at x* = (0,...,0)
17
18
LaTeX formats:
19
    Inline: $f(x) = 10D + \sum_{i=1}^D (x_i^2 -10cos(2\pi x_i))$
20
    Equation: \begin{equation}
21
              f(x) = 10D + \sum_{i=1}^D (x_i^2 -10cos(2\pi x_i))
22
              \end{equation}
23
    Domain: $-5.12 \leq x_i \leq 5.12$
24
25
Reference: https://www.sfu.ca/~ssurjano/rastr.html
26
"""
27
28
import math
29
30
__all__ = ['Rastrigin']
31
32
33
class Rastrigin(object):
34
35
    def __init__(self, Lower=-5.12, Upper=5.12):
36
        self.Lower = Lower
37
        self.Upper = Upper
38
39
    @classmethod
40
    def function(cls):
41
        def evaluate(D, sol):
42
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
43
            val = 0.0
44
45
            for i in range(D):
46
                val += math.pow(sol[i], 2) - (10 * math.cos(2 * math.pi * sol[i]))
47
48
            return 10 * D + val
49
50
        return evaluate
51