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

Rosenbrock.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 Rosenbrock 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 \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: Iztok Fister Jr. and Lucija Brezočnik
6
7
License: MIT
8
9
Function: Rosenbrock 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 ∈ [-30, 30], for all i = 1, 2,..., D.
14
15
Global minimum:
16
    f(x*) = 0, at x* = (1,...,1)
17
18
LaTeX formats:
19
    Inline: $f(x) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2)$
20
    Equation: \begin{equation}
21
              f(x) = \sum_{i=1}^{D-1} (100 (x_{i+1} - x_i^2)^2 + (x_i - 1)^2)
22
              \end{equation}
23
    Domain: $-30 \leq x_i \leq 30$
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__ = ['Rosenbrock']
35
36
37
class Rosenbrock(object):
38
39
    def __init__(self, Lower=-30, Upper=30):
40
        self.Lower = Lower
41
        self.Upper = Upper
42
43
    @classmethod
44
    def function(cls):
45
        def evaluate(D, sol):
46
47
            val = 0.0
48
49
            for i in range(D - 1):
50
                val += 100 * math.pow(sol[i + 1] - math.pow((sol[i]), 2), 2) + math.pow((sol[i] - 1), 2)
51
52
            return val
53
54
        return evaluate
55