Passed
Push — master ( ae0128...5b0f89 )
by
unknown
02:10 queued 01:07
created

Griewank.__init__()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
"""Implementation of Griewank 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: February 2018
4
5
Authors: Iztok Fister Jr. and Lucija Brezočnik
6
7
License: MIT
8
9
Function: Griewank 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 ∈ [-100, 100], 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) = \sum_{i=1}^D \frac{x_i^2}{4000} -
20
            \prod_{i=1}^D cos(\frac{x_i}{\sqrt{i}}) + 1$
21
    Equation: \begin{equation} f(x) = \sum_{i=1}^D \frac{x_i^2}{4000} -
22
              \prod_{i=1}^D cos(\frac{x_i}{\sqrt{i}}) + 1 \end{equation}
23
    Domain: $-100 \leq x_i \leq 100$
24
25
Reference paper:
26
    Jamil, M., and Yang, X. S. (2013).
27
    A literature survey of benchmark functions for global optimisation problems.
28
    International Journal of Mathematical Modelling and Numerical Optimisation,
29
    4(2), 150-194.
30
"""
31
32
import math
33
34
__all__ = ['Griewank']
35
36
37
class Griewank(object):
38
39
    def __init__(self, Lower=-100, Upper=100):
40
        self.Lower = Lower
41
        self.Upper = Upper
42
43
    @classmethod
44
    def function(cls):
45
        def evaluate(D, sol):
46
47
            val1 = 0.0
48
            val2 = 1.0
49
50
            for i in range(D):
51
                val1 += (math.pow(sol[i], 2) / 4000)
52
                val2 *= (math.cos(sol[i] / math.sqrt(i + 1)))
53
54
            return val1 - val2 + 1
55
56
        return evaluate
57