Skip to content

Commit d1b7684

Browse files
committed
add 1d test-functions
1 parent a63e41c commit d1b7684

File tree

6 files changed

+230
-4
lines changed

6 files changed

+230
-4
lines changed

src/surfaces/test_functions/algebraic/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"""Algebraic test functions with closed-form analytical expressions."""
66

77
from ._base_algebraic_function import AlgebraicFunction, MathematicalFunction
8+
from .test_functions_1d.damped_sine_function import DampedSineFunction
9+
from .test_functions_1d.forrester_function import ForresterFunction
810
from .test_functions_1d.gramacy_and_lee_function import GramacyAndLeeFunction
11+
from .test_functions_1d.quadratic_exponential_function import QuadraticExponentialFunction
12+
from .test_functions_1d.sine_product_function import SineProductFunction
913
from .test_functions_2d.ackley_function import AckleyFunction
1014
from .test_functions_2d.beale_function import BealeFunction
1115
from .test_functions_2d.booth_function import BoothFunction
@@ -36,9 +40,11 @@
3640
"BoothFunction",
3741
"BukinFunctionN6",
3842
"CrossInTrayFunction",
43+
"DampedSineFunction",
3944
"DropWaveFunction",
4045
"EasomFunction",
4146
"EggholderFunction",
47+
"ForresterFunction",
4248
"GoldsteinPriceFunction",
4349
"GramacyAndLeeFunction",
4450
"GriewankFunction",
@@ -48,10 +54,12 @@
4854
"LeviFunctionN13",
4955
"MatyasFunction",
5056
"McCormickFunction",
57+
"QuadraticExponentialFunction",
5158
"RastriginFunction",
5259
"RosenbrockFunction",
5360
"SchafferFunctionN2",
5461
"SimionescuFunction",
62+
"SineProductFunction",
5563
"SphereFunction",
5664
"StyblinskiTangFunction",
5765
"ThreeHumpCamelFunction",
@@ -63,9 +71,11 @@
6371
BoothFunction,
6472
BukinFunctionN6,
6573
CrossInTrayFunction,
74+
DampedSineFunction,
6675
DropWaveFunction,
6776
EasomFunction,
6877
EggholderFunction,
78+
ForresterFunction,
6979
GoldsteinPriceFunction,
7080
GramacyAndLeeFunction,
7181
GriewankFunction,
@@ -75,10 +85,12 @@
7585
LeviFunctionN13,
7686
MatyasFunction,
7787
McCormickFunction,
88+
QuadraticExponentialFunction,
7889
RastriginFunction,
7990
RosenbrockFunction,
8091
SchafferFunctionN2,
8192
SimionescuFunction,
93+
SineProductFunction,
8294
SphereFunction,
8395
StyblinskiTangFunction,
8496
ThreeHumpCamelFunction,
@@ -88,7 +100,11 @@
88100
mathematical_functions = algebraic_functions
89101

90102
algebraic_functions_1d = [
103+
DampedSineFunction,
104+
ForresterFunction,
91105
GramacyAndLeeFunction,
106+
QuadraticExponentialFunction,
107+
SineProductFunction,
92108
]
93109
mathematical_functions_1d = algebraic_functions_1d
94110

src/surfaces/test_functions/algebraic/test_functions_1d/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
# License: MIT License
44

55

6+
from .damped_sine_function import DampedSineFunction
7+
from .forrester_function import ForresterFunction
68
from .gramacy_and_lee_function import GramacyAndLeeFunction
9+
from .quadratic_exponential_function import QuadraticExponentialFunction
10+
from .sine_product_function import SineProductFunction
711

812
__all__ = [
13+
"DampedSineFunction",
14+
"ForresterFunction",
915
"GramacyAndLeeFunction",
16+
"QuadraticExponentialFunction",
17+
"SineProductFunction",
1018
]
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Author: Simon Blanke
2+
3+
# License: MIT License
4+
5+
6+
import numpy as np
7+
8+
from .._base_algebraic_function import AlgebraicFunction
9+
10+
11+
class DampedSineFunction(AlgebraicFunction):
12+
"""Damped Sine one-dimensional test function.
13+
14+
A one-dimensional test function combining sine and linear terms
15+
with Gaussian damping. The exponential decay creates a localized
16+
oscillatory region near the origin.
17+
18+
The function is defined as:
19+
20+
.. math::
21+
22+
f(x) = -(x + \\sin(x)) e^{-x^2}
23+
24+
Parameters
25+
----------
26+
metric : str, default="score"
27+
Either "loss" (minimize) or "score" (maximize).
28+
sleep : float, default=0
29+
Artificial delay in seconds added to each evaluation.
30+
31+
Attributes
32+
----------
33+
n_dim : int
34+
Number of dimensions (always 1).
35+
default_bounds : tuple
36+
Default parameter bounds (-10, 10).
37+
38+
References
39+
----------
40+
.. [1] AMPGO (Adaptive Memory Programming for Global Optimization)
41+
benchmark suite, Problem06.
42+
http://infinity77.net/global_optimization/test_functions_1d.html
43+
44+
.. [2] Gavana, A. (2013). "Global Optimization Benchmarks and AMPGO".
45+
46+
Examples
47+
--------
48+
>>> from surfaces.test_functions import DampedSineFunction
49+
>>> func = DampedSineFunction()
50+
>>> func({"x0": 0.6796}) # Near global minimum
51+
-0.824...
52+
>>> search_space = func.search_space
53+
>>> len(search_space)
54+
1
55+
"""
56+
57+
name = "Damped Sine Function"
58+
_name_ = "damped_sine_function"
59+
__name__ = "DampedSineFunction"
60+
61+
_spec = {
62+
"convex": False,
63+
"unimodal": False,
64+
"separable": True,
65+
"scalable": False,
66+
}
67+
68+
f_global = -0.8242393984760573
69+
x_global = np.array([0.6795787635255166])
70+
71+
default_bounds = (-10.0, 10.0)
72+
n_dim = 1
73+
74+
latex_formula = r"f(x) = -(x + \sin(x)) e^{-x^2}"
75+
pgfmath_formula = "-(#1 + sin(deg(#1))) * exp(-#1^2)"
76+
77+
def __init__(
78+
self,
79+
objective="minimize",
80+
sleep=0,
81+
memory=False,
82+
collect_data=True,
83+
callbacks=None,
84+
catch_errors=None,
85+
noise=None,
86+
):
87+
super().__init__(objective, sleep, memory, collect_data, callbacks, catch_errors, noise)
88+
self.n_dim = 1
89+
90+
def _create_objective_function(self):
91+
def damped_sine_function(params):
92+
x = params["x0"]
93+
94+
return -(x + np.sin(x)) * np.exp(-(x**2))
95+
96+
self.pure_objective_function = damped_sine_function
97+
98+
def _search_space(self, min=-10.0, max=10.0, value_types="array", size=10000):
99+
return super()._create_n_dim_search_space(
100+
min=min, max=max, size=size, value_types=value_types
101+
)

