|
1
|
|
|
# encoding=utf8 |
|
2
|
|
|
|
|
3
|
|
|
"""Implementations of Alpine functions.""" |
|
4
|
|
|
|
|
5
|
|
|
import math |
|
6
|
|
|
from NiaPy.benchmarks.benchmark import Benchmark |
|
7
|
|
|
|
|
8
|
|
|
__all__ = ['Alpine1', 'Alpine2'] |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class Alpine1(Benchmark): |
|
12
|
|
|
r"""Implementation of Alpine1 function. |
|
13
|
|
|
|
|
14
|
|
|
Date: 2018 |
|
15
|
|
|
|
|
16
|
|
|
Author: Lucija Brezočnik |
|
17
|
|
|
|
|
18
|
|
|
License: MIT |
|
19
|
|
|
|
|
20
|
|
|
Function: **Alpine1 function** |
|
21
|
|
|
|
|
22
|
|
|
:math:`f(\mathbf{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert` |
|
23
|
|
|
|
|
24
|
|
|
**Input domain:** |
|
25
|
|
|
The function can be defined on any input domain but it is usually |
|
26
|
|
|
evaluated on the hypercube :math:`x_i ∈ [-10, 10]`, for all :math:`i = 1, 2,..., D`. |
|
27
|
|
|
|
|
28
|
|
|
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (0,...,0)` |
|
29
|
|
|
|
|
30
|
|
|
LaTeX formats: |
|
31
|
|
|
Inline: |
|
32
|
|
|
$f(\mathbf{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert$ |
|
33
|
|
|
|
|
34
|
|
|
Equation: |
|
35
|
|
|
\begin{equation} f(\mathbf{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert \end{equation} |
|
36
|
|
|
|
|
37
|
|
|
Domain: |
|
38
|
|
|
$-10 \leq x_i \leq 10$ |
|
39
|
|
|
|
|
40
|
|
|
Reference paper: |
|
41
|
|
|
Jamil, M., and Yang, X. S. (2013). |
|
42
|
|
|
A literature survey of benchmark functions for global optimisation problems. |
|
43
|
|
|
International Journal of Mathematical Modelling and Numerical Optimisation, |
|
44
|
|
|
4(2), 150-194. |
|
45
|
|
|
""" |
|
46
|
|
|
Name = ['Alpine1'] |
|
47
|
|
|
|
|
48
|
|
|
def __init__(self, Lower=-10.0, Upper=10.0): |
|
49
|
|
|
r"""Initialize of Alpine1 benchmark. |
|
50
|
|
|
|
|
51
|
|
|
Args: |
|
52
|
|
|
Lower (Optional[float]): Lower bound of problem. |
|
53
|
|
|
Upper (Optional[float]): Upper bound of problem. |
|
54
|
|
|
|
|
55
|
|
|
See Also: |
|
56
|
|
|
:func:`NiaPy.benchmarks.Benchmark.__init__` |
|
57
|
|
|
""" |
|
58
|
|
|
Benchmark.__init__(self, Lower, Upper) |
|
59
|
|
|
|
|
60
|
|
|
@staticmethod |
|
61
|
|
|
def latex_code(): |
|
62
|
|
|
r"""Return the latex code of the problem. |
|
63
|
|
|
|
|
64
|
|
|
Returns: |
|
65
|
|
|
str: Latex code |
|
66
|
|
|
""" |
|
67
|
|
|
return r'''$f(\mathbf{x}) = \sum_{i=1}^{D} \lvert x_i \sin(x_i)+0.1x_i \rvert$''' |
|
68
|
|
|
|
|
69
|
|
|
def function(self): |
|
70
|
|
|
r"""Return benchmark evaluation function. |
|
71
|
|
|
|
|
72
|
|
|
Returns: |
|
73
|
|
|
Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function |
|
74
|
|
|
""" |
|
75
|
|
|
def evaluate(D, sol): |
|
76
|
|
|
r"""Fitness function. |
|
77
|
|
|
|
|
78
|
|
|
Args: |
|
79
|
|
|
D (int): Dimensionality of the problem |
|
80
|
|
|
sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check. |
|
81
|
|
|
|
|
82
|
|
|
Returns: |
|
83
|
|
|
float: Fitness value for the solution. |
|
84
|
|
|
""" |
|
85
|
|
|
val = 0.0 |
|
86
|
|
|
|
|
87
|
|
|
for i in range(D): |
|
88
|
|
|
val += abs(math.sin(sol[i]) + 0.1 * sol[i]) |
|
89
|
|
|
|
|
90
|
|
|
return val |
|
91
|
|
|
|
|
92
|
|
|
return evaluate |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
class Alpine2(Benchmark): |
|
96
|
|
|
r"""Implementation of Alpine2 function. |
|
97
|
|
|
|
|
98
|
|
|
Date: 2018 |
|
99
|
|
|
|
|
100
|
|
|
Author: Lucija Brezočnik |
|
101
|
|
|
|
|
102
|
|
|
License: MIT |
|
103
|
|
|
|
|
104
|
|
|
Function: **Alpine2 function** |
|
105
|
|
|
|
|
106
|
|
|
:math:`f(\mathbf{x}) = \prod_{i=1}^{D} \sqrt{x_i} \sin(x_i)` |
|
107
|
|
|
|
|
108
|
|
|
**Input domain:** |
|
109
|
|
|
The function can be defined on any input domain but it is usually |
|
110
|
|
|
evaluated on the hypercube :math:`x_i ∈ [0, 10]`, for all :math:`i = 1, 2,..., D`. |
|
111
|
|
|
|
|
112
|
|
|
**Global minimum:** :math:`f(x^*) = 2.808^D`, at :math:`x^* = (7.917,...,7.917)` |
|
113
|
|
|
|
|
114
|
|
|
LaTeX formats: |
|
115
|
|
|
Inline: |
|
116
|
|
|
$f(\mathbf{x}) = \prod_{i=1}^{D} \sqrt{x_i} \sin(x_i)$ |
|
117
|
|
|
|
|
118
|
|
|
Equation: |
|
119
|
|
|
\begin{equation} f(\mathbf{x}) = |
|
120
|
|
|
\prod_{i=1}^{D} \sqrt{x_i} \sin(x_i) \end{equation} |
|
121
|
|
|
|
|
122
|
|
|
Domain: |
|
123
|
|
|
$0 \leq x_i \leq 10$ |
|
124
|
|
|
|
|
125
|
|
|
Reference paper: |
|
126
|
|
|
Jamil, M., and Yang, X. S. (2013). |
|
127
|
|
|
A literature survey of benchmark functions for global optimisation problems. |
|
128
|
|
|
International Journal of Mathematical Modelling and Numerical Optimisation, |
|
129
|
|
|
4(2), 150-194. |
|
130
|
|
|
""" |
|
131
|
|
|
Name = ['Alpine2'] |
|
132
|
|
|
|
|
133
|
|
|
def __init__(self, Lower=0.0, Upper=10.0): |
|
134
|
|
|
r"""Initialize of Alpine2 benchmark. |
|
135
|
|
|
|
|
136
|
|
|
Args: |
|
137
|
|
|
Lower (Optional[float]): Lower bound of problem. |
|
138
|
|
|
Upper (Optional[float]): Upper bound of problem. |
|
139
|
|
|
|
|
140
|
|
|
See Also: |
|
141
|
|
|
:func:`NiaPy.benchmarks.Benchmark.__init__` |
|
142
|
|
|
""" |
|
143
|
|
|
Benchmark.__init__(self, Lower=Lower, Upper=Upper) |
|
144
|
|
|
|
|
145
|
|
|
@staticmethod |
|
146
|
|
|
def latex_code(): |
|
147
|
|
|
r"""Return the latex code of the problem. |
|
148
|
|
|
|
|
149
|
|
|
Returns: |
|
150
|
|
|
str: Latex code |
|
151
|
|
|
""" |
|
152
|
|
|
return r'''$f(\mathbf{x}) = \prod_{i=1}^{D} \sqrt{x_i} \sin(x_i)$''' |
|
153
|
|
|
|
|
154
|
|
|
def function(self): |
|
155
|
|
|
r"""Return benchmark evaluation function. |
|
156
|
|
|
|
|
157
|
|
|
Returns: |
|
158
|
|
|
Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function |
|
159
|
|
|
""" |
|
160
|
|
|
def evaluate(D, sol): |
|
161
|
|
|
r"""Fitness function. |
|
162
|
|
|
|
|
163
|
|
|
Args: |
|
164
|
|
|
D (int): Dimensionality of the problem |
|
165
|
|
|
sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check. |
|
166
|
|
|
|
|
167
|
|
|
Returns: |
|
168
|
|
|
float: Fitness value for the solution. |
|
169
|
|
|
""" |
|
170
|
|
|
val = 1.0 |
|
171
|
|
|
|
|
172
|
|
|
for i in range(D): |
|
173
|
|
|
val *= math.sqrt(sol[i]) * math.sin(sol[i]) |
|
174
|
|
|
|
|
175
|
|
|
return val |
|
176
|
|
|
|
|
177
|
|
|
return evaluate |
|
178
|
|
|
|