Skip to content

Commit 8bb59fe

Browse files
author
Gabriel Belouze
committed
1 parent 91c37d9 commit 8bb59fe

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

pybenchfunction/function.py

+39-31
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ class AckleyN3:
119119
latex_formula = r'f(x, y) = -200exp(-0.2\sqrt{x^2 + y^2}) + 5exp(cos(3x) + sin(3y))'
120120
latex_formula_dimension = r'd=2'
121121
latex_formula_input_domain = r'x \in [-32, 32], y \in [-32, 32]'
122-
latex_formula_global_minimum = r'f(x, y)\approx-195.629028238419, at$$ $$x=\pm0.682584587365898, and$$ $$ y=-0.36075325513719'
122+
latex_formula_global_minimum = (
123+
r"f(x, y)\approx-186.4112127, at$$ $$x=\approx0.0000000008,"
124+
r" and$$ $$ y\approx-0.0068"
125+
)
123126
continuous = False
124127
convex = False
125128
separable = False
@@ -139,8 +142,8 @@ def __init__(self, d=None):
139142
def get_param(self):
140143
return {}
141144

142-
def get_global_minimum(self, d):
143-
X = np.array([0.682584587365898, -0.36075325513719])
145+
def get_global_minimum(self):
146+
X = np.array([8.27712029e-10, -6.77344009e-03])
144147
return (X, self(X))
145148

146149
def __call__(self, X):
@@ -189,7 +192,7 @@ class Adjiman:
189192
latex_formula = r'f(x, y)=cos(x)sin(y) - \frac{x}{y^2+1}'
190193
latex_formula_dimension = r'd=2'
191194
latex_formula_input_domain = r'x \in [-1, 2], y \in [-1, 1]'
192-
latex_formula_global_minimum = r'f(0, 0)=-2.02181'
195+
latex_formula_global_minimum = r'f(2, 0.10578347)=-2.02181'
193196
continuous = True
194197
convex = False
195198
separable = False
@@ -211,8 +214,7 @@ def get_param(self):
211214
return {}
212215

213216
def get_global_minimum(self, d):
214-
X = np.array([1 / (i + 1) for i in range(d)])
215-
X = np.array([0, 0])
217+
X = np.array([2, 0.10578347])
216218
return (X, self(X))
217219

218220
def __call__(self, X):
@@ -356,7 +358,7 @@ def get_global_minimum(self, d):
356358

357359
def __call__(self, X):
358360
x, y = X
359-
res = (1.5 - x + x*y) **2 + (2.25 - x + x*y**2)**2 + (2.625 - x + x*y**3)*2
361+
res = (1.5 - x + x*y) **2 + (2.25 - x + x*y**2)**2 + (2.625 - x + x*y**3)**2
360362
return res
361363

362364
class Bird:
@@ -801,7 +803,7 @@ class DeckkersAarts:
801803
latex_formula = r'f(x, y) = 10^5x^2 + y^2 -(x^2 + y^2)^2 + 10^{-5}(x^2 + y^2)^4'
802804
latex_formula_dimension = r'd=2'
803805
latex_formula_input_domain = r'x \in [-20, 20], y \in [-20, 20]'
804-
latex_formula_global_minimum = r'f(0, \pm15)\approx25628.906250000004'
806+
latex_formula_global_minimum = r"f(0, \pm15)\approx-17320.76671"
805807
continuous = True
806808
convex = False
807809
separable = False
@@ -858,7 +860,7 @@ def get_param(self):
858860
return {}
859861

860862
def get_global_minimum(self, d):
861-
X = np.array([2**((-2**(i) - 2)/2**i) for i in range(1, d+1)])
863+
X = np.array([2 ** (-((2 ** i) - 2) / 2**i) for i in range(1, d + 1)])
862864
return (X, self(X))
863865

864866
def __call__(self, X):
@@ -1615,11 +1617,15 @@ def get_global_minimum(self, d):
16151617
return (X, self(X))
16161618

16171619
def __call__(self, X):
1618-
d = X.shape[0]
1619-
res = np.sum([(np.sum([((j+1) + self.beta * (X[j] ** (i+1) -j**(i+1)))
1620-
for j in range(d)])) **2
1621-
for i in range(d)])
1622-
return res
1620+
d = X.shape[0]
1621+
j = np.arange(1, d + 1)
1622+
res = np.sum(
1623+
[
1624+
np.sum((j + self.beta) * (X**i - (1 / j) ** i)) ** 2
1625+
for i in range(1, d + 1)
1626+
]
1627+
)
1628+
return res
16231629

16241630
class PermDBeta:
16251631
name = 'Perm d, beta'
@@ -1648,8 +1654,9 @@ def __init__(self, d, beta=0.5):
16481654
def get_param(self):
16491655
return {'beta': self.beta}
16501656

1651-
def get_global_minimum(self, d):
1652-
X = np.array([1 / (i + 1) for i in range(d)])
1657+
def get_global_minimum(self):
1658+
d = self.d
1659+
X = np.arange(1, d)
16531660
return (X, self(X))
16541661

16551662
def __call__(self, X):
@@ -1953,8 +1960,8 @@ def __call__(self, X):
19531960
res = res + 0.1 * np.sqrt(np.sum(X**2))
19541961
return res
19551962

1956-
class SchaffelN1:
1957-
name = 'Schaffel N. 1'
1963+
class SchafferN1:
1964+
name = 'Schaffer N. 1'
19581965
latex_formula = r'f(x, y)=0.5 + \frac{sin^2(x^2+y^2)^2-0.5}{(1+0.001(x^2+y^2))^2}'
19591966
latex_formula_dimension = r'd=2'
19601967
latex_formula_input_domain = r'x \in [-100, 100], y \in [-100, 100]'
@@ -1988,8 +1995,8 @@ def __call__(self, X):
19881995
res = 0.5 + (np.sin((x**2 + y**2)**2)**2 - 0.5)/(1 + 0.001*(x**2 + y**2))**2
19891996
return res
19901997

1991-
class SchaffelN2:
1992-
name = 'Schaffel N. 2'
1998+
class SchafferN2:
1999+
name = 'Schaffer N. 2'
19932000
latex_formula = r'f(x, y)=0.5 + \frac{sin^2(x^2-y^2)-0.5}{(1+0.001(x^2+y^2))^2}'
19942001
latex_formula_dimension = r'd=2'
19952002
latex_formula_input_domain = r'x \in [-100, 100], y \in [-100, 100]'
@@ -2023,8 +2030,8 @@ def __call__(self, X):
20232030
res = 0.5 + (np.sin((x**2 + y**2))**2 - 0.5)/(1 + 0.001*(x**2 + y**2))**2
20242031
return res
20252032

2026-
class SchaffelN3:
2027-
name = 'Schaffel N. 3'
2033+
class SchafferN3:
2034+
name = 'Schaffer N. 3'
20282035
latex_formula = r'f(x, y)=0.5 + \frac{sin^2(cos(|x^2-y^2|))-0.5}{(1+0.001(x^2+y^2))^2}'
20292036
latex_formula_dimension = r'd=2'
20302037
latex_formula_input_domain = r'x \in [-100, 100], y \in [-100, 100]'
@@ -2058,9 +2065,9 @@ def __call__(self, X):
20582065
res = 0.5 + (np.sin(np.cos(np.abs(x**2 + y**2)))**2 - 0.5)/(1 + 0.001*(x**2 + y**2))**2
20592066
return res
20602067

2061-
class SchaffelN4:
2062-
name = 'Schaffel N. 4'
2063-
latex_formula = r'f(x, y)=0.5 + \frac{sin^2(cos(|x^2-y^2|))-0.5}{(1+0.001(x^2+y^2))^2}'
2068+
class SchafferN4:
2069+
name = 'Schaffer N. 4'
2070+
latex_formula = r"f(x, y)=0.5 + \frac{cos^2(sin(|x^2-y^2|))-0.5}{(1+0.001(x^2+y^2))^2}"
20642071
latex_formula_dimension = r'd=2'
20652072
latex_formula_input_domain = r'x \in [-100, 100], y \in [-100, 100]'
20662073
latex_formula_global_minimum = r'f(0, 1.253115)\approx0.292579'
@@ -2090,7 +2097,7 @@ def get_global_minimum(self, d):
20902097

20912098
def __call__(self, X):
20922099
x, y = X
2093-
res = 0.5 + (np.cos(np.sin(np.abs(x**2 + y**2)))**2 - 0.5)/(1 + 0.001*(x**2 + y**2))**2
2100+
res = 0.5 + (np.cos(np.sin(np.abs(x**2 - y**2)))**2 - 0.5)/(1 + 0.001*(x**2 + y**2))**2
20942101
return res
20952102

20962103
class Schwefel:
@@ -2347,9 +2354,10 @@ def get_global_minimum(self, d):
23472354
return None
23482355

23492356
def __call__(self, X):
2350-
d = X.shape[0]
2351-
for i in range(0,d):
2352-
res = np.prod(np.sum([i * np.cos((j+1)*X[i] + j) for j in range(1, 5+1)]))
2357+
j = np.arange(1, 6)[None, :]
2358+
res = np.cos((j + 1) * X[:, None] + j) \
2359+
.sum(axis=1) \
2360+
.prod()
23532361
return res
23542362

23552363
class ShubertN3:
@@ -2565,7 +2573,7 @@ def __call__(self, X):
25652573

25662574
class Trid:
25672575
name = 'Trid'
2568-
latex_formula = r'f(\mathbf{x})=\sum_{i=1}^{d}(x_i-1)^2-\sum_{i=2}^{d}(x_i-1x_{i-1})'
2576+
latex_formula = r"f(\mathbf{x})=\sum_{i=1}^{d}(x_i-1)^2-\sum_{i=2}^{d}(x_ix_{i-1})"
25692577
latex_formula_dimension = r'd \in \mathbb{N}_{+}^{*}'
25702578
latex_formula_input_domain = r'x_i \in [-d^2, d^2], \forall i \in \llbracket 1, d\rrbracket'
25712579
latex_formula_global_minimum = r'f(\mathbf{x}) =\frac{-d(d+4)(d-1)}{6}, $$$$x_i=i(d+1-i)'
@@ -2596,7 +2604,7 @@ def get_global_minimum(self, d):
25962604
def __call__(self, X):
25972605
d = X.shape[0]
25982606
i = np.arange(1, d+1)
2599-
res = np.sum(X-1)**2 - np.sum(X[1:]*X[:-1])
2607+
res = np.sum((X - 1) ** 2) - np.sum(X[1:] * X[:-1])
26002608
return res
26012609

26022610
class Wolfe:

0 commit comments

Comments
 (0)