@@ -90,7 +90,11 @@ def _true_evaluate(self, x: torch.Tensor) -> torch.Tensor:
9090
9191
9292def 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+ )
9498 return f
9599
96100
@@ -202,9 +206,9 @@ def ellipsoid_func(x: torch.Tensor):
202206def zakharov_func (x : torch .Tensor ) -> torch .Tensor :
203207 d = x .size (- 1 )
204208 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 )
206210 sum2 = torch .sum (0.5 * i * x , dim = - 1 )
207- return sum1 + sum2 ** 2 + sum2 ** 4
211+ return sum1 + sum2 ** 2 + sum2 ** 4
208212
209213
210214class Zakharov (ShiftAffineNumericalProblem ):
@@ -220,13 +224,15 @@ def __init__(self, **kwargs):
220224 def _true_evaluate (self , x : torch .Tensor ) -> torch .Tensor :
221225 return zakharov_func (x )
222226
227+
223228def levy_func (x : torch .Tensor ) -> torch .Tensor :
224229 w = 1 + (x - 1 ) / 4
225230 term1 = torch .sin (torch .pi * w [:, 0 ]) ** 2
226231 term2 = torch .sum ((w [:, :- 1 ] - 1 ) ** 2 * (1 + 10 * torch .sin (torch .pi * w [:, :- 1 ] + 1 ) ** 2 ), dim = 1 )
227232 term3 = (w [:, - 1 ] - 1 ) ** 2 * (1 + torch .sin (2 * torch .pi * w [:, - 1 ]) ** 2 )
228233 return term1 + term2 + term3
229234
235+
230236class Levy (ShiftAffineNumericalProblem ):
231237 """The Levy function whose minimum is x = [1, ..., 1]"""
232238
0 commit comments