diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..77101b0 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,29 @@ +name: pytest + +on: [push, pull_request] + +jobs: + test: + strategy: + matrix: + python-version: + - '3.6' + - '3.7' + - '3.8' + - '3.9' + - '3.10' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools + pip install pytest + pip install scipy + - name: Run pytest + run: | + pip install . + pytest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b7340ca..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: python -dist: xenial -python: - - "2.7" - - "3.5" - - "3.6" - - "3.7" - - "3.8" - - "3.9" -install: - - pip install . -script: - - pip install scipy - - pytest -notifications: - slack: bayeso:FWBoHH9TMqjKUJWkZxCaTNVE diff --git a/LICENSE b/LICENSE index c48865d..c150506 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2021 Jungtaek Kim +Copyright (c) 2019-2022 Jungtaek Kim Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2bd3aae..d81f761 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # BayesO Benchmarks -[![Build Status](https://app.travis-ci.com/jungtaekkim/bayeso-benchmarks.svg?branch=main)](https://app.travis-ci.com/jungtaekkim/bayeso-benchmarks) +[![Build Status](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml/badge.svg)](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) Benchmarks for Bayesian optimization. -The details of benchmark functions can be found in [these notes](http://jungtaek.github.io/notes/benchmarks_bo.pdf). +The details of benchmark functions can be found in [these notes](https://jungtaek.github.io/notes/benchmarks_bo.pdf). ## Installation We recommend installing it with `virtualenv`. @@ -65,10 +65,7 @@ Y_noise = obj_fun.output_gaussian_noise(X) ``` ## Author -* [Jungtaek Kim](http://jungtaek.github.io) (POSTECH) - -## Contact -* Jungtaek Kim: [jtkim@postech.ac.kr](mailto:jtkim@postech.ac.kr) +* [Jungtaek Kim](https://jungtaek.github.io) (POSTECH) ## License [MIT License](LICENSE) diff --git a/bayeso_benchmarks/__init__.py b/bayeso_benchmarks/__init__.py index bb8dd93..e112df7 100644 --- a/bayeso_benchmarks/__init__.py +++ b/bayeso_benchmarks/__init__.py @@ -1,9 +1,10 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: June 24, 2021 +# last updated: October 23, 2021 # -__version__ = '0.1.5' + +__version__ = '0.1.6' from bayeso_benchmarks.inf_dim_ackley import Ackley @@ -24,6 +25,9 @@ from bayeso_benchmarks.two_dim_eggholder import Eggholder from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice from bayeso_benchmarks.two_dim_holdertable import HolderTable +from bayeso_benchmarks.two_dim_kim1 import Kim1 +from bayeso_benchmarks.two_dim_kim2 import Kim2 +from bayeso_benchmarks.two_dim_kim3 import Kim3 from bayeso_benchmarks.two_dim_michalewicz import Michalewicz from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel diff --git a/bayeso_benchmarks/benchmark_base.py b/bayeso_benchmarks/benchmark_base.py index 77aeef3..acda74a 100644 --- a/bayeso_benchmarks/benchmark_base.py +++ b/bayeso_benchmarks/benchmark_base.py @@ -74,6 +74,11 @@ def function(self, bx): def _output(self, X): assert isinstance(X, np.ndarray) + bounds = self.get_bounds() + + assert np.all(X >= bounds[:, 0]) + assert np.all(X <= bounds[:, 1]) + if len(X.shape) == 2: list_results = [self.function(bx) for bx in X] else: @@ -220,6 +225,6 @@ def sample_uniform(self, num_points, seed=None): bounds = self.get_bounds() points = random_state_.uniform(size=(num_points, dim_problem)) - points = (bounds[:, 0] + (bounds[:, 1] - bounds[:, 0])) * points + points = bounds[:, 0] + (bounds[:, 1] - bounds[:, 0]) * points return points diff --git a/bayeso_benchmarks/inf_dim_ackley.py b/bayeso_benchmarks/inf_dim_ackley.py index 5791618..77a1186 100644 --- a/bayeso_benchmarks/inf_dim_ackley.py +++ b/bayeso_benchmarks/inf_dim_ackley.py @@ -40,4 +40,7 @@ def __init__(self, dim_problem, seed=None): function = lambda bx: fun_target(bx, dim_problem) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Ackley, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_cosines.py b/bayeso_benchmarks/inf_dim_cosines.py index f57cb6d..de52158 100644 --- a/bayeso_benchmarks/inf_dim_cosines.py +++ b/bayeso_benchmarks/inf_dim_cosines.py @@ -33,4 +33,7 @@ def __init__(self, dim_problem, seed=None): function = lambda bx: fun_target(bx, dim_problem) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Cosines, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_rosenbrock.py b/bayeso_benchmarks/inf_dim_rosenbrock.py index e8c89c3..e2b12fd 100644 --- a/bayeso_benchmarks/inf_dim_rosenbrock.py +++ b/bayeso_benchmarks/inf_dim_rosenbrock.py @@ -37,4 +37,7 @@ def __init__(self, dim_problem, seed=None): function = lambda bx: fun_target(bx, dim_problem) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Rosenbrock, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_sphere.py b/bayeso_benchmarks/inf_dim_sphere.py index a134d33..a68cf68 100644 --- a/bayeso_benchmarks/inf_dim_sphere.py +++ b/bayeso_benchmarks/inf_dim_sphere.py @@ -36,4 +36,7 @@ def __init__(self, dim_problem, seed=None): function = lambda bx: fun_target(bx, dim_problem) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Sphere, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/one_dim_constant.py b/bayeso_benchmarks/one_dim_constant.py index f951341..cd59f76 100644 --- a/bayeso_benchmarks/one_dim_constant.py +++ b/bayeso_benchmarks/one_dim_constant.py @@ -43,4 +43,7 @@ def __init__(self, global_minimum = constant function = lambda bx: fun_target(bx, dim_bx, constant) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Constant, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/one_dim_gramacyandlee2012.py b/bayeso_benchmarks/one_dim_gramacyandlee2012.py index 7fba3ab..5559f1d 100644 --- a/bayeso_benchmarks/one_dim_gramacyandlee2012.py +++ b/bayeso_benchmarks/one_dim_gramacyandlee2012.py @@ -30,4 +30,7 @@ def __init__(self, seed=None): global_minimum = -0.86901113 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(GramacyAndLee2012, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/one_dim_linear.py b/bayeso_benchmarks/one_dim_linear.py index 70fecf4..6e03550 100644 --- a/bayeso_benchmarks/one_dim_linear.py +++ b/bayeso_benchmarks/one_dim_linear.py @@ -47,4 +47,7 @@ def __init__(self, global_minimum = slope * bounds[0, 1] function = lambda bx: fun_target(bx, dim_bx, slope) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Linear, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/one_dim_step.py b/bayeso_benchmarks/one_dim_step.py index 4d67aa3..9610fe9 100644 --- a/bayeso_benchmarks/one_dim_step.py +++ b/bayeso_benchmarks/one_dim_step.py @@ -55,4 +55,7 @@ def __init__(self, global_minimum = np.min(step_values) function = lambda bx: fun_target(bx, dim_bx, steps, step_values) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Step, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/six_dim_hartmann6d.py b/bayeso_benchmarks/six_dim_hartmann6d.py index b03e612..690e396 100644 --- a/bayeso_benchmarks/six_dim_hartmann6d.py +++ b/bayeso_benchmarks/six_dim_hartmann6d.py @@ -63,4 +63,7 @@ def __init__(self, global_minimum = -3.322368 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Hartmann6D, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/three_dim_hartmann3d.py b/bayeso_benchmarks/three_dim_hartmann3d.py index 29b76fc..0e528a3 100644 --- a/bayeso_benchmarks/three_dim_hartmann3d.py +++ b/bayeso_benchmarks/three_dim_hartmann3d.py @@ -60,4 +60,7 @@ def __init__(self, global_minimum = -3.86278 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Hartmann3D, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_beale.py b/bayeso_benchmarks/two_dim_beale.py index e0ff89f..3abc875 100644 --- a/bayeso_benchmarks/two_dim_beale.py +++ b/bayeso_benchmarks/two_dim_beale.py @@ -31,4 +31,7 @@ def __init__(self, seed=None): global_minimum = 0.0 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Beale, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_bohachevsky.py b/bayeso_benchmarks/two_dim_bohachevsky.py index dfd8c2c..c82364c 100644 --- a/bayeso_benchmarks/two_dim_bohachevsky.py +++ b/bayeso_benchmarks/two_dim_bohachevsky.py @@ -31,4 +31,7 @@ def __init__(self, seed=None): global_minimum = 0.0 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Bohachevsky, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_branin.py b/bayeso_benchmarks/two_dim_branin.py index dea9d4c..28979fc 100644 --- a/bayeso_benchmarks/two_dim_branin.py +++ b/bayeso_benchmarks/two_dim_branin.py @@ -53,4 +53,7 @@ def __init__(self, global_minimum = 0.3978874 function = lambda bx: fun_target(bx, dim_bx, a, b, c, r, s, t) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Branin, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_dejong5.py b/bayeso_benchmarks/two_dim_dejong5.py index e21d297..0199891 100644 --- a/bayeso_benchmarks/two_dim_dejong5.py +++ b/bayeso_benchmarks/two_dim_dejong5.py @@ -48,4 +48,7 @@ def __init__(self, seed=None): global_minimum = 0.9980038 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(DeJong5, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_dropwave.py b/bayeso_benchmarks/two_dim_dropwave.py index 74d3b90..405eb67 100644 --- a/bayeso_benchmarks/two_dim_dropwave.py +++ b/bayeso_benchmarks/two_dim_dropwave.py @@ -31,4 +31,7 @@ def __init__(self, seed=None): global_minimum = -1.0 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(DropWave, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_eggholder.py b/bayeso_benchmarks/two_dim_eggholder.py index 43a2ab6..5395e62 100644 --- a/bayeso_benchmarks/two_dim_eggholder.py +++ b/bayeso_benchmarks/two_dim_eggholder.py @@ -38,4 +38,7 @@ def __init__(self, global_minimum = -959.6406627 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Eggholder, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_goldsteinprice.py b/bayeso_benchmarks/two_dim_goldsteinprice.py index 8922af6..940499f 100644 --- a/bayeso_benchmarks/two_dim_goldsteinprice.py +++ b/bayeso_benchmarks/two_dim_goldsteinprice.py @@ -39,4 +39,7 @@ def __init__(self, seed=None): global_minimum = 3.0 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(GoldsteinPrice, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_holdertable.py b/bayeso_benchmarks/two_dim_holdertable.py index 2c3b0ef..6011272 100644 --- a/bayeso_benchmarks/two_dim_holdertable.py +++ b/bayeso_benchmarks/two_dim_holdertable.py @@ -34,4 +34,7 @@ def __init__(self, seed=None): global_minimum = -19.2085026 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(HolderTable, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_kim1.py b/bayeso_benchmarks/two_dim_kim1.py new file mode 100644 index 0000000..11b6595 --- /dev/null +++ b/bayeso_benchmarks/two_dim_kim1.py @@ -0,0 +1,37 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = np.sin(bx[0]) + np.cos(bx[1]) + 0.016 * (bx[0] - 5.0)**2 + 0.008 * (bx[1] - 5.0)**2 + return y + + +class Kim1(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 2 + bounds = np.array([ + [-16.0, 16.0], + [-16.0, 16.0], + ]) + global_minimizers = np.array([ + [4.72130726, 3.17086303], + ]) + global_minimum = -1.9715232347905773 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Kim1, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_kim2.py b/bayeso_benchmarks/two_dim_kim2.py new file mode 100644 index 0000000..27ec15f --- /dev/null +++ b/bayeso_benchmarks/two_dim_kim2.py @@ -0,0 +1,42 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = np.sin(bx[0] / 1.0) + np.cos(bx[1] / 1.0) \ + + np.sin(bx[0] / 2.0) + np.cos(bx[1] / 2.0) \ + + np.sin(bx[0] / 4.0) + np.cos(bx[1] / 4.0) \ + + np.sin(bx[0] / 8.0) + np.cos(bx[1] / 8.0) \ + + np.sin(bx[0] / 16.0) + np.cos(bx[1] / 16.0) \ + + 0.0032 * (bx[0] - 20.0)**2 + 0.0016 * (bx[1] - 20.0)**2 + return y + + +class Kim2(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 2 + bounds = np.array([ + [-128.0, 128.0], + [-128.0, 128.0], + ]) + global_minimizers = np.array([ + [-2.1013466, 34.14526252], + ]) + global_minimum = -3.454387473489018 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Kim2, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_kim3.py b/bayeso_benchmarks/two_dim_kim3.py new file mode 100644 index 0000000..bb0ffd7 --- /dev/null +++ b/bayeso_benchmarks/two_dim_kim3.py @@ -0,0 +1,52 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np + +from bayeso_benchmarks import utils +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = np.sin(bx[0] / 1.0) + np.cos(bx[1] / 1.0) \ + + np.sin(bx[0] / 2.0) + np.cos(bx[1] / 2.0) \ + + np.sin(bx[0] / 4.0) + np.cos(bx[1] / 4.0) \ + + np.sin(bx[0] / 8.0) + np.cos(bx[1] / 8.0) \ + + np.sin(bx[0] / 16.0) + np.cos(bx[1] / 16.0) \ + + 0.0016 * (bx[0] - 40.0)**2 + 0.0008 * (bx[1] - 40.0)**2 \ + - 256000.0 * utils.pdf_two_dim_normal( + bx, np.array([-120.0, -120.0]), + np.array([[1000.0, 0.0], [0.0, 1000.0]]) + ) \ + - 256000.0 * utils.pdf_two_dim_normal( + bx, np.array([-120.0, +120.0]), + np.array([[1000.0, 0.0], [0.0, 1000.0]]) + ) + + return y + + +class Kim3(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 2 + bounds = np.array([ + [-256.0, 256.0], + [-256.0, 256.0], + ]) + global_minimizers = np.array([ + [48.12477173, 34.19859065], + ]) + global_minimum = -4.943967919350982 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Kim3, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_michalewicz.py b/bayeso_benchmarks/two_dim_michalewicz.py index 215d517..886a5f9 100644 --- a/bayeso_benchmarks/two_dim_michalewicz.py +++ b/bayeso_benchmarks/two_dim_michalewicz.py @@ -36,4 +36,7 @@ def __init__(self, seed=None): global_minimum = -1.8013034 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Michalewicz, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_sixhumpcamel.py b/bayeso_benchmarks/two_dim_sixhumpcamel.py index 20c06ac..80c6283 100644 --- a/bayeso_benchmarks/two_dim_sixhumpcamel.py +++ b/bayeso_benchmarks/two_dim_sixhumpcamel.py @@ -32,4 +32,7 @@ def __init__(self, seed=None): global_minimum = -1.0316 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(SixHumpCamel, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_threehumpcamel.py b/bayeso_benchmarks/two_dim_threehumpcamel.py index 99b8a29..9bf97e8 100644 --- a/bayeso_benchmarks/two_dim_threehumpcamel.py +++ b/bayeso_benchmarks/two_dim_threehumpcamel.py @@ -31,4 +31,7 @@ def __init__(self, seed=None): global_minimum = 0.0 function = lambda bx: fun_target(bx, dim_bx) - Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(ThreeHumpCamel, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/utils.py b/bayeso_benchmarks/utils.py new file mode 100644 index 0000000..7374b7d --- /dev/null +++ b/bayeso_benchmarks/utils.py @@ -0,0 +1,17 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np + + +def pdf_two_dim_normal(bx, mu, Cov): + assert bx.shape[0] == mu.shape[0] == Cov.shape[0] == Cov.shape[1] == 2 + + dim = bx.shape[0] + + term_first = ((2.0 * np.pi)**(-0.5 * dim)) * (np.linalg.det(Cov)**(-0.5)) + term_second = np.exp(-0.5 * np.dot(np.dot((bx - mu), np.linalg.inv(Cov)), bx - mu)) + + return term_first * term_second diff --git a/examples/plot_benchmarks.py b/examples/plot_benchmarks.py index 5b2d105..3813462 100644 --- a/examples/plot_benchmarks.py +++ b/examples/plot_benchmarks.py @@ -160,6 +160,18 @@ def plot_2d(obj_fun, obj_fun = target_class() plot_2d(obj_fun, 'holdertable_2d') + from bayeso_benchmarks.two_dim_kim1 import Kim1 as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'kim1_2d') + + from bayeso_benchmarks.two_dim_kim2 import Kim2 as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'kim2_2d') + + from bayeso_benchmarks.two_dim_kim3 import Kim3 as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'kim3_2d') + from bayeso_benchmarks.two_dim_michalewicz import Michalewicz as target_class obj_fun = target_class() plot_2d(obj_fun, 'michalewicz_2d') diff --git a/figures/ackley_1d.pdf b/figures/ackley_1d.pdf index 86a80a7..610fef5 100644 Binary files a/figures/ackley_1d.pdf and b/figures/ackley_1d.pdf differ diff --git a/figures/ackley_2d.pdf b/figures/ackley_2d.pdf index 0860978..92e2f9a 100644 Binary files a/figures/ackley_2d.pdf and b/figures/ackley_2d.pdf differ diff --git a/figures/beale_2d.pdf b/figures/beale_2d.pdf index ec41266..d06fee7 100644 Binary files a/figures/beale_2d.pdf and b/figures/beale_2d.pdf differ diff --git a/figures/bohachevsky_2d.pdf b/figures/bohachevsky_2d.pdf index 1d7a74f..92bfd5e 100644 Binary files a/figures/bohachevsky_2d.pdf and b/figures/bohachevsky_2d.pdf differ diff --git a/figures/branin_2d.pdf b/figures/branin_2d.pdf index eb78b87..7328230 100644 Binary files a/figures/branin_2d.pdf and b/figures/branin_2d.pdf differ diff --git a/figures/cosines_1d.pdf b/figures/cosines_1d.pdf index fdcfb63..05020b8 100644 Binary files a/figures/cosines_1d.pdf and b/figures/cosines_1d.pdf differ diff --git a/figures/cosines_2d.pdf b/figures/cosines_2d.pdf index 601f810..931316b 100644 Binary files a/figures/cosines_2d.pdf and b/figures/cosines_2d.pdf differ diff --git a/figures/dejong5_2d.pdf b/figures/dejong5_2d.pdf index b3073a9..8e2fd33 100644 Binary files a/figures/dejong5_2d.pdf and b/figures/dejong5_2d.pdf differ diff --git a/figures/dropwave_2d.pdf b/figures/dropwave_2d.pdf index a9b1565..82d8ebf 100644 Binary files a/figures/dropwave_2d.pdf and b/figures/dropwave_2d.pdf differ diff --git a/figures/eggholder_2d.pdf b/figures/eggholder_2d.pdf index eb5ffec..15dcc12 100644 Binary files a/figures/eggholder_2d.pdf and b/figures/eggholder_2d.pdf differ diff --git a/figures/goldsteinprice_2d.pdf b/figures/goldsteinprice_2d.pdf index 38604b0..af8faee 100644 Binary files a/figures/goldsteinprice_2d.pdf and b/figures/goldsteinprice_2d.pdf differ diff --git a/figures/gramacyandlee2012.pdf b/figures/gramacyandlee2012.pdf index a1bc660..4affb26 100644 Binary files a/figures/gramacyandlee2012.pdf and b/figures/gramacyandlee2012.pdf differ diff --git a/figures/holdertable_2d.pdf b/figures/holdertable_2d.pdf index cb1338d..ea5948b 100644 Binary files a/figures/holdertable_2d.pdf and b/figures/holdertable_2d.pdf differ diff --git a/figures/kim1_2d.pdf b/figures/kim1_2d.pdf new file mode 100644 index 0000000..5f8b90e Binary files /dev/null and b/figures/kim1_2d.pdf differ diff --git a/figures/kim2_2d.pdf b/figures/kim2_2d.pdf new file mode 100644 index 0000000..4172c3e Binary files /dev/null and b/figures/kim2_2d.pdf differ diff --git a/figures/kim3_2d.pdf b/figures/kim3_2d.pdf new file mode 100644 index 0000000..8a1b595 Binary files /dev/null and b/figures/kim3_2d.pdf differ diff --git a/figures/michalewicz_2d.pdf b/figures/michalewicz_2d.pdf index 5baa665..8f88935 100644 Binary files a/figures/michalewicz_2d.pdf and b/figures/michalewicz_2d.pdf differ diff --git a/figures/rosenbrock_2d.pdf b/figures/rosenbrock_2d.pdf index 66b7e07..ed00706 100644 Binary files a/figures/rosenbrock_2d.pdf and b/figures/rosenbrock_2d.pdf differ diff --git a/figures/sixhumpcamel_2d.pdf b/figures/sixhumpcamel_2d.pdf index bcf0b40..524e667 100644 Binary files a/figures/sixhumpcamel_2d.pdf and b/figures/sixhumpcamel_2d.pdf differ diff --git a/figures/sphere_1d.pdf b/figures/sphere_1d.pdf index 73ddeb8..45f36d6 100644 Binary files a/figures/sphere_1d.pdf and b/figures/sphere_1d.pdf differ diff --git a/figures/sphere_2d.pdf b/figures/sphere_2d.pdf index 5942e26..3671f3d 100644 Binary files a/figures/sphere_2d.pdf and b/figures/sphere_2d.pdf differ diff --git a/figures/threehumpcamel_2d.pdf b/figures/threehumpcamel_2d.pdf index f6d8031..bf5378f 100644 Binary files a/figures/threehumpcamel_2d.pdf and b/figures/threehumpcamel_2d.pdf differ diff --git a/setup.py b/setup.py index 5ac7249..f5f770d 100644 --- a/setup.py +++ b/setup.py @@ -8,14 +8,14 @@ setup( name='bayeso-benchmarks', - version='0.1.5', + version='0.1.6', author='Jungtaek Kim', author_email='jtkim@postech.ac.kr', url='https://github.com/jungtaekkim/bayeso-benchmarks', license='MIT', description='Benchmarks for Bayesian optimization', packages=list_packages, - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, != 3.3.*, !=3.4.*, <4', + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, != 3.3.*, !=3.4.*, !=3.5.*, <4', install_requires=required, classifiers=[ 'License :: OSI Approved :: MIT License', diff --git a/tests/test_global_minimum.py b/tests/test_global_minimum.py index 84c1ddf..8269c03 100644 --- a/tests/test_global_minimum.py +++ b/tests/test_global_minimum.py @@ -9,10 +9,11 @@ from bayeso_benchmarks import Ackley from bayeso_benchmarks import Branin -from bayeso_benchmarks import DeJong5 -from bayeso_benchmarks import Eggholder from bayeso_benchmarks import GramacyAndLee2012 from bayeso_benchmarks import HolderTable +from bayeso_benchmarks import Kim1 +from bayeso_benchmarks import Kim2 +from bayeso_benchmarks import Kim3 from bayeso_benchmarks import Michalewicz @@ -62,26 +63,32 @@ def test_global_minimum_branin(): _test_global_minimum(obj_fun) -def test_global_minimum_dejong5(): - class_fun = DeJong5 +def test_global_minimum_gramacyandlee2012(): + class_fun = GramacyAndLee2012 obj_fun = class_fun() _test_global_minimum(obj_fun) -def test_global_minimum_eggholder(): - class_fun = Eggholder +def test_global_minimum_holdertable(): + class_fun = HolderTable obj_fun = class_fun() _test_global_minimum(obj_fun) -def test_global_minimum_gramacyandlee2012(): - class_fun = GramacyAndLee2012 +def test_global_minimum_kim1(): + class_fun = Kim1 obj_fun = class_fun() _test_global_minimum(obj_fun) -def test_global_minimum_holdertable(): - class_fun = HolderTable +def test_global_minimum_kim2(): + class_fun = Kim2 + obj_fun = class_fun() + + _test_global_minimum(obj_fun) + +def test_global_minimum_kim3(): + class_fun = Kim3 obj_fun = class_fun() _test_global_minimum(obj_fun) diff --git a/tests/test_import.py b/tests/test_import.py index 72ccb83..100bee6 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -66,6 +66,21 @@ def test_import_two_dim_holdertable(): from bayeso_benchmarks.two_dim_holdertable import HolderTable from bayeso_benchmarks import HolderTable +def test_import_two_dim_kim1(): + import bayeso_benchmarks.two_dim_kim1 + from bayeso_benchmarks.two_dim_kim1 import Kim1 + from bayeso_benchmarks import Kim1 + +def test_import_two_dim_kim2(): + import bayeso_benchmarks.two_dim_kim2 + from bayeso_benchmarks.two_dim_kim2 import Kim2 + from bayeso_benchmarks import Kim2 + +def test_import_two_dim_kim3(): + import bayeso_benchmarks.two_dim_kim3 + from bayeso_benchmarks.two_dim_kim3 import Kim3 + from bayeso_benchmarks import Kim3 + def test_import_two_dim_michalewicz(): import bayeso_benchmarks.two_dim_michalewicz from bayeso_benchmarks.two_dim_michalewicz import Michalewicz diff --git a/tests/test_two_dim_kim1.py b/tests/test_two_dim_kim1.py new file mode 100644 index 0000000..45ff5d9 --- /dev/null +++ b/tests/test_two_dim_kim1.py @@ -0,0 +1,104 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_kim1 import * + +class_fun = Kim1 + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [9.91424384], + [2.97034052], + [4.2184372], + [8.54390332], + [1.6], + [2.84809668], + [7.35424384], + [0.41034052], + [1.6584372], + ]) + + for elem in obj_fun.output(grids): + print('{},'.format(elem)) + + print(grids) + print(obj_fun.output(grids)) + print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [11.91424384], + [4.97034052], + [6.2184372], + [10.54390332], + [3.6], + [4.84809668], + [9.35424384], + [2.41034052], + [3.6584372], + ]) + + for elem in obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE): + print('{},'.format(elem)) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [10.90767214], + [2.69381192], + [5.51381428], + [11.58996303], + [1.13169325], + [2.37982277], + [10.51266947], + [1.94520998], + [0.71948843], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + for elem in outputs: + print('{},'.format(elem)) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) diff --git a/tests/test_two_dim_kim2.py b/tests/test_two_dim_kim2.py new file mode 100644 index 0000000..b4a821d --- /dev/null +++ b/tests/test_two_dim_kim2.py @@ -0,0 +1,104 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_kim2 import * + +class_fun = Kim2 + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [101.67527989], + [35.75642525], + [74.69517061], + [72.83885464], + [6.92], + [45.85874536], + [85.29127989], + [19.37242525], + [58.31117061], + ]) + + for elem in obj_fun.output(grids): + print('{},'.format(elem)) + + print(grids) + print(obj_fun.output(grids)) + print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [103.67527989], + [37.75642525], + [76.69517061], + [74.83885464], + [8.92], + [47.85874536], + [87.29127989], + [21.37242525], + [60.31117061], + ]) + + for elem in obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE): + print('{},'.format(elem)) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [102.6687082], + [35.47989665], + [75.99054769], + [75.88491435], + [6.45169325], + [45.39047145], + [88.44970553], + [20.90729471], + [57.37222184], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + for elem in outputs: + print('{},'.format(elem)) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) diff --git a/tests/test_two_dim_kim3.py b/tests/test_two_dim_kim3.py new file mode 100644 index 0000000..ef6423f --- /dev/null +++ b/tests/test_two_dim_kim3.py @@ -0,0 +1,104 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: October 27, 2021 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_kim3 import * + +class_fun = Kim3 + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [208.90875507], + [72.1885316], + [145.18351361], + [145.56021506], + [8.83995458], + [81.83497908], + [176.14075507], + [39.4205316], + [112.41551361], + ]) + + for elem in obj_fun.output(grids): + print('{},'.format(elem)) + + print(grids) + print(obj_fun.output(grids)) + print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [210.90875507], + [74.1885316], + [147.18351361], + [147.56021506], + [10.83995458], + [83.83497908], + [178.14075507], + [41.4205316], + [114.41551361], + ]) + + for elem in obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE): + print('{},'.format(elem)) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [209.90218338], + [71.912003], + [146.47889068], + [148.60627477], + [8.37164783], + [81.36670517], + [179.2991807], + [40.95540106], + [111.47656484], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + for elem in outputs: + print('{},'.format(elem)) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) diff --git a/tests/test_version.py b/tests/test_version.py index 1eba15e..f0bb691 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,9 +1,10 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: May 1, 2021 +# last updated: October 23, 2021 # -STR_VERSION = '0.1.5' + +STR_VERSION = '0.1.6' def test_version_bayeso():