@@ 84-156 (lines=73) @@ | ||
81 | return 0.5 + (sin(x[0] ** 2 - x[1] ** 2) ** 2 - 0.5) / (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2 |
|
82 | return f |
|
83 | ||
84 | class SchafferN4(Benchmark): |
|
85 | r"""Implementations of Schaffer N. 2 functions. |
|
86 | ||
87 | Date: 2018 |
|
88 | ||
89 | Author: Klemen Berkovič |
|
90 | ||
91 | License: MIT |
|
92 | ||
93 | Function: |
|
94 | **Schaffer N. 2 Function** |
|
95 | :math:`f(\textbf{x}) = 0.5 + \frac{ \cos^2 \left( \sin \left( x_1^2 - x_2^2 \right) \right)- 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }` |
|
96 | ||
97 | **Input domain:** |
|
98 | The function can be defined on any input domain but it is usually |
|
99 | evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`. |
|
100 | ||
101 | **Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)` |
|
102 | ||
103 | LaTeX formats: |
|
104 | Inline: |
|
105 | $f(\textbf{x}) = 0.5 + \frac{ \cos^2 \left( \sin \left( x_1^2 - x_2^2 \right) \right)- 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }$ |
|
106 | ||
107 | Equation: |
|
108 | \begin{equation} f(\textbf{x}) = 0.5 + \frac{ \cos^2 \left( \sin \left( x_1^2 - x_2^2 \right) \right)- 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 } \end{equation} |
|
109 | ||
110 | Domain: |
|
111 | $-100 \leq x_i \leq 100$ |
|
112 | ||
113 | Reference: |
|
114 | http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf |
|
115 | """ |
|
116 | Name = ['SchafferN4'] |
|
117 | ||
118 | def __init__(self, Lower=-100.0, Upper=100.0): |
|
119 | r"""Initialize of ScahfferN4 benchmark. |
|
120 | ||
121 | Args: |
|
122 | Lower (Optional[float]): Lower bound of problem. |
|
123 | Upper (Optional[float]): Upper bound of problem. |
|
124 | ||
125 | See Also: |
|
126 | :func:`NiaPy.benchmarks.Benchmark.__init__` |
|
127 | """ |
|
128 | Benchmark.__init__(self, Lower, Upper) |
|
129 | ||
130 | @staticmethod |
|
131 | def latex_code(): |
|
132 | r"""Return the latex code of the problem. |
|
133 | ||
134 | Returns: |
|
135 | str: Latex code |
|
136 | """ |
|
137 | return r'''$f(\textbf{x}) = 0.5 + \frac{ \cos^2 \left( \sin \left( x_1^2 - x_2^2 \right) \right)- 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }$''' |
|
138 | ||
139 | def function(self): |
|
140 | r"""Return benchmark evaluation function. |
|
141 | ||
142 | Returns: |
|
143 | Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function |
|
144 | """ |
|
145 | def f(D, x): |
|
146 | r"""Fitness function. |
|
147 | ||
148 | Args: |
|
149 | D (int): Dimensionality of the problem |
|
150 | sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check. |
|
151 | ||
152 | Returns: |
|
153 | float: Fitness value for the solution. |
|
154 | """ |
|
155 | return 0.5 + (cos(sin(x[0] ** 2 - x[1] ** 2)) ** 2 - 0.5) / (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2 |
|
156 | return f |
|
157 | ||
158 | class ExpandedSchaffer(Benchmark): |
|
159 | r"""Implementations of Expanded Schaffer functions. |
|
@@ 10-82 (lines=73) @@ | ||
7 | ||
8 | __all__ = ['SchafferN2', 'SchafferN4', 'ExpandedSchaffer'] |
|
9 | ||
10 | class SchafferN2(Benchmark): |
|
11 | r"""Implementations of Schaffer N. 2 functions. |
|
12 | ||
13 | Date: 2018 |
|
14 | ||
15 | Author: Klemen Berkovič |
|
16 | ||
17 | License: MIT |
|
18 | ||
19 | Function: |
|
20 | **Schaffer N. 2 Function** |
|
21 | :math:`f(\textbf{x}) = 0.5 + \frac{ \sin^2 \left( x_1^2 - x_2^2 \right) - 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }` |
|
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:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)` |
|
28 | ||
29 | LaTeX formats: |
|
30 | Inline: |
|
31 | $f(\textbf{x}) = 0.5 + \frac{ \sin^2 \left( x_1^2 - x_2^2 \right) - 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }$ |
|
32 | ||
33 | Equation: |
|
34 | \begin{equation} f(\textbf{x}) = 0.5 + \frac{ \sin^2 \left( x_1^2 - x_2^2 \right) - 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 } \end{equation} |
|
35 | ||
36 | Domain: |
|
37 | $-100 \leq x_i \leq 100$ |
|
38 | ||
39 | Reference: |
|
40 | http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf |
|
41 | """ |
|
42 | Name = ['SchafferN2'] |
|
43 | ||
44 | def __init__(self, Lower=-100.0, Upper=100.0): |
|
45 | r"""Initialize of SchafferN2 benchmark. |
|
46 | ||
47 | Args: |
|
48 | Lower (Optional[float]): Lower bound of problem. |
|
49 | Upper (Optional[float]): Upper bound of problem. |
|
50 | ||
51 | See Also: |
|
52 | :func:`NiaPy.benchmarks.Benchmark.__init__` |
|
53 | """ |
|
54 | Benchmark.__init__(self, Lower, Upper) |
|
55 | ||
56 | @staticmethod |
|
57 | def latex_code(): |
|
58 | r"""Return the latex code of the problem. |
|
59 | ||
60 | Returns: |
|
61 | str: Latex code |
|
62 | """ |
|
63 | return r'''$f(\textbf{x}) = 0.5 + \frac{ \sin^2 \left( x_1^2 - x_2^2 \right) - 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }$''' |
|
64 | ||
65 | def function(self): |
|
66 | r"""Return benchmark evaluation function. |
|
67 | ||
68 | Returns: |
|
69 | Callable[[int, Union[int, float, List[int, float], numpy.ndarray]], float]: Fitness function |
|
70 | """ |
|
71 | def f(D, x): |
|
72 | r"""Fitness function. |
|
73 | ||
74 | Args: |
|
75 | D (int): Dimensionality of the problem |
|
76 | sol (Union[int, float, List[int, float], numpy.ndarray]): Solution to check. |
|
77 | ||
78 | Returns: |
|
79 | float: Fitness value for the solution. |
|
80 | """ |
|
81 | return 0.5 + (sin(x[0] ** 2 - x[1] ** 2) ** 2 - 0.5) / (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2 |
|
82 | return f |
|
83 | ||
84 | class SchafferN4(Benchmark): |
|
85 | r"""Implementations of Schaffer N. 2 functions. |