Skip to content

Commit 226d07d

Browse files
authored
Merge pull request #4 from jungtaekkim/0.1.7
0.1.7
2 parents 6e82748 + 5b1b3f4 commit 226d07d

File tree

106 files changed

+7201
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+7201
-94
lines changed

.github/workflows/pytest.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
- '3.8'
1313
- '3.9'
1414
- '3.10'
15-
runs-on: ubuntu-latest
15+
- '3.11'
16+
runs-on: ubuntu-20.04
1617
steps:
1718
- uses: actions/checkout@v2
1819
- uses: actions/setup-python@v2

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2022 Jungtaek Kim
3+
Copyright (c) 2019-2023 Jungtaek Kim
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# BayesO Benchmarks
1+
<p align="center">
2+
<img src="https://github.com/jungtaekkim/bayeso/blob/main/docs/_static/assets/logo_bayeso_capitalized.svg" width="400" />
3+
</p>
4+
5+
# BayesO Benchmarks: Benchmark Functions for Bayesian Optimization
26
[![Build Status](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml/badge.svg)](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml)
37
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
48

5-
Benchmarks for Bayesian optimization.
9+
This repository provides the implementation of benchmark functions for Bayesian optimization.
610
The details of benchmark functions can be found in [these notes](https://jungtaek.github.io/notes/benchmarks_bo.pdf).
711

12+
* [https://bayeso.org](https://bayeso.org)
13+
814
## Installation
915
We recommend installing it with `virtualenv`.
1016
You can choose one of three installation options.
@@ -64,8 +70,5 @@ Y = obj_fun.output(X)
6470
Y_noise = obj_fun.output_gaussian_noise(X)
6571
```
6672

67-
## Author
68-
* [Jungtaek Kim](https://jungtaek.github.io) (POSTECH)
69-
7073
## License
7174
[MIT License](LICENSE)

bayeso_benchmarks/__init__.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#
22
# author: Jungtaek Kim ([email protected])
3-
# last updated: October 23, 2021
3+
# last updated: January 6, 2023
44
#
55

66

7-
__version__ = '0.1.6'
7+
__version__ = '0.1.7'
88

99

1010
from bayeso_benchmarks.inf_dim_ackley import Ackley
1111
from bayeso_benchmarks.inf_dim_cosines import Cosines
12+
from bayeso_benchmarks.inf_dim_griewank import Griewank
13+
from bayeso_benchmarks.inf_dim_levy import Levy
14+
from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin
1215
from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock
1316
from bayeso_benchmarks.inf_dim_sphere import Sphere
17+
from bayeso_benchmarks.inf_dim_zakharov import Zakharov
1418

1519
from bayeso_benchmarks.one_dim_constant import Constant
1620
from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012
@@ -20,17 +24,58 @@
2024
from bayeso_benchmarks.two_dim_beale import Beale
2125
from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky
2226
from bayeso_benchmarks.two_dim_branin import Branin
27+
from bayeso_benchmarks.two_dim_bukin6 import Bukin6
2328
from bayeso_benchmarks.two_dim_dejong5 import DeJong5
2429
from bayeso_benchmarks.two_dim_dropwave import DropWave
30+
from bayeso_benchmarks.two_dim_easom import Easom
2531
from bayeso_benchmarks.two_dim_eggholder import Eggholder
2632
from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice
2733
from bayeso_benchmarks.two_dim_holdertable import HolderTable
2834
from bayeso_benchmarks.two_dim_kim1 import Kim1
2935
from bayeso_benchmarks.two_dim_kim2 import Kim2
3036
from bayeso_benchmarks.two_dim_kim3 import Kim3
3137
from bayeso_benchmarks.two_dim_michalewicz import Michalewicz
38+
from bayeso_benchmarks.two_dim_shubert import Shubert
3239
from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel
3340
from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel
3441

42+
from bayeso_benchmarks.four_dim_colville import Colville
3543
from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D
3644
from bayeso_benchmarks.six_dim_hartmann6d import Hartmann6D
45+
46+
47+
all_benchmarks = [
48+
Ackley,
49+
Cosines,
50+
Griewank,
51+
Levy,
52+
Rastrigin,
53+
Rosenbrock,
54+
Sphere,
55+
Zakharov,
56+
Constant,
57+
GramacyAndLee2012,
58+
Linear,
59+
Step,
60+
Beale,
61+
Bohachevsky,
62+
Branin,
63+
Bukin6,
64+
DeJong5,
65+
DropWave,
66+
Easom,
67+
Eggholder,
68+
GoldsteinPrice,
69+
HolderTable,
70+
Kim1,
71+
Kim2,
72+
Kim3,
73+
Michalewicz,
74+
Shubert,
75+
SixHumpCamel,
76+
ThreeHumpCamel,
77+
Colville,
78+
Hartmann3D,
79+
Hartmann6D,
80+
]
81+
num_benchmarks = len(all_benchmarks)

bayeso_benchmarks/benchmark_base.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#
22
# author: Jungtaek Kim ([email protected])
3-
# last updated: May 1, 2021
3+
# last updated: December 13, 2022
44
#
55

66
import numpy as np
77

88
EPSILON = 1e-4
99

1010

11-
class Function(object):
11+
class Function:
1212
def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, function, dim_problem=None, seed=None):
1313
assert isinstance(dimensionality, int) or dimensionality is np.inf
1414
assert isinstance(bounds, np.ndarray)
1515
assert isinstance(global_minimizers, np.ndarray)
1616
assert isinstance(global_minimum, float)
1717
assert callable(function)
18-
assert isinstance(dim_problem, int) or dim_problem is None
18+
assert isinstance(dim_problem, (type(None), int))
19+
assert isinstance(seed, (type(None), int))
1920
assert len(bounds.shape) == 2
2021
assert bounds.shape[1] == 2
2122
assert (bounds[:, 0] <= bounds[:, 1]).all()
@@ -30,6 +31,7 @@ def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, fu
3031
self.random_state = np.random.RandomState(seed)
3132

3233
self.validate_properties()
34+
self.set_name()
3335

3436
@property
3537
def dimensionality(self):
@@ -47,6 +49,14 @@ def global_minimizers(self):
4749
def global_minimum(self):
4850
return self._global_minimum
4951

52+
def set_name(self):
53+
name = self.__class__.__name__.lower()
54+
55+
if self.dimensionality is np.inf:
56+
self.name = f'{name}_{self.dim_problem}'
57+
else:
58+
self.name = name
59+
5060
def get_bounds(self):
5161
if self.dimensionality is np.inf:
5262
return np.array(list(self.bounds) * self.dim_problem)
@@ -134,7 +144,7 @@ def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01):
134144

135145
noise = self.random_state.randn(num_X)
136146
mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity
137-
noise *= mask.astype(np.float)
147+
noise *= mask.astype(float)
138148
by += scale_noise * noise
139149

140150
Y = np.expand_dims(by, axis=1)
@@ -172,7 +182,7 @@ def output_sparse_student_t_noise(self, X, scale_noise=0.1, dof=4.0, sparsity=0.
172182

173183
noise = self.random_state.standard_t(dof, size=num_X)
174184
mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity
175-
noise *= mask.astype(np.float)
185+
noise *= mask.astype(float)
176186
by += scale_noise * noise
177187

178188
Y = np.expand_dims(by, axis=1)
@@ -228,3 +238,6 @@ def sample_uniform(self, num_points, seed=None):
228238
points = bounds[:, 0] + (bounds[:, 1] - bounds[:, 0]) * points
229239

230240
return points
241+
242+
def __call__(self, X):
243+
return self.output(X)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# author: Jungtaek Kim ([email protected])
3+
# last updated: December 30, 2022
4+
#
5+
6+
import numpy as np
7+
8+
from bayeso_benchmarks.benchmark_base import Function
9+
10+
11+
def fun_target(bx, dim_bx):
12+
assert len(bx.shape) == 1
13+
assert bx.shape[0] == dim_bx
14+
15+
y = 100.0 * (bx[0]**2 - bx[1])**2
16+
y += (bx[0] - 1.0)**2
17+
y += (bx[2] - 1.0)**2
18+
y += 90.0 * (bx[2]**2 - bx[3])**2
19+
y += 10.1 * ((bx[1] - 1.0)**2 + (bx[3] - 1.0)**2)
20+
y += 19.8 * (bx[1] - 1.0) * (bx[3] - 1.0)
21+
22+
return y
23+
24+
25+
class Colville(Function):
26+
def __init__(self, seed=None):
27+
assert isinstance(seed, (type(None), int))
28+
29+
dim_bx = 4
30+
bounds = np.array([
31+
[-10.0, 10.0],
32+
[-10.0, 10.0],
33+
[-10.0, 10.0],
34+
[-10.0, 10.0],
35+
])
36+
assert bounds.shape[0] == dim_bx
37+
assert bounds.shape[1] == 2
38+
39+
global_minimizers = np.array([
40+
[1.0, 1.0, 1.0, 1.0],
41+
])
42+
global_minimum = 0.0
43+
function = lambda bx: fun_target(bx, dim_bx)
44+
45+
try:
46+
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
47+
except:
48+
super(Colville, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# author: Jungtaek Kim ([email protected])
3+
# last updated: January 6, 2023
4+
#
5+
6+
import numpy as np
7+
8+
from bayeso_benchmarks.benchmark_base import Function
9+
10+
11+
def fun_target(bx, dim_bx):
12+
assert len(bx.shape) == 1
13+
assert bx.shape[0] == dim_bx
14+
15+
first_term = np.sum(bx**2 / 4000.0)
16+
17+
second_term = 1.0
18+
for ind in range(1, dim_bx + 1):
19+
second_term *= np.cos(bx[ind - 1] / np.sqrt(ind))
20+
21+
y = first_term - second_term + 1.0
22+
return y
23+
24+
25+
class Griewank(Function):
26+
def __init__(self, dim_problem, seed=None):
27+
assert isinstance(dim_problem, int)
28+
assert isinstance(seed, (type(None), int))
29+
30+
dim_bx = np.inf
31+
bounds = np.array([
32+
[-600.0, 600.0],
33+
])
34+
global_minimizers = np.array([
35+
[0.0],
36+
])
37+
global_minimum = 0.0
38+
dim_problem = dim_problem
39+
40+
function = lambda bx: fun_target(bx, dim_problem)
41+
42+
try:
43+
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
44+
except:
45+
super(Griewank, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)

bayeso_benchmarks/inf_dim_levy.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# author: Jungtaek Kim ([email protected])
3+
# last updated: December 29, 2022
4+
#
5+
6+
import numpy as np
7+
8+
from bayeso_benchmarks.benchmark_base import Function
9+
10+
11+
def fun_target(bx, dim_bx,
12+
):
13+
assert len(bx.shape) == 1
14+
assert bx.shape[0] == dim_bx
15+
16+
bw = []
17+
for x in bx:
18+
w = 1.0 + (x - 1.0) / 4.0
19+
bw.append(w)
20+
bw = np.array(bw)
21+
22+
y = np.sin(np.pi * bw[0])**2
23+
24+
for w in bw[:-1]:
25+
y += (w - 1.0)**2 * (1.0 + 10.0 * np.sin(np.pi * w + 1.0)**2)
26+
27+
y += (bw[-1] - 1.0)**2 * (1.0 + np.sin(2.0 * np.pi * bw[-1])**2)
28+
return y
29+
30+
31+
class Levy(Function):
32+
def __init__(self, dim_problem, seed=None):
33+
assert isinstance(dim_problem, int)
34+
assert isinstance(seed, (type(None), int))
35+
36+
dim_bx = np.inf
37+
bounds = np.array([
38+
[-10.0, 10.0],
39+
])
40+
global_minimizers = np.array([
41+
[1.0],
42+
])
43+
global_minimum = 0.0
44+
dim_problem = dim_problem
45+
46+
function = lambda bx: fun_target(bx, dim_problem)
47+
48+
try:
49+
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
50+
except:
51+
super(Levy, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# author: Jungtaek Kim ([email protected])
3+
# last updated: December 20, 2022
4+
#
5+
6+
import numpy as np
7+
8+
from bayeso_benchmarks.benchmark_base import Function
9+
10+
11+
def fun_target(bx, dim_bx):
12+
assert len(bx.shape) == 1
13+
assert bx.shape[0] == dim_bx
14+
15+
y = 10.0 * dim_bx
16+
17+
for ind in range(0, dim_bx):
18+
y += bx[ind]**2 - 10.0 * np.cos(2.0 * np.pi * bx[ind])
19+
20+
return y
21+
22+
23+
class Rastrigin(Function):
24+
def __init__(self, dim_problem, seed=None):
25+
assert isinstance(dim_problem, int)
26+
assert isinstance(seed, (type(None), int))
27+
28+
dim_bx = np.inf
29+
bounds = np.array([
30+
[-5.12, 5.12],
31+
])
32+
global_minimizers = np.array([
33+
[0.0],
34+
])
35+
global_minimum = 0.0
36+
dim_problem = dim_problem
37+
38+
function = lambda bx: fun_target(bx, dim_problem)
39+
40+
try:
41+
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
42+
except:
43+
super(Rastrigin, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)

0 commit comments

Comments
 (0)