src/surfaces/test_functions/algebraic/test_functions_1d/forrester_function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class ForresterFunction(AlgebraicFunction):
6666
"scalable": False,
6767
}
6868

69-
f_global = -6.020740095378691
70-
x_global = np.array([0.7572489953693498])
69+
f_global = -6.020740055766075
70+
x_global = np.array([0.7572487144081974])
7171

7272
default_bounds = (0.0, 1.0)
7373
n_dim = 1

src/surfaces/test_functions/algebraic/test_functions_1d/quadratic_exponential_function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class QuadraticExponentialFunction(AlgebraicFunction):
6565
"scalable": False,
6666
}
6767

68-
f_global = -3.8504536747755516
69-
x_global = np.array([2.8680336666498003])
68+
f_global = -3.8504507087979953
69+
x_global = np.array([2.8680325095605212])
7070

7171
default_bounds = (1.9, 3.9)
7272
n_dim = 1
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Author: Simon Blanke
2+
3+
# License: MIT License
4+
5+
6+
import numpy as np
7+
8+
from .._base_algebraic_function import AlgebraicFunction
9+
10+
11+
class SineProductFunction(AlgebraicFunction):
12+
"""Sine Product one-dimensional test function.
13+
14+
A one-dimensional test function that multiplies a linear term
15+
with a sine function. The amplitude of oscillations grows with x,
16+
creating increasingly deep valleys at larger values.
17+
18+
The function is defined as:
19+
20+
.. math::
21+
22+
f(x) = -x \\sin(x)
23+
24+
Parameters
25+
----------
26+
metric : str, default="score"
27+
Either "loss" (minimize) or "score" (maximize).
28+
sleep : float, default=0
29+
Artificial delay in seconds added to each evaluation.
30+
31+
Attributes
32+
----------
33+
n_dim : int
34+
Number of dimensions (always 1).
35+
default_bounds : tuple
36+
Default parameter bounds (0, 10).
37+
38+
References
39+
----------
40+
.. [1] AMPGO (Adaptive Memory Programming for Global Optimization)
41+
benchmark suite, Problem10.
42+
http://infinity77.net/global_optimization/test_functions_1d.html
43+
44+
.. [2] Gavana, A. (2013). "Global Optimization Benchmarks and AMPGO".
45+
46+
Examples
47+
--------
48+
>>> from surfaces.test_functions import SineProductFunction
49+
>>> func = SineProductFunction()
50+
>>> func({"x0": 7.9787}) # Near global minimum
51+
-7.916...
52+
>>> search_space = func.search_space
53+
>>> len(search_space)
54+
1
55+
"""
56+
57+
name = "Sine Product Function"
58+
_name_ = "sine_product_function"
59+
__name__ = "SineProductFunction"
60+
61+
_spec = {
62+
"convex": False,
63+
"unimodal": False,
64+
"separable": True,
65+
"scalable": False,
66+
}
67+
68+
f_global = -7.916727371587256
69+
x_global = np.array([7.9786653537049483])
70+
71+
default_bounds = (0.0, 10.0)
72+
n_dim = 1
73+
74+
latex_formula = r"f(x) = -x \sin(x)"
75+
pgfmath_formula = "-#1 * sin(deg(#1))"
76+
77+
def __init__(
78+
self,
79+
objective="minimize",
80+
sleep=0,
81+
memory=False,
82+
collect_data=True,
83+
callbacks=None,
84+
catch_errors=None,
85+
noise=None,
86+
):
87+
super().__init__(objective, sleep, memory, collect_data, callbacks, catch_errors, noise)
88+
self.n_dim = 1
89+
90+
def _create_objective_function(self):
91+
def sine_product_function(params):
92+
x = params["x0"]
93+
94+
return -x * np.sin(x)
95+
96+
self.pure_objective_function = sine_product_function
97+
98+
def _search_space(self, min=0.0, max=10.0, value_types="array", size=10000):
99+
return super()._create_n_dim_search_space(
100+
min=min, max=max, size=size, value_types=value_types
101+
)

0 commit comments

Comments
 (0)