@@ -90,7 +90,11 @@ def _true_evaluate(self, x: torch.Tensor) -> torch.Tensor:
90
90
91
91
92
92
def griewank_func (x : torch .Tensor ) -> torch .Tensor :
93
- f = 1 / 4000 * torch .sum (x ** 2 , dim = 1 ) - torch .prod (torch .cos (x / torch .sqrt (torch .arange (1 , x .size (1 ) + 1 , device = x .device ))), dim = 1 ) + 1
93
+ f = (
94
+ 1 / 4000 * torch .sum (x ** 2 , dim = 1 )
95
+ - torch .prod (torch .cos (x / torch .sqrt (torch .arange (1 , x .size (1 ) + 1 , device = x .device ))), dim = 1 )
96
+ + 1
97
+ )
94
98
return f
95
99
96
100
@@ -202,9 +206,9 @@ def ellipsoid_func(x: torch.Tensor):
202
206
def zakharov_func (x : torch .Tensor ) -> torch .Tensor :
203
207
d = x .size (- 1 )
204
208
i = torch .arange (1 , d + 1 , dtype = x .dtype , device = x .device )
205
- sum1 = torch .sum (x ** 2 , dim = - 1 )
209
+ sum1 = torch .sum (x ** 2 , dim = - 1 )
206
210
sum2 = torch .sum (0.5 * i * x , dim = - 1 )
207
- return sum1 + sum2 ** 2 + sum2 ** 4
211
+ return sum1 + sum2 ** 2 + sum2 ** 4
208
212
209
213
210
214
class Zakharov (ShiftAffineNumericalProblem ):
@@ -220,13 +224,15 @@ def __init__(self, **kwargs):
220
224
def _true_evaluate (self , x : torch .Tensor ) -> torch .Tensor :
221
225
return zakharov_func (x )
222
226
227
+
223
228
def levy_func (x : torch .Tensor ) -> torch .Tensor :
224
229
w = 1 + (x - 1 ) / 4
225
230
term1 = torch .sin (torch .pi * w [:, 0 ]) ** 2
226
231
term2 = torch .sum ((w [:, :- 1 ] - 1 ) ** 2 * (1 + 10 * torch .sin (torch .pi * w [:, :- 1 ] + 1 ) ** 2 ), dim = 1 )
227
232
term3 = (w [:, - 1 ] - 1 ) ** 2 * (1 + torch .sin (2 * torch .pi * w [:, - 1 ]) ** 2 )
228
233
return term1 + term2 + term3
229
234
235
+
230
236
class Levy (ShiftAffineNumericalProblem ):
231
237
"""The Levy function whose minimum is x = [1, ..., 1]"""
232
238
0 commit comments