1
|
|
|
# encoding=utf8 |
2
|
|
|
|
3
|
|
|
"""Implementations of HGBat functions.""" |
4
|
|
|
|
5
|
|
|
from math import fabs |
6
|
|
|
from NiaPy.benchmarks.benchmark import Benchmark |
7
|
|
|
|
8
|
|
|
__all__ = ['HGBat'] |
9
|
|
|
|
10
|
|
|
class HGBat(Benchmark): |
11
|
|
|
r"""Implementations of HGBat functions. |
12
|
|
|
|
13
|
|
|
Date: 2018 |
14
|
|
|
|
15
|
|
|
Author: Klemen Berkovič |
16
|
|
|
|
17
|
|
|
License: MIT |
18
|
|
|
|
19
|
|
|
Function: |
20
|
|
|
**HGBat Function** |
21
|
|
|
:math:`f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5` |
22
|
|
|
|
23
|
|
|
**Input domain:** |
24
|
|
|
The function can be defined on any input domain but it is usually |
25
|
|
|
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`. |
26
|
|
|
|
27
|
|
|
**Global minimum:** |
28
|
|
|
:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)` |
29
|
|
|
|
30
|
|
|
LaTeX formats: |
31
|
|
|
Inline: |
32
|
|
|
$$f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5 |
33
|
|
|
|
34
|
|
|
Equation: |
35
|
|
|
\begin{equation} f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5 \end{equation} |
36
|
|
|
|
37
|
|
|
Domain: |
38
|
|
|
$-100 \leq x_i \leq 100$ |
39
|
|
|
|
40
|
|
|
Reference: |
41
|
|
|
http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf |
42
|
|
|
""" |
43
|
|
|
Name = ['HGBat'] |
44
|
|
|
|
45
|
|
|
def __init__(self, Lower=-100.0, Upper=100.0): |
46
|
|
|
r"""Initialize of HGBat benchmark. |
47
|
|
|
|
48
|
|
|
Args: |
49
|
|
|
Lower (Optional[float]): Lower bound of problem. |
50
|
|
|
Upper (Optional[float]): Upper bound of problem. |
51
|
|
|
|
52
|
|
|
See Also: |
53
|
|
|
:func:`NiaPy.benchmarks.Benchmark.__init__` |
54
|
|
|
""" |
55
|
|
|
Benchmark.__init__(self, Lower, Upper) |
56
|
|
|
|
57
|
|
|
@staticmethod |
58
|
|
|
def latex_code(): |
59
|
|
|
r"""Return the latex code of the problem. |
60
|
|
|
|
61
|
|
|
Returns: |
62
|
|
|
str: Latex code |
63
|
|
|
""" |
64
|
|
|
return r'''$f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5$''' |
65
|
|
|
|
66
|
|
|
def function(self): |
67
|
|
|
r"""Return benchmark evaluation function. |
68
|
|
|
|
69
|
|
|
Returns: |
70
|
|
|
Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function |
71
|
|
|
""" |
72
|
|
|
def f(D, x): |
73
|
|
|
r"""Fitness function. |
74
|
|
|
|
75
|
|
|
Args: |
76
|
|
|
D (int): Dimensionality of the problem |
77
|
|
|
sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check. |
78
|
|
|
|
79
|
|
|
Returns: |
80
|
|
|
float: Fitness value for the solution. |
81
|
|
|
""" |
82
|
|
|
val1, val2 = 0.0, 0.0 |
83
|
|
|
for i in range(D): val1 += x[i] ** 2 |
84
|
|
|
for i in range(D): val2 += x[i] |
85
|
|
|
return fabs(val1 ** 2 - val2 ** 2) ** (1 / 2) + (0.5 * val1 + val2) / D + 0.5 |
86
|
|
|
return f |
87
|
|
|
|
88
|
|
|
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3 |
89
|
|
|
|