├── .github └── workflows │ └── pytest.yml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── bayeso_benchmarks ├── __init__.py ├── benchmark_base.py ├── four_dim_colville.py ├── inf_dim_ackley.py ├── inf_dim_cosines.py ├── inf_dim_griewank.py ├── inf_dim_levy.py ├── inf_dim_rastrigin.py ├── inf_dim_rosenbrock.py ├── inf_dim_sphere.py ├── inf_dim_zakharov.py ├── one_dim_constant.py ├── one_dim_gramacyandlee2012.py ├── one_dim_linear.py ├── one_dim_step.py ├── six_dim_hartmann6d.py ├── three_dim_hartmann3d.py ├── two_dim_beale.py ├── two_dim_bohachevsky.py ├── two_dim_branin.py ├── two_dim_bukin6.py ├── two_dim_dejong5.py ├── two_dim_dropwave.py ├── two_dim_easom.py ├── two_dim_eggholder.py ├── two_dim_goldsteinprice.py ├── two_dim_holdertable.py ├── two_dim_kim1.py ├── two_dim_kim2.py ├── two_dim_kim3.py ├── two_dim_michalewicz.py ├── two_dim_shubert.py ├── two_dim_sixhumpcamel.py ├── two_dim_threehumpcamel.py └── utils.py ├── examples ├── find_global_minimum.py └── plot_benchmarks.py ├── figures ├── ackley_1d.pdf ├── ackley_2d.pdf ├── beale_2d.pdf ├── bohachevsky_2d.pdf ├── branin_2d.pdf ├── bukin6_2d.pdf ├── cosines_1d.pdf ├── cosines_2d.pdf ├── dejong5_2d.pdf ├── dropwave_2d.pdf ├── easom_2d.pdf ├── eggholder_2d.pdf ├── goldsteinprice_2d.pdf ├── gramacyandlee2012_1d.pdf ├── griewank_1d.pdf ├── griewank_2d.pdf ├── griewank_zoom_in_1d.pdf ├── griewank_zoom_in_2d.pdf ├── holdertable_2d.pdf ├── kim1_2d.pdf ├── kim2_2d.pdf ├── kim3_2d.pdf ├── levy_1d.pdf ├── levy_2d.pdf ├── michalewicz_2d.pdf ├── rastrigin_1d.pdf ├── rastrigin_2d.pdf ├── rosenbrock_2d.pdf ├── shubert_2d.pdf ├── sixhumpcamel_2d.pdf ├── sphere_1d.pdf ├── sphere_2d.pdf ├── threehumpcamel_2d.pdf ├── zakharov_1d.pdf └── zakharov_2d.pdf ├── publish_new_release.txt ├── pyproject.toml └── tests ├── test_four_dim_colville.py ├── test_global_minimum.py ├── test_import.py ├── test_inf_dim_ackley.py ├── test_inf_dim_cosines.py ├── test_inf_dim_griewank.py ├── test_inf_dim_levy.py ├── test_inf_dim_rastrigin.py ├── test_inf_dim_rosenbrock.py ├── test_inf_dim_sphere.py ├── test_inf_dim_zakharov.py ├── test_one_dim_constant.py ├── test_one_dim_gramacyandlee2012.py ├── test_one_dim_linear.py ├── test_one_dim_step.py ├── test_six_dim_hartmann6d.py ├── test_three_dim_hartmann3d.py ├── test_two_dim_beale.py ├── test_two_dim_bohachevsky.py ├── test_two_dim_branin.py ├── test_two_dim_bukin6.py ├── test_two_dim_dejong5.py ├── test_two_dim_dropwave.py ├── test_two_dim_easom.py ├── test_two_dim_eggholder.py ├── test_two_dim_goldsteinprice.py ├── test_two_dim_holdertable.py ├── test_two_dim_kim1.py ├── test_two_dim_kim2.py ├── test_two_dim_kim3.py ├── test_two_dim_michalewicz.py ├── test_two_dim_shubert.py ├── test_two_dim_sixhumpcamel.py ├── test_two_dim_threehumpcamel.py ├── test_utils.py └── test_version.py /.github/workflows/pytest.yml: -------------------------------------------------------------------------------- 1 | name: pytest 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | strategy: 8 | matrix: 9 | python-version: 10 | - '3.7' 11 | - '3.8' 12 | - '3.9' 13 | - '3.10' 14 | - '3.11' 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: actions/setup-python@v2 19 | with: 20 | python-version: ${{ matrix.python-version }} 21 | - name: Install this project and its dependencies 22 | run: | 23 | pip install --upgrade pip 24 | pip install .[dev] 25 | pip list 26 | - name: Run pytest 27 | run: | 28 | pytest 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # Jungtaek 132 | .DS_Store 133 | __MACOSX/ 134 | *.swp 135 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2024 Jungtaek Kim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | # BayesO Benchmarks: Benchmark Functions for Bayesian Optimization 6 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7577330.svg)](https://doi.org/10.5281/zenodo.7577330) 7 | [![Build Status](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml/badge.svg)](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml) 8 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 9 | 10 | This repository provides the implementation of benchmark functions for Bayesian optimization. 11 | The details of benchmark functions can be found in [these notes](https://jungtaek.github.io/notes/benchmarks_bo.pdf). 12 | 13 | * [https://bayeso.org](https://bayeso.org) 14 | 15 | ## Installation 16 | We recommend installing it with `virtualenv`. 17 | You can choose one of three installation options. 18 | 19 | * Using PyPI repository (for user installation) 20 | 21 | To install the released version in PyPI repository, command it. 22 | 23 | ```shell 24 | pip install bayeso-benchmarks 25 | ``` 26 | 27 | * Using source code (for developer installation) 28 | 29 | To install `bayeso-benchmarks` from source code, command the following in the `bayeso-benchmarks` root. 30 | 31 | ```shell 32 | pip install . 33 | ``` 34 | 35 | * Using source code (for editable development mode) 36 | 37 | To use editable development mode, command the following in the `bayeso-benchmarks` root. 38 | 39 | ```shell 40 | pip install -e . 41 | ``` 42 | 43 | If you want to install the packages required for development, you can simply add `[dev]`. 44 | For example, `pip install .[dev]` or `pip install -e .[dev]`. 45 | 46 | * Uninstallation 47 | 48 | If you would like to uninstall `bayeso-benchmarks`, command it. 49 | 50 | ```shell 51 | pip uninstall bayeso-benchmarks 52 | ``` 53 | 54 | ## Simple Example 55 | A simple example on Branin function is shown below. 56 | ```python 57 | from bayeso_benchmarks import Branin 58 | 59 | obj_fun = Branin() 60 | bounds = obj_fun.get_bounds() 61 | 62 | X = obj_fun.sample_uniform(100) 63 | 64 | Y = obj_fun.output(X) 65 | Y_noise = obj_fun.output_gaussian_noise(X) 66 | ``` 67 | 68 | ## Citation 69 | ``` 70 | @misc{KimJ2023software, 71 | author={Kim, Jungtaek}, 72 | title={{BayesO Benchmarks}: Benchmark Functions for {Bayesian} Optimization}, 73 | doi={10.5281/zenodo.7577330}, 74 | url={https://github.com/jungtaekkim/bayeso-benchmarks}, 75 | howpublished={\url{https://doi.org/10.5281/zenodo.7577330}}, 76 | year={2023} 77 | } 78 | ``` 79 | 80 | ## License 81 | [MIT License](LICENSE) 82 | -------------------------------------------------------------------------------- /bayeso_benchmarks/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: January 27, 2023 4 | # 5 | 6 | 7 | __version__ = '0.2.0' 8 | 9 | 10 | from bayeso_benchmarks.inf_dim_ackley import Ackley 11 | 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 15 | from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock 16 | from bayeso_benchmarks.inf_dim_sphere import Sphere 17 | from bayeso_benchmarks.inf_dim_zakharov import Zakharov 18 | 19 | from bayeso_benchmarks.one_dim_constant import Constant 20 | from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 21 | from bayeso_benchmarks.one_dim_linear import Linear 22 | from bayeso_benchmarks.one_dim_step import Step 23 | 24 | from bayeso_benchmarks.two_dim_beale import Beale 25 | from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky 26 | from bayeso_benchmarks.two_dim_branin import Branin 27 | from bayeso_benchmarks.two_dim_bukin6 import Bukin6 28 | from bayeso_benchmarks.two_dim_dejong5 import DeJong5 29 | from bayeso_benchmarks.two_dim_dropwave import DropWave 30 | from bayeso_benchmarks.two_dim_easom import Easom 31 | from bayeso_benchmarks.two_dim_eggholder import Eggholder 32 | from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice 33 | from bayeso_benchmarks.two_dim_holdertable import HolderTable 34 | from bayeso_benchmarks.two_dim_kim1 import Kim1 35 | from bayeso_benchmarks.two_dim_kim2 import Kim2 36 | from bayeso_benchmarks.two_dim_kim3 import Kim3 37 | from bayeso_benchmarks.two_dim_michalewicz import Michalewicz 38 | from bayeso_benchmarks.two_dim_shubert import Shubert 39 | from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel 40 | from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel 41 | 42 | from bayeso_benchmarks.four_dim_colville import Colville 43 | from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D 44 | 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) 82 | -------------------------------------------------------------------------------- /bayeso_benchmarks/benchmark_base.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: December 13, 2022 4 | # 5 | 6 | import numpy as np 7 | 8 | EPSILON = 1e-4 9 | 10 | 11 | class Function: 12 | def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, function, dim_problem=None, seed=None): 13 | assert isinstance(dimensionality, int) or dimensionality is np.inf 14 | assert isinstance(bounds, np.ndarray) 15 | assert isinstance(global_minimizers, np.ndarray) 16 | assert isinstance(global_minimum, float) 17 | assert callable(function) 18 | assert isinstance(dim_problem, (type(None), int)) 19 | assert isinstance(seed, (type(None), int)) 20 | assert len(bounds.shape) == 2 21 | assert bounds.shape[1] == 2 22 | assert (bounds[:, 0] <= bounds[:, 1]).all() 23 | 24 | self._dimensionality = dimensionality 25 | self._bounds = bounds 26 | self._global_minimizers = global_minimizers 27 | self._global_minimum = global_minimum 28 | self._function = function 29 | 30 | self.dim_problem = dim_problem 31 | self.random_state = np.random.RandomState(seed) 32 | 33 | self.validate_properties() 34 | self.set_name() 35 | 36 | @property 37 | def dimensionality(self): 38 | return self._dimensionality 39 | 40 | @property 41 | def bounds(self): 42 | return self._bounds 43 | 44 | @property 45 | def global_minimizers(self): 46 | return self._global_minimizers 47 | 48 | @property 49 | def global_minimum(self): 50 | return self._global_minimum 51 | 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 | 60 | def get_bounds(self): 61 | if self.dimensionality is np.inf: 62 | return np.array(list(self.bounds) * self.dim_problem) 63 | else: 64 | return self.bounds 65 | 66 | def get_global_minimizers(self): 67 | if self.dimensionality is np.inf: 68 | global_minimizers = self.global_minimizers 69 | for _ in range(1, self.dim_problem): 70 | global_minimizers = np.concatenate((global_minimizers, self.global_minimizers), axis=1) 71 | 72 | return global_minimizers 73 | else: 74 | return self.global_minimizers 75 | 76 | def function(self, bx): 77 | if self.dimensionality is np.inf: 78 | assert self.dim_problem is bx.shape[0] 79 | else: 80 | assert self.dimensionality is bx.shape[0] 81 | 82 | return self._function(bx) 83 | 84 | def _output(self, X): 85 | assert isinstance(X, np.ndarray) 86 | 87 | bounds = self.get_bounds() 88 | 89 | assert np.all(X >= bounds[:, 0]) 90 | assert np.all(X <= bounds[:, 1]) 91 | 92 | if len(X.shape) == 2: 93 | list_results = [self.function(bx) for bx in X] 94 | else: 95 | list_results = [self.function(X)] 96 | 97 | by = np.array(list_results) 98 | return by 99 | 100 | def output(self, X): 101 | by = self._output(X) 102 | Y = np.expand_dims(by, axis=1) 103 | 104 | assert len(Y.shape) == 2 105 | assert Y.shape[1] == 1 106 | return Y 107 | 108 | def output_constant_noise(self, X, scale_noise=0.01): 109 | assert isinstance(scale_noise, float) 110 | 111 | by = self._output(X) 112 | by += scale_noise 113 | 114 | Y = np.expand_dims(by, axis=1) 115 | 116 | assert len(Y.shape) == 2 117 | assert Y.shape[1] == 1 118 | return Y 119 | 120 | def output_gaussian_noise(self, X, scale_noise=0.01): 121 | assert isinstance(scale_noise, float) 122 | 123 | by = self._output(X) 124 | by += scale_noise * self.random_state.randn(by.shape[0]) 125 | 126 | Y = np.expand_dims(by, axis=1) 127 | 128 | assert len(Y.shape) == 2 129 | assert Y.shape[1] == 1 130 | return Y 131 | 132 | def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01): 133 | assert isinstance(scale_noise, float) 134 | assert isinstance(sparsity, float) 135 | assert sparsity >= 0.0 and sparsity <= 1.0 136 | assert sparsity < 0.5 137 | 138 | by = self._output(X) 139 | 140 | if len(X.shape) == 2: 141 | num_X = X.shape[0] 142 | else: 143 | num_X = 1 144 | 145 | noise = self.random_state.randn(num_X) 146 | mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity 147 | noise *= mask.astype(float) 148 | by += scale_noise * noise 149 | 150 | Y = np.expand_dims(by, axis=1) 151 | 152 | assert len(Y.shape) == 2 153 | assert Y.shape[1] == 1 154 | return Y 155 | 156 | def output_student_t_noise(self, X, scale_noise=0.01, dof=4.0): 157 | assert isinstance(scale_noise, float) 158 | assert isinstance(dof, float) 159 | 160 | by = self._output(X) 161 | by += scale_noise * self.random_state.standard_t(dof, size=by.shape[0]) 162 | 163 | Y = np.expand_dims(by, axis=1) 164 | 165 | assert len(Y.shape) == 2 166 | assert Y.shape[1] == 1 167 | return Y 168 | 169 | def output_sparse_student_t_noise(self, X, scale_noise=0.1, dof=4.0, sparsity=0.01): 170 | assert isinstance(scale_noise, float) 171 | assert isinstance(dof, float) 172 | assert isinstance(sparsity, float) 173 | assert sparsity >= 0.0 and sparsity <= 1.0 174 | assert sparsity < 0.5 175 | 176 | by = self._output(X) 177 | 178 | if len(X.shape) == 2: 179 | num_X = X.shape[0] 180 | else: 181 | num_X = 1 182 | 183 | noise = self.random_state.standard_t(dof, size=num_X) 184 | mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity 185 | noise *= mask.astype(float) 186 | by += scale_noise * noise 187 | 188 | Y = np.expand_dims(by, axis=1) 189 | 190 | assert len(Y.shape) == 2 191 | assert Y.shape[1] == 1 192 | return Y 193 | 194 | def validate_properties(self): 195 | shape_bounds = self.get_bounds().shape 196 | 197 | global_minimizers = self.get_global_minimizers() 198 | shape_global_minimizers = global_minimizers.shape 199 | 200 | assert len(shape_bounds) == 2 201 | assert shape_bounds[1] == 2 202 | assert len(shape_global_minimizers) == 2 203 | assert np.all(np.abs(self.output(global_minimizers) - self.global_minimum) < EPSILON) 204 | 205 | if self.dimensionality is np.inf: 206 | assert shape_bounds[0] == shape_global_minimizers[1] 207 | else: 208 | assert self.dimensionality == shape_bounds[0] == shape_global_minimizers[1] 209 | 210 | def sample_grids(self, num_grids): 211 | assert isinstance(num_grids, int) 212 | 213 | list_grids = [] 214 | for bound in self.get_bounds(): 215 | list_grids.append(np.linspace(bound[0], bound[1], num_grids)) 216 | list_grids_mesh = list(np.meshgrid(*list_grids)) 217 | list_grids = [] 218 | for elem in list_grids_mesh: 219 | list_grids.append(elem.flatten(order='C')) 220 | grids = np.vstack(tuple(list_grids)) 221 | grids = grids.T 222 | return grids 223 | 224 | def sample_uniform(self, num_points, seed=None): 225 | assert isinstance(num_points, int) 226 | assert isinstance(seed, (type(None), int)) 227 | 228 | random_state_ = np.random.RandomState(seed) 229 | 230 | if self.dimensionality is np.inf: 231 | dim_problem = self.dim_problem 232 | else: 233 | dim_problem = self.dimensionality 234 | 235 | bounds = self.get_bounds() 236 | 237 | points = random_state_.uniform(size=(num_points, dim_problem)) 238 | points = bounds[:, 0] + (bounds[:, 1] - bounds[:, 0]) * points 239 | 240 | return points 241 | 242 | def __call__(self, X): 243 | return self.output(X) 244 | -------------------------------------------------------------------------------- /bayeso_benchmarks/four_dim_colville.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 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 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 46 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_ackley.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 | a=20.0, 13 | b=0.2, 14 | c=2.0*np.pi 15 | ): 16 | assert len(bx.shape) == 1 17 | assert bx.shape[0] == dim_bx 18 | assert isinstance(a, float) 19 | assert isinstance(b, float) 20 | assert isinstance(c, float) 21 | 22 | y = -a * np.exp(-b * np.linalg.norm(bx, ord=2, axis=0) * np.sqrt(1.0 / dim_bx)) - np.exp(1.0 / dim_bx * np.sum(np.cos(c * bx), axis=0)) + a + np.exp(1.0) 23 | return y 24 | 25 | 26 | class Ackley(Function): 27 | def __init__(self, dim_problem, seed=None): 28 | assert isinstance(dim_problem, int) 29 | assert isinstance(seed, (type(None), int)) 30 | 31 | dim_bx = np.inf 32 | bounds = np.array([ 33 | [-32.768, 32.768], 34 | ]) 35 | global_minimizers = np.array([ 36 | [0.0], 37 | ]) 38 | global_minimum = 0.0 39 | dim_problem = dim_problem 40 | 41 | function = lambda bx: fun_target(bx, dim_problem) 42 | 43 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 44 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_cosines.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 = np.sum(np.cos(bx) * (np.abs(bx) * (0.1 / (2.0 * np.pi)) - 1.0)) 16 | return y 17 | 18 | 19 | class Cosines(Function): 20 | def __init__(self, dim_problem, seed=None): 21 | assert isinstance(dim_problem, int) 22 | assert isinstance(seed, (type(None), int)) 23 | 24 | dim_bx = np.inf 25 | bounds = np.array([ 26 | [-2.0 * np.pi, 2.0 * np.pi], 27 | ]) 28 | global_minimizers = np.array([ 29 | [0.0], 30 | ]) 31 | global_minimum = -1.0 * dim_problem 32 | dim_problem = dim_problem 33 | 34 | function = lambda bx: fun_target(bx, dim_problem) 35 | 36 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 37 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_griewank.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 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 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 43 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_levy.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 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 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 49 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_rastrigin.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 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 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 41 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_rosenbrock.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 = 0.0 16 | 17 | for ind in range(0, dim_bx - 1): 18 | y += 100 * (bx[ind+1] - bx[ind]**2)**2 + (bx[ind] - 1.0)**2 19 | return y 20 | 21 | 22 | class Rosenbrock(Function): 23 | def __init__(self, dim_problem, seed=None): 24 | assert isinstance(dim_problem, int) 25 | assert isinstance(seed, (type(None), int)) 26 | assert dim_problem > 1 27 | 28 | dim_bx = np.inf 29 | bounds = np.array([ 30 | [-2.048, 2.048], 31 | ]) 32 | global_minimizers = np.array([ 33 | [1.0], 34 | ]) 35 | global_minimum = 0.0 36 | dim_problem = dim_problem 37 | 38 | function = lambda bx: fun_target(bx, dim_problem) 39 | 40 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 41 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_sphere.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 = 0.0 16 | 17 | for ind in range(0, dim_bx): 18 | y += bx[ind]**2 19 | return y 20 | 21 | 22 | class Sphere(Function): 23 | def __init__(self, dim_problem, seed=None): 24 | assert isinstance(dim_problem, int) 25 | assert isinstance(seed, (type(None), int)) 26 | 27 | dim_bx = np.inf 28 | bounds = np.array([ 29 | [-5.12, 5.12], 30 | ]) 31 | global_minimizers = np.array([ 32 | [0.0], 33 | ]) 34 | global_minimum = 0.0 35 | dim_problem = dim_problem 36 | 37 | function = lambda bx: fun_target(bx, dim_problem) 38 | 39 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 40 | -------------------------------------------------------------------------------- /bayeso_benchmarks/inf_dim_zakharov.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 4, 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) 16 | 17 | inner_term = 0.0 18 | for ind in range(1, dim_bx + 1): 19 | inner_term += 0.5 * ind * bx[ind - 1] 20 | 21 | second_term = inner_term**2 22 | third_term = inner_term**4 23 | 24 | y = first_term + second_term + third_term 25 | return y 26 | 27 | 28 | class Zakharov(Function): 29 | def __init__(self, dim_problem, seed=None): 30 | assert isinstance(dim_problem, int) 31 | assert isinstance(seed, (type(None), int)) 32 | 33 | dim_bx = np.inf 34 | bounds = np.array([ 35 | [-5.0, 10.0], 36 | ]) 37 | global_minimizers = np.array([ 38 | [0.0], 39 | ]) 40 | global_minimum = 0.0 41 | dim_problem = dim_problem 42 | 43 | function = lambda bx: fun_target(bx, dim_problem) 44 | 45 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) 46 | -------------------------------------------------------------------------------- /bayeso_benchmarks/one_dim_constant.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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, constant): 12 | assert len(bx.shape) == 1 13 | assert bx.shape[0] == dim_bx 14 | assert isinstance(constant, float) 15 | 16 | y = constant 17 | return y 18 | 19 | 20 | class Constant(Function): 21 | def __init__(self, 22 | bounds=np.array([ 23 | [-10.0, 10.0], 24 | ]), 25 | constant=0.0, 26 | seed=None 27 | ): 28 | assert isinstance(constant, float) 29 | assert isinstance(bounds, np.ndarray) 30 | assert isinstance(seed, (type(None), int)) 31 | assert len(bounds.shape) == 2 32 | assert bounds.shape[0] == 1 33 | assert bounds.shape[1] == 2 34 | assert bounds[0, 0] < bounds[0, 1] 35 | 36 | dim_bx = bounds.shape[0] 37 | min_bx = bounds[0, 0] 38 | max_bx = bounds[0, 1] 39 | global_minimizers = np.array([ 40 | [min_bx], 41 | [max_bx], 42 | ]) 43 | global_minimum = constant 44 | function = lambda bx: fun_target(bx, dim_bx, constant) 45 | 46 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 47 | -------------------------------------------------------------------------------- /bayeso_benchmarks/one_dim_gramacyandlee2012.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = np.sin(10.0 * np.pi * bx[0]) / (2 * bx[0]) + (bx[0] - 1.0)**4 16 | return y 17 | 18 | 19 | class GramacyAndLee2012(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 1 24 | bounds = np.array([ 25 | [0.5, 2.5], 26 | ]) 27 | assert bounds.shape[0] == dim_bx 28 | assert bounds.shape[1] == 2 29 | 30 | global_minimizers = np.array([ 31 | [0.54856344], 32 | ]) 33 | global_minimum = -0.8690111350 34 | function = lambda bx: fun_target(bx, dim_bx) 35 | 36 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 37 | -------------------------------------------------------------------------------- /bayeso_benchmarks/one_dim_linear.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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, slope): 12 | assert len(bx.shape) == 1 13 | assert bx.shape[0] == dim_bx 14 | assert isinstance(slope, float) 15 | 16 | y = slope * bx[0] 17 | return y 18 | 19 | 20 | class Linear(Function): 21 | def __init__(self, 22 | bounds=np.array([ 23 | [-10, 10], 24 | ]), 25 | slope=1.0, 26 | seed=None 27 | ): 28 | assert isinstance(slope, float) 29 | assert isinstance(bounds, np.ndarray) 30 | assert isinstance(seed, (type(None), int)) 31 | assert len(bounds.shape) == 2 32 | assert bounds.shape[0] == 1 33 | assert bounds.shape[1] == 2 34 | assert bounds[0, 0] < bounds[0, 1] 35 | 36 | dim_bx = bounds.shape[0] 37 | 38 | if slope > 0.0: 39 | global_minimizers = np.array([ 40 | [bounds[0, 0]], 41 | ]) 42 | global_minimum = slope * bounds[0, 0] 43 | else: 44 | global_minimizers = np.array([ 45 | [bounds[0, 1]], 46 | ]) 47 | global_minimum = slope * bounds[0, 1] 48 | function = lambda bx: fun_target(bx, dim_bx, slope) 49 | 50 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 51 | -------------------------------------------------------------------------------- /bayeso_benchmarks/one_dim_step.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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, steps, step_values): 12 | assert len(bx.shape) == 1 13 | assert bx.shape[0] == dim_bx 14 | assert isinstance(steps, list) 15 | assert isinstance(step_values, list) 16 | assert len(steps) == len(step_values) + 1 17 | assert isinstance(steps[0], float) 18 | assert isinstance(step_values[0], float) 19 | 20 | y = None 21 | for ind_step in range(0, len(steps) - 1): 22 | if ind_step < (len(steps) - 2) and steps[ind_step] <= bx[0] and bx[0] < steps[ind_step+1]: 23 | y = step_values[ind_step] 24 | break 25 | elif ind_step == (len(steps) - 2) and steps[ind_step] <= bx[0] and bx[0] <= steps[ind_step+1]: 26 | y = step_values[ind_step] 27 | break 28 | 29 | if y is None: 30 | raise ValueError('Conditions for steps') 31 | return y 32 | 33 | 34 | class Step(Function): 35 | def __init__(self, 36 | steps=[-10., -5., 0., 5., 10.], 37 | step_values=[-2., 0., 1., -1.], 38 | seed=None 39 | ): 40 | assert isinstance(steps, list) 41 | assert isinstance(step_values, list) 42 | assert isinstance(seed, (type(None), int)) 43 | assert len(steps) == len(step_values) + 1 44 | assert isinstance(steps[0], float) 45 | assert isinstance(step_values[0], float) 46 | assert np.all(np.sort(steps) == np.asarray(steps)) 47 | 48 | dim_bx = 1 49 | bounds = np.array([ 50 | [np.min(steps), np.max(steps)], 51 | ]) 52 | assert bounds.shape[0] == dim_bx 53 | assert bounds.shape[1] == 2 54 | 55 | global_minimizers = np.array([ 56 | [steps[np.argmin(step_values)]], 57 | ]) 58 | global_minimum = np.min(step_values) 59 | function = lambda bx: fun_target(bx, dim_bx, steps, step_values) 60 | 61 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 62 | -------------------------------------------------------------------------------- /bayeso_benchmarks/six_dim_hartmann6d.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | alpha = np.array([1.0, 1.2, 3.0, 3.2]) 16 | A = np.array([ 17 | [10.0, 3.0, 17.0, 3.5, 1.7, 8.0], 18 | [0.05, 10.0, 17.0, 0.1, 8.0, 14.0], 19 | [3.0, 3.5, 1.7, 10.0, 17.0, 8.0], 20 | [17.0, 8.0, 0.05, 10.0, 0.1, 14.0] 21 | ]) 22 | P = 1e-4 * np.array([ 23 | [1312, 1696, 5569, 124, 8283, 5886], 24 | [2329, 4135, 8307, 3736, 1004, 9991], 25 | [2348, 1451, 3522, 2883, 3047, 6650], 26 | [4047, 8828, 8732, 5743, 1091, 381] 27 | ]) 28 | 29 | outer = 0.0 30 | for i_ in range(0, 4): 31 | inner = 0.0 32 | for j_ in range(0, 6): 33 | inner += A[i_, j_] * (bx[j_] - P[i_, j_])**2 34 | outer += alpha[i_] * np.exp(-1.0 * inner) 35 | 36 | y = -1.0 * outer 37 | return y 38 | 39 | 40 | class Hartmann6D(Function): 41 | def __init__(self, seed=None): 42 | assert isinstance(seed, (type(None), int)) 43 | 44 | dim_bx = 6 45 | bounds = np.array([ 46 | [0.0, 1.0], 47 | [0.0, 1.0], 48 | [0.0, 1.0], 49 | [0.0, 1.0], 50 | [0.0, 1.0], 51 | [0.0, 1.0], 52 | ]) 53 | assert bounds.shape[0] == dim_bx 54 | assert bounds.shape[1] == 2 55 | 56 | global_minimizers = np.array([ 57 | [0.20168949, 0.15001068, 0.47687397, 0.27533242, 0.3116516, 0.65730054], 58 | ]) 59 | global_minimum = -3.3223680115 60 | function = lambda bx: fun_target(bx, dim_bx) 61 | 62 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 63 | -------------------------------------------------------------------------------- /bayeso_benchmarks/three_dim_hartmann3d.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | alpha = np.array([1.0, 1.2, 3.0, 3.2]) 16 | A = np.array([ 17 | [3.0, 10.0, 30.0], 18 | [0.1, 10.0, 35.0], 19 | [3.0, 10.0, 30.0], 20 | [0.1, 10.0, 35.0], 21 | ]) 22 | P = 1e-4 * np.array([ 23 | [3689, 1170, 2673], 24 | [4699, 4387, 7470], 25 | [1091, 8732, 5547], 26 | [381, 5743, 8828], 27 | ]) 28 | 29 | outer = 0.0 30 | for i_ in range(0, 4): 31 | inner = 0.0 32 | for j_ in range(0, 3): 33 | inner += A[i_, j_] * (bx[j_] - P[i_, j_])**2 34 | outer += alpha[i_] * np.exp(-1.0 * inner) 35 | 36 | y = -1.0 * outer 37 | return y 38 | 39 | 40 | class Hartmann3D(Function): 41 | def __init__(self, seed=None): 42 | assert isinstance(seed, (type(None), int)) 43 | 44 | dim_bx = 3 45 | bounds = np.array([ 46 | [0.0, 1.0], 47 | [0.0, 1.0], 48 | [0.0, 1.0], 49 | ]) 50 | assert bounds.shape[0] == dim_bx 51 | assert bounds.shape[1] == 2 52 | 53 | global_minimizers = np.array([ 54 | [0.11458889, 0.55564889, 0.85254698], 55 | ]) 56 | global_minimum = -3.8627797874 57 | function = lambda bx: fun_target(bx, dim_bx) 58 | 59 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 60 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_beale.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 = (1.5 - bx[0] + bx[0] * bx[1])**2 + (2.25 - bx[0] + bx[0] * bx[1]**2)**2 + (2.625 - bx[0] + bx[0] * bx[1]**3)**2 16 | return y 17 | 18 | 19 | class Beale(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-4.5, 4.5], 26 | [-4.5, 4.5], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [3.0, 0.5], 33 | ]) 34 | global_minimum = 0.0 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_bohachevsky.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 = bx[0]**2 + 2.0 * bx[1]**2 - 0.3 * np.cos(3.0 * np.pi * bx[0]) - 0.4 * np.cos(4.0 * np.pi * bx[1]) + 0.7 16 | return y 17 | 18 | 19 | class Bohachevsky(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-100.0, 100.0], 26 | [-100.0, 100.0], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [0.0, 0.0], 33 | ]) 34 | global_minimum = 0.0 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_branin.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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, a, b, c, r, s, t): 12 | assert len(bx.shape) == 1 13 | assert bx.shape[0] == dim_bx 14 | assert isinstance(a, float) 15 | assert isinstance(b, float) 16 | assert isinstance(c, float) 17 | assert isinstance(r, float) 18 | assert isinstance(s, float) 19 | assert isinstance(t, float) 20 | 21 | y = a * (bx[1] - b * bx[0]**2 + c * bx[0] - r)**2 + s * (1 - t) * np.cos(bx[0]) + s 22 | return y 23 | 24 | 25 | class Branin(Function): 26 | def __init__(self, 27 | a=1.0, 28 | b=5.1 / (4.0 * np.pi**2), 29 | c=5 / np.pi, 30 | r=6.0, 31 | s=10.0, 32 | t=1 / (8 * np.pi), 33 | seed=None 34 | ): 35 | assert isinstance(a, float) 36 | assert isinstance(b, float) 37 | assert isinstance(c, float) 38 | assert isinstance(r, float) 39 | assert isinstance(s, float) 40 | assert isinstance(t, float) 41 | assert isinstance(seed, (type(None), int)) 42 | 43 | dim_bx = 2 44 | bounds = np.array([ 45 | [-5, 10], 46 | [0, 15], 47 | ]) 48 | assert bounds.shape[0] == dim_bx 49 | assert bounds.shape[1] == 2 50 | 51 | global_minimizers = np.array([ 52 | [-np.pi, 12.275], 53 | [np.pi, 2.275], 54 | [9.42478, 2.475], 55 | ]) 56 | global_minimum = 0.3978873577 57 | function = lambda bx: fun_target(bx, dim_bx, a, b, c, r, s, t) 58 | 59 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 60 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_bukin6.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 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 | y = 100.0 * np.sqrt(np.abs(bx[1] - 0.01 * bx[0]**2)) + 0.01 * np.abs(bx[0] + 10.0) 16 | return y 17 | 18 | 19 | class Bukin6(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-15, -5], 26 | [-3, 3], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [-10.0, 1.0], 33 | ]) 34 | global_minimum = 0.0 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_dejong5.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | A = np.array([ 16 | [-32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0], 17 | [-32.0, -32.0, -32.0, -32.0, -32.0, -16.0, -16.0, -16.0, -16.0, -16.0, 0.0, 0.0, 0.0, 0.0, 0.0, 16.0, 16.0, 16.0, 16.0, 16.0, 32.0, 32.0, 32.0, 32.0, 32.0], 18 | ]) 19 | y = 0.002 20 | 21 | for ind in range(0, 25): 22 | cur_y = 1.0 / (ind + 1.0 + (bx[0] - A[0, ind])**6 + (bx[1] - A[1, ind])**6) 23 | y += cur_y 24 | y = y**(-1) 25 | 26 | return y 27 | 28 | 29 | class DeJong5(Function): 30 | def __init__(self, seed=None): 31 | assert isinstance(seed, (type(None), int)) 32 | 33 | dim_bx = 2 34 | bounds = np.array([ 35 | [-65.536, 65.536], 36 | [-65.536, 65.536], 37 | ]) 38 | assert bounds.shape[0] == dim_bx 39 | assert bounds.shape[1] == 2 40 | 41 | global_minimizers = np.array([ 42 | [-31.97707837, -31.97795471], 43 | [-31.99140499, -31.99140499], 44 | [-32.01411043, -32.01411352], 45 | [-32.01747329, -32.01236504], 46 | [-32.0293114, -32.01718511], 47 | [-31.9618885, -32.00659555], 48 | [-32.0400369, -31.9824982], 49 | [-31.98255954, -32.04163256], 50 | ]) 51 | global_minimum = 0.9980038378 52 | function = lambda bx: fun_target(bx, dim_bx) 53 | 54 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 55 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_dropwave.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 9, 2021 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 = -1.0 * (1 + np.cos(12.0 * np.sqrt(bx[0]**2 + bx[1]**2))) / (0.5 * (bx[0]**2 + bx[1]**2) + 2.0) 16 | return y 17 | 18 | 19 | class DropWave(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-5.12, 5.12], 26 | [-5.12, 5.12], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [0.0, 0.0], 33 | ]) 34 | global_minimum = -1.0 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_easom.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 3, 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 | y = -1.0 * np.cos(bx[0]) * np.cos(bx[1]) * np.exp(-1.0 * (bx[0] - np.pi)**2 - (bx[1] - np.pi)**2) 16 | return y 17 | 18 | 19 | class Easom(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-100, 100], 26 | [-100, 100], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [np.pi, np.pi], 33 | ]) 34 | global_minimum = -1.0 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_eggholder.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = -1.0 * (bx[1] + 47.0) * np.sin(np.sqrt(np.abs(bx[1] + bx[0] / 2.0 + 47.0))) - bx[0] * np.sin(np.sqrt(np.abs(bx[0] - (bx[1] + 47.0)))) 16 | return y 17 | 18 | 19 | class Eggholder(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-512.0, 512.0], 26 | [-512.0, 512.0], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [512.0, 404.2318066], 33 | ]) 34 | global_minimum = -959.6406627209 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_goldsteinprice.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | term_1a = (bx[0] + bx[1] + 1.0)**2 16 | term_1b = 19.0 - 14.0 * bx[0] + 3.0 * bx[0]**2 - 14.0 * bx[1] + 6.0 * bx[0] * bx[1] + 3.0 * bx[1]**2 17 | term_1 = 1.0 + term_1a * term_1b 18 | 19 | term_2a = (2.0 * bx[0] - 3.0 * bx[1])**2 20 | term_2b = 18.0 - 32.0 * bx[0] + 12.0 * bx[0]**2 + 48.0 * bx[1] - 36.0 * bx[0] * bx[1] + 27.0 * bx[1]**2 21 | term_2 = 30.0 + term_2a * term_2b 22 | 23 | y = term_1 * term_2 24 | return y 25 | 26 | 27 | class GoldsteinPrice(Function): 28 | def __init__(self, seed=None): 29 | assert isinstance(seed, (type(None), int)) 30 | 31 | dim_bx = 2 32 | bounds = np.array([ 33 | [-2.0, 2.0], 34 | [-2.0, 2.0], 35 | ]) 36 | assert bounds.shape[0] == dim_bx 37 | assert bounds.shape[1] == 2 38 | 39 | global_minimizers = np.array([ 40 | [0.0, -1.0], 41 | ]) 42 | global_minimum = 2.9999999999 43 | function = lambda bx: fun_target(bx, dim_bx) 44 | 45 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 46 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_holdertable.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = -1.0 * np.abs(np.sin(bx[0]) * np.cos(bx[1]) * np.exp(np.abs(1.0 - np.sqrt(bx[0]**2 + bx[1]**2) / np.pi))) 16 | return y 17 | 18 | 19 | class HolderTable(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-10.0, 10.0], 26 | [-10.0, 10.0], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [8.05502347, 9.66459002], 33 | [8.05502347, -9.66459002], 34 | [-8.05502347, 9.66459002], 35 | [-8.05502347, -9.66459002], 36 | ]) 37 | global_minimum = -19.2085025679 38 | function = lambda bx: fun_target(bx, dim_bx) 39 | 40 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 41 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_kim1.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = np.sin(bx[0]) + np.cos(bx[1]) + 0.016 * (bx[0] - 5.0)**2 + 0.008 * (bx[1] - 5.0)**2 16 | return y 17 | 18 | 19 | class Kim1(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-16.0, 16.0], 26 | [-16.0, 16.0], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [4.72130726, 3.17086303], 33 | ]) 34 | global_minimum = -1.9715232348 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_kim2.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = np.sin(bx[0] / 1.0) + np.cos(bx[1] / 1.0) \ 16 | + np.sin(bx[0] / 2.0) + np.cos(bx[1] / 2.0) \ 17 | + np.sin(bx[0] / 4.0) + np.cos(bx[1] / 4.0) \ 18 | + np.sin(bx[0] / 8.0) + np.cos(bx[1] / 8.0) \ 19 | + np.sin(bx[0] / 16.0) + np.cos(bx[1] / 16.0) \ 20 | + 0.0032 * (bx[0] - 20.0)**2 + 0.0016 * (bx[1] - 20.0)**2 21 | return y 22 | 23 | 24 | class Kim2(Function): 25 | def __init__(self, seed=None): 26 | assert isinstance(seed, (type(None), int)) 27 | 28 | dim_bx = 2 29 | bounds = np.array([ 30 | [-128.0, 128.0], 31 | [-128.0, 128.0], 32 | ]) 33 | assert bounds.shape[0] == dim_bx 34 | assert bounds.shape[1] == 2 35 | 36 | global_minimizers = np.array([ 37 | [-2.1013466, 34.14526252], 38 | ]) 39 | global_minimum = -3.4543874735 40 | function = lambda bx: fun_target(bx, dim_bx) 41 | 42 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 43 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_kim3.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 2023 4 | # 5 | 6 | import numpy as np 7 | 8 | from bayeso_benchmarks import utils 9 | from bayeso_benchmarks.benchmark_base import Function 10 | 11 | 12 | def fun_target(bx, dim_bx): 13 | assert len(bx.shape) == 1 14 | assert bx.shape[0] == dim_bx 15 | 16 | y = np.sin(bx[0] / 1.0) + np.cos(bx[1] / 1.0) \ 17 | + np.sin(bx[0] / 2.0) + np.cos(bx[1] / 2.0) \ 18 | + np.sin(bx[0] / 4.0) + np.cos(bx[1] / 4.0) \ 19 | + np.sin(bx[0] / 8.0) + np.cos(bx[1] / 8.0) \ 20 | + np.sin(bx[0] / 16.0) + np.cos(bx[1] / 16.0) \ 21 | + 0.0016 * (bx[0] - 40.0)**2 + 0.0008 * (bx[1] - 40.0)**2 \ 22 | - 256000.0 * utils.pdf_two_dim_normal( 23 | bx, np.array([-120.0, -120.0]), 24 | np.array([[1000.0, 0.0], [0.0, 1000.0]]) 25 | ) \ 26 | - 256000.0 * utils.pdf_two_dim_normal( 27 | bx, np.array([-120.0, +120.0]), 28 | np.array([[1000.0, 0.0], [0.0, 1000.0]]) 29 | ) 30 | 31 | return y 32 | 33 | 34 | class Kim3(Function): 35 | def __init__(self, seed=None): 36 | assert isinstance(seed, (type(None), int)) 37 | 38 | dim_bx = 2 39 | bounds = np.array([ 40 | [-256.0, 256.0], 41 | [-256.0, 256.0], 42 | ]) 43 | assert bounds.shape[0] == dim_bx 44 | assert bounds.shape[1] == 2 45 | 46 | global_minimizers = np.array([ 47 | [48.12477173, 34.19859065], 48 | ]) 49 | global_minimum = -4.9439679194 50 | function = lambda bx: fun_target(bx, dim_bx) 51 | 52 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 53 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_michalewicz.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = 0.0 16 | 17 | for ind in range(0, dim_bx): 18 | y += np.sin(bx[ind]) * np.sin(((ind + 1.0) * bx[ind]**2) / np.pi)**(2.0 * 10.0) 19 | y *= -1.0 20 | 21 | return y 22 | 23 | 24 | class Michalewicz(Function): 25 | def __init__(self, seed=None): 26 | assert isinstance(seed, (type(None), int)) 27 | 28 | dim_bx = 2 29 | bounds = np.array([ 30 | [0.0, np.pi], 31 | [0.0, np.pi], 32 | ]) 33 | assert bounds.shape[0] == dim_bx 34 | assert bounds.shape[1] == 2 35 | 36 | global_minimizers = np.array([ 37 | [2.20290552, 1.57079632], 38 | ]) 39 | global_minimum = -1.8013034101 40 | function = lambda bx: fun_target(bx, dim_bx) 41 | 42 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 43 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_shubert.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 = 0.0 16 | for ind in range(1, 6): 17 | first_term += ind * np.cos((ind + 1.0) * bx[0] + ind) 18 | 19 | second_term = 0.0 20 | for ind in range(1, 6): 21 | second_term += ind * np.cos((ind + 1.0) * bx[1] + ind) 22 | 23 | y = first_term * second_term 24 | return y 25 | 26 | 27 | class Shubert(Function): 28 | def __init__(self, seed=None): 29 | assert isinstance(seed, (type(None), int)) 30 | 31 | dim_bx = 2 32 | bounds = np.array([ 33 | [-10, 10], 34 | [-10, 10], 35 | ]) 36 | assert bounds.shape[0] == dim_bx 37 | assert bounds.shape[1] == 2 38 | 39 | global_minimizers = np.array([ 40 | [-7.08350641, -7.70831374], 41 | [5.48286421, -7.70831373], 42 | [-0.8003211, -7.70831374], 43 | [4.85805688, -7.08350641], 44 | [-7.70831374, -0.8003211], 45 | [-7.70831374, 5.4828642], 46 | [4.85805688, 5.48286421], 47 | ]) 48 | global_minimum = -186.7309088311 49 | 50 | function = lambda bx: fun_target(bx, dim_bx) 51 | 52 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 53 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_sixhumpcamel.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 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 | y = (4.0 - 2.1 * bx[0]**2 + bx[0]**4 / 3.0) * bx[0]**2 + bx[0] * bx[1] + (-4.0 + 4.0 * bx[1]**2) * bx[1]**2 16 | return y 17 | 18 | 19 | class SixHumpCamel(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-3.0, 3.0], 26 | [-2.0, 2.0], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [0.08984201, -0.7126564], 33 | [-0.08984201, 0.7126564], 34 | ]) 35 | global_minimum = -1.0316284535 36 | function = lambda bx: fun_target(bx, dim_bx) 37 | 38 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 39 | -------------------------------------------------------------------------------- /bayeso_benchmarks/two_dim_threehumpcamel.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: February 8, 2021 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 = 2 * bx[0]**2 - 1.05 * bx[0]**4 + 1.0 / 6.0 * bx[0]**6 + bx[0] * bx[1] + bx[1]**2 16 | return y 17 | 18 | 19 | class ThreeHumpCamel(Function): 20 | def __init__(self, seed=None): 21 | assert isinstance(seed, (type(None), int)) 22 | 23 | dim_bx = 2 24 | bounds = np.array([ 25 | [-5.0, 5.0], 26 | [-5.0, 5.0], 27 | ]) 28 | assert bounds.shape[0] == dim_bx 29 | assert bounds.shape[1] == 2 30 | 31 | global_minimizers = np.array([ 32 | [0.0, 0.0], 33 | ]) 34 | global_minimum = 0.0 35 | function = lambda bx: fun_target(bx, dim_bx) 36 | 37 | super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) 38 | -------------------------------------------------------------------------------- /bayeso_benchmarks/utils.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: January 4, 2023 4 | # 5 | 6 | import numpy as np 7 | 8 | import bayeso_benchmarks as bb 9 | 10 | 11 | def get_benchmark(str_fun, seed=None, **kwargs): 12 | count = 0 13 | 14 | for class_benchmark in bb.all_benchmarks: 15 | if str_fun == class_benchmark.__name__.lower(): 16 | target_class = class_benchmark 17 | count += 1 18 | 19 | if count == 0: 20 | raise ValueError('missing str_fun.') 21 | elif count > 1: 22 | raise ValueError('duplicate class name.') 23 | 24 | if str_fun in [ 25 | 'ackley', 26 | 'cosines', 27 | 'griewank', 28 | 'levy', 29 | 'rastrigin', 30 | 'rosenbrock', 31 | 'sphere', 32 | 'zakharov', 33 | ]: 34 | assert 'dim' in kwargs 35 | dim = kwargs['dim'] 36 | 37 | benchmark = target_class(dim, seed=seed) 38 | elif str_fun == 'constant': 39 | assert 'bounds' in kwargs 40 | assert 'constant' in kwargs 41 | bounds = kwargs['bounds'] 42 | constant = kwargs['constant'] 43 | 44 | benchmark = target_class(bounds=bounds, constant=constant, seed=seed) 45 | elif str_fun == 'linear': 46 | assert 'bounds' in kwargs 47 | assert 'slope' in kwargs 48 | bounds = kwargs['bounds'] 49 | slope = kwargs['slope'] 50 | 51 | benchmark = target_class(bounds=bounds, slope=slope, seed=seed) 52 | elif str_fun == 'step': 53 | assert 'steps' in kwargs 54 | assert 'step_values' in kwargs 55 | steps = kwargs['steps'] 56 | step_values = kwargs['step_values'] 57 | 58 | benchmark = target_class(steps=steps, step_values=step_values, seed=seed) 59 | else: 60 | benchmark = target_class(seed=seed) 61 | 62 | return benchmark 63 | 64 | def pdf_two_dim_normal(bx, mu, Cov): 65 | assert bx.shape[0] == mu.shape[0] == Cov.shape[0] == Cov.shape[1] == 2 66 | 67 | dim = bx.shape[0] 68 | 69 | term_first = ((2.0 * np.pi)**(-0.5 * dim)) * (np.linalg.det(Cov)**(-0.5)) 70 | term_second = np.exp(-0.5 * np.dot(np.dot((bx - mu), np.linalg.inv(Cov)), bx - mu)) 71 | 72 | return term_first * term_second 73 | -------------------------------------------------------------------------------- /examples/find_global_minimum.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 2023 4 | # 5 | 6 | import numpy as np 7 | import scipy.optimize as scio 8 | 9 | from bayeso_benchmarks import Ackley 10 | from bayeso_benchmarks import Cosines 11 | from bayeso_benchmarks import Griewank 12 | from bayeso_benchmarks import Levy 13 | from bayeso_benchmarks import Rastrigin 14 | from bayeso_benchmarks import Rosenbrock 15 | from bayeso_benchmarks import Sphere 16 | from bayeso_benchmarks import Zakharov 17 | from bayeso_benchmarks import GramacyAndLee2012 18 | from bayeso_benchmarks import Beale 19 | from bayeso_benchmarks import Bohachevsky 20 | from bayeso_benchmarks import Branin 21 | from bayeso_benchmarks import Bukin6 22 | from bayeso_benchmarks import DeJong5 23 | from bayeso_benchmarks import DropWave 24 | from bayeso_benchmarks import Easom 25 | from bayeso_benchmarks import Eggholder 26 | from bayeso_benchmarks import GoldsteinPrice 27 | from bayeso_benchmarks import HolderTable 28 | from bayeso_benchmarks import Kim1 29 | from bayeso_benchmarks import Kim2 30 | from bayeso_benchmarks import Kim3 31 | from bayeso_benchmarks import Michalewicz 32 | from bayeso_benchmarks import Shubert 33 | from bayeso_benchmarks import SixHumpCamel 34 | from bayeso_benchmarks import ThreeHumpCamel 35 | from bayeso_benchmarks import Colville 36 | from bayeso_benchmarks import Hartmann3D 37 | from bayeso_benchmarks import Hartmann6D 38 | 39 | 40 | TEST_EPSILON = 1e-7 41 | 42 | all_benchmarks = [ 43 | Ackley, 44 | Cosines, 45 | Griewank, 46 | Levy, 47 | Rastrigin, 48 | Rosenbrock, 49 | Sphere, 50 | Zakharov, 51 | GramacyAndLee2012, 52 | Beale, 53 | Bohachevsky, 54 | Branin, 55 | Bukin6, 56 | DeJong5, 57 | DropWave, 58 | Easom, 59 | Eggholder, 60 | GoldsteinPrice, 61 | HolderTable, 62 | Kim1, 63 | Kim2, 64 | Kim3, 65 | Michalewicz, 66 | Shubert, 67 | SixHumpCamel, 68 | ThreeHumpCamel, 69 | Colville, 70 | Hartmann3D, 71 | Hartmann6D, 72 | ] 73 | 74 | 75 | def find_global_minimum(obj_fun): 76 | print(obj_fun.name, flush=True) 77 | 78 | fun_target = lambda bx: np.squeeze(obj_fun.output(bx), axis=1) 79 | 80 | grids = obj_fun.sample_grids(5) 81 | grids = np.concatenate((grids, obj_fun.get_global_minimizers()), axis=0) 82 | 83 | list_bx = [] 84 | list_by = [] 85 | 86 | for initial in grids: 87 | results = scio.minimize(fun_target, initial, method='L-BFGS-B', bounds=obj_fun.get_bounds()) 88 | 89 | list_bx.append(results.x) 90 | list_by.append(results.fun) 91 | 92 | ind_minimum = np.argmin(np.squeeze(list_by)) 93 | bx_best = list_bx[ind_minimum] 94 | y_best = list_by[ind_minimum] 95 | 96 | print(bx_best, flush=True) 97 | print(obj_fun.global_minimum, flush=True) 98 | print(y_best, flush=True) 99 | print('', flush=True) 100 | 101 | X = np.array(list_bx) 102 | by = np.squeeze(list_by) 103 | indices = np.argsort(by) 104 | X = X[indices] 105 | by = by[indices] 106 | 107 | print('candidates of global optima', flush=True) 108 | for bx_candidate, y_candidate in zip(X, by): 109 | if (obj_fun.global_minimum - y_candidate) > 0: 110 | print(bx_candidate, y_candidate, flush=True) 111 | print('', flush=True) 112 | 113 | assert (obj_fun.global_minimum - y_best) <= TEST_EPSILON 114 | assert (obj_fun.global_minimum - y_best) <= 0 115 | 116 | for global_minimizer in obj_fun.get_global_minimizers(): 117 | assert (obj_fun.global_minimum - fun_target(global_minimizer)[0]) <= 0 118 | 119 | 120 | if __name__ == '__main__': 121 | for class_fun in all_benchmarks: 122 | try: 123 | obj_fun = class_fun() 124 | except: 125 | obj_fun = class_fun(2) 126 | 127 | find_global_minimum(obj_fun) 128 | -------------------------------------------------------------------------------- /examples/plot_benchmarks.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jungtaek.kim.mail@gmail.com) 3 | # last updated: August 4, 2023 4 | # 5 | 6 | import numpy as np 7 | import os 8 | import matplotlib.pyplot as plt 9 | 10 | 11 | def plot_1d(obj_fun, 12 | str_fun, 13 | str_x_axis=r'$x$', 14 | str_y_axis=r'$f(x)$', 15 | str_figures='../figures', 16 | show_figure=False, 17 | bounds=None, # for zooming in on part of a figure 18 | ): 19 | print(str_fun) 20 | 21 | if bounds is None: 22 | bounds = obj_fun.get_bounds() 23 | print(bounds) 24 | assert bounds.shape[0] == 1 25 | 26 | X = np.linspace(bounds[0, 0], bounds[0, 1], 1000) 27 | Y = obj_fun.output(X[..., np.newaxis]).flatten() 28 | 29 | assert len(X.shape) == 1 30 | assert len(Y.shape) == 1 31 | assert X.shape[0] == Y.shape[0] 32 | 33 | plt.rc('text', usetex=True) 34 | 35 | _ = plt.figure(figsize=(10, 6)) 36 | ax = plt.gca() 37 | 38 | ax.plot(X, Y, 39 | linewidth=4, 40 | marker='None') 41 | 42 | ax.set_xlabel(str_x_axis, fontsize=36) 43 | ax.set_ylabel(str_y_axis, fontsize=36) 44 | ax.tick_params(labelsize=24) 45 | 46 | ax.set_xlim([np.min(X), np.max(X)]) 47 | ax.grid() 48 | 49 | plt.tight_layout() 50 | plt.savefig(os.path.join(str_figures, str_fun + '.pdf'), 51 | format='pdf', 52 | transparent=True, 53 | bbox_inches='tight') 54 | 55 | if show_figure: 56 | plt.show() 57 | 58 | plt.close('all') 59 | 60 | def plot_2d(obj_fun, 61 | str_fun, 62 | str_x1_axis=r'$x_1$', 63 | str_x2_axis=r'$x_2$', 64 | str_y_axis=r'$f(\mathbf{x})$', 65 | str_figures='../figures', 66 | show_figure=False, 67 | bounds=None, # for zooming in on part of a figure 68 | ): 69 | print(str_fun) 70 | 71 | if bounds is None: 72 | bounds = obj_fun.get_bounds() 73 | print(bounds) 74 | assert bounds.shape[0] == 2 75 | 76 | num_grids = 300 77 | 78 | X1 = np.linspace(bounds[0, 0], bounds[0, 1], num_grids) 79 | X2 = np.linspace(bounds[1, 0], bounds[1, 1], num_grids) 80 | 81 | if obj_fun.name == 'easom': 82 | num_grids_additional = 300 83 | 84 | X1 = np.concatenate([ 85 | X1, 86 | np.linspace(np.pi - 3.0, np.pi + 3.0, num_grids_additional) 87 | ], axis=0) 88 | X2 = np.concatenate([ 89 | X2, 90 | np.linspace(np.pi - 3.0, np.pi + 3.0, num_grids_additional) 91 | ], axis=0) 92 | 93 | X1 = np.sort(X1) 94 | X2 = np.sort(X2) 95 | 96 | X1, X2 = np.meshgrid(X1, X2) 97 | X = np.concatenate((X1[..., np.newaxis], X2[..., np.newaxis]), axis=2) 98 | X = np.reshape(X, (X.shape[0] * X.shape[1], X.shape[2])) 99 | 100 | Y = obj_fun.output(X).flatten() 101 | 102 | assert len(X.shape) == 2 103 | assert len(Y.shape) == 1 104 | assert X.shape[0] == Y.shape[0] 105 | 106 | Y = np.reshape(Y, (X1.shape[0], X2.shape[0])) 107 | 108 | plt.rc('text', usetex=True) 109 | 110 | _ = plt.figure(figsize=(8, 6)) 111 | ax = plt.axes(projection='3d') 112 | 113 | surf = ax.plot_surface(X1, X2, Y, 114 | cmap='coolwarm', 115 | linewidth=0) 116 | 117 | ax.set_xlabel(str_x1_axis, fontsize=24, labelpad=10) 118 | ax.set_ylabel(str_x2_axis, fontsize=24, labelpad=10) 119 | ax.set_zlabel(str_y_axis, fontsize=24, labelpad=10) 120 | ax.tick_params(labelsize=16) 121 | 122 | ax.set_xlim([np.min(X1), np.max(X1)]) 123 | ax.set_ylim([np.min(X2), np.max(X2)]) 124 | ax.grid() 125 | 126 | cbar = plt.colorbar(surf, 127 | shrink=0.6, 128 | aspect=12, 129 | pad=0.15, 130 | ) 131 | cbar.ax.tick_params(labelsize=16) 132 | 133 | if np.max(Y) > 1000: 134 | plt.ticklabel_format(axis='z', style='sci', scilimits=(0, 0), useMathText=True) 135 | ax.zaxis.get_offset_text().set_fontsize(14) 136 | 137 | plt.tight_layout() 138 | plt.savefig(os.path.join(str_figures, str_fun + '.pdf'), 139 | format='pdf', 140 | transparent=True, 141 | bbox_inches='tight') 142 | 143 | if show_figure: 144 | plt.show() 145 | 146 | plt.close('all') 147 | 148 | 149 | if __name__ == '__main__': 150 | # one dim. 151 | from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 as target_class 152 | obj_fun = target_class() 153 | plot_1d(obj_fun, 'gramacyandlee2012_1d') 154 | 155 | from bayeso_benchmarks.inf_dim_ackley import Ackley as target_class 156 | obj_fun = target_class(1) 157 | plot_1d(obj_fun, 'ackley_1d') 158 | 159 | from bayeso_benchmarks.inf_dim_cosines import Cosines as target_class 160 | obj_fun = target_class(1) 161 | plot_1d(obj_fun, 'cosines_1d') 162 | 163 | from bayeso_benchmarks.inf_dim_griewank import Griewank as target_class 164 | obj_fun = target_class(1) 165 | plot_1d(obj_fun, 'griewank_1d') 166 | plot_1d(obj_fun, 'griewank_zoom_in_1d', bounds=np.array([[-50, 50]])) 167 | 168 | from bayeso_benchmarks.inf_dim_levy import Levy as target_class 169 | obj_fun = target_class(1) 170 | plot_1d(obj_fun, 'levy_1d') 171 | 172 | from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin as target_class 173 | obj_fun = target_class(1) 174 | plot_1d(obj_fun, 'rastrigin_1d') 175 | 176 | from bayeso_benchmarks.inf_dim_sphere import Sphere as target_class 177 | obj_fun = target_class(1) 178 | plot_1d(obj_fun, 'sphere_1d') 179 | 180 | from bayeso_benchmarks.inf_dim_zakharov import Zakharov as target_class 181 | obj_fun = target_class(1) 182 | plot_1d(obj_fun, 'zakharov_1d') 183 | 184 | # two dim. 185 | from bayeso_benchmarks.two_dim_beale import Beale as target_class 186 | obj_fun = target_class() 187 | plot_2d(obj_fun, 'beale_2d') 188 | 189 | from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky as target_class 190 | obj_fun = target_class() 191 | plot_2d(obj_fun, 'bohachevsky_2d') 192 | 193 | from bayeso_benchmarks.two_dim_branin import Branin as target_class 194 | obj_fun = target_class() 195 | plot_2d(obj_fun, 'branin_2d') 196 | 197 | from bayeso_benchmarks.two_dim_bukin6 import Bukin6 as target_class 198 | obj_fun = target_class() 199 | plot_2d(obj_fun, 'bukin6_2d') 200 | 201 | from bayeso_benchmarks.two_dim_dejong5 import DeJong5 as target_class 202 | obj_fun = target_class() 203 | plot_2d(obj_fun, 'dejong5_2d') 204 | 205 | from bayeso_benchmarks.two_dim_dropwave import DropWave as target_class 206 | obj_fun = target_class() 207 | plot_2d(obj_fun, 'dropwave_2d') 208 | 209 | from bayeso_benchmarks.two_dim_easom import Easom as target_class 210 | obj_fun = target_class() 211 | plot_2d(obj_fun, 'easom_2d') 212 | 213 | from bayeso_benchmarks.two_dim_eggholder import Eggholder as target_class 214 | obj_fun = target_class() 215 | plot_2d(obj_fun, 'eggholder_2d') 216 | 217 | from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice as target_class 218 | obj_fun = target_class() 219 | plot_2d(obj_fun, 'goldsteinprice_2d') 220 | 221 | from bayeso_benchmarks.two_dim_holdertable import HolderTable as target_class 222 | obj_fun = target_class() 223 | plot_2d(obj_fun, 'holdertable_2d') 224 | 225 | from bayeso_benchmarks.two_dim_kim1 import Kim1 as target_class 226 | obj_fun = target_class() 227 | plot_2d(obj_fun, 'kim1_2d') 228 | 229 | from bayeso_benchmarks.two_dim_kim2 import Kim2 as target_class 230 | obj_fun = target_class() 231 | plot_2d(obj_fun, 'kim2_2d') 232 | 233 | from bayeso_benchmarks.two_dim_kim3 import Kim3 as target_class 234 | obj_fun = target_class() 235 | plot_2d(obj_fun, 'kim3_2d') 236 | 237 | from bayeso_benchmarks.two_dim_michalewicz import Michalewicz as target_class 238 | obj_fun = target_class() 239 | plot_2d(obj_fun, 'michalewicz_2d') 240 | 241 | from bayeso_benchmarks.two_dim_shubert import Shubert as target_class 242 | obj_fun = target_class() 243 | plot_2d(obj_fun, 'shubert_2d') 244 | 245 | from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel as target_class 246 | obj_fun = target_class() 247 | plot_2d(obj_fun, 'sixhumpcamel_2d') 248 | 249 | from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel as target_class 250 | obj_fun = target_class() 251 | plot_2d(obj_fun, 'threehumpcamel_2d') 252 | 253 | from bayeso_benchmarks.inf_dim_ackley import Ackley as target_class 254 | obj_fun = target_class(2) 255 | plot_2d(obj_fun, 'ackley_2d') 256 | 257 | from bayeso_benchmarks.inf_dim_cosines import Cosines as target_class 258 | obj_fun = target_class(2) 259 | plot_2d(obj_fun, 'cosines_2d') 260 | 261 | from bayeso_benchmarks.inf_dim_griewank import Griewank as target_class 262 | obj_fun = target_class(2) 263 | plot_2d(obj_fun, 'griewank_2d') 264 | plot_2d(obj_fun, 'griewank_zoom_in_2d', bounds=np.array([[-50, 50], [-50, 50]])) 265 | 266 | from bayeso_benchmarks.inf_dim_levy import Levy as target_class 267 | obj_fun = target_class(2) 268 | plot_2d(obj_fun, 'levy_2d') 269 | 270 | from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin as target_class 271 | obj_fun = target_class(2) 272 | plot_2d(obj_fun, 'rastrigin_2d') 273 | 274 | from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock as target_class 275 | obj_fun = target_class(2) 276 | plot_2d(obj_fun, 'rosenbrock_2d') 277 | 278 | from bayeso_benchmarks.inf_dim_sphere import Sphere as target_class 279 | obj_fun = target_class(2) 280 | plot_2d(obj_fun, 'sphere_2d') 281 | 282 | from bayeso_benchmarks.inf_dim_zakharov import Zakharov as target_class 283 | obj_fun = target_class(2) 284 | plot_2d(obj_fun, 'zakharov_2d') 285 | -------------------------------------------------------------------------------- /figures/ackley_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/ackley_1d.pdf -------------------------------------------------------------------------------- /figures/ackley_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/ackley_2d.pdf -------------------------------------------------------------------------------- /figures/beale_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/beale_2d.pdf -------------------------------------------------------------------------------- /figures/bohachevsky_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/bohachevsky_2d.pdf -------------------------------------------------------------------------------- /figures/branin_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/branin_2d.pdf -------------------------------------------------------------------------------- /figures/bukin6_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/bukin6_2d.pdf -------------------------------------------------------------------------------- /figures/cosines_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/cosines_1d.pdf -------------------------------------------------------------------------------- /figures/cosines_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/cosines_2d.pdf -------------------------------------------------------------------------------- /figures/dejong5_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/dejong5_2d.pdf -------------------------------------------------------------------------------- /figures/dropwave_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/dropwave_2d.pdf -------------------------------------------------------------------------------- /figures/easom_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/easom_2d.pdf -------------------------------------------------------------------------------- /figures/eggholder_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/eggholder_2d.pdf -------------------------------------------------------------------------------- /figures/goldsteinprice_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/goldsteinprice_2d.pdf -------------------------------------------------------------------------------- /figures/gramacyandlee2012_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/gramacyandlee2012_1d.pdf -------------------------------------------------------------------------------- /figures/griewank_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/griewank_1d.pdf -------------------------------------------------------------------------------- /figures/griewank_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/griewank_2d.pdf -------------------------------------------------------------------------------- /figures/griewank_zoom_in_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/griewank_zoom_in_1d.pdf -------------------------------------------------------------------------------- /figures/griewank_zoom_in_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/griewank_zoom_in_2d.pdf -------------------------------------------------------------------------------- /figures/holdertable_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/holdertable_2d.pdf -------------------------------------------------------------------------------- /figures/kim1_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/kim1_2d.pdf -------------------------------------------------------------------------------- /figures/kim2_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/kim2_2d.pdf -------------------------------------------------------------------------------- /figures/kim3_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/kim3_2d.pdf -------------------------------------------------------------------------------- /figures/levy_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/levy_1d.pdf -------------------------------------------------------------------------------- /figures/levy_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/levy_2d.pdf -------------------------------------------------------------------------------- /figures/michalewicz_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/michalewicz_2d.pdf -------------------------------------------------------------------------------- /figures/rastrigin_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/rastrigin_1d.pdf -------------------------------------------------------------------------------- /figures/rastrigin_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/rastrigin_2d.pdf -------------------------------------------------------------------------------- /figures/rosenbrock_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/rosenbrock_2d.pdf -------------------------------------------------------------------------------- /figures/shubert_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/shubert_2d.pdf -------------------------------------------------------------------------------- /figures/sixhumpcamel_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/sixhumpcamel_2d.pdf -------------------------------------------------------------------------------- /figures/sphere_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/sphere_1d.pdf -------------------------------------------------------------------------------- /figures/sphere_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/sphere_2d.pdf -------------------------------------------------------------------------------- /figures/threehumpcamel_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/threehumpcamel_2d.pdf -------------------------------------------------------------------------------- /figures/zakharov_1d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/zakharov_1d.pdf -------------------------------------------------------------------------------- /figures/zakharov_2d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jungtaekkim/bayeso-benchmarks/4f39c2f9d160af261253f0c9539271c2671ac202/figures/zakharov_2d.pdf -------------------------------------------------------------------------------- /publish_new_release.txt: -------------------------------------------------------------------------------- 1 | # 0. (If needed) Install setuptools, wheel, build, and twine. 2 | 3 | # 1. Merge a working branch to the main branch first. 4 | 5 | # 2. Clone the main branch in a new clean directory. 6 | 7 | # 3. Create wheel and source files. 8 | python3 -m build 9 | 10 | # 4. Upload wheel and source files to the PyPI repository. 11 | python3 -m twine upload dist/* 12 | 13 | # 5. (Optional) Upload to Anaconda repository. 14 | ~/anaconda3/bin/anaconda upload dist/*.tar.gz 15 | # or 16 | anaconda upload dist/*.tar.gz 17 | 18 | # 6. Publish a new release at GitHub. 19 | ## Create a tag at GitHub. 20 | ## Make sure that it is created in the main branch. 21 | ## Assign the tag to a new release. 22 | ## The name convention of tags is "v0.5.5". 23 | ## Upload the wheel and source files, which can be downloaded from the PyPI repository, together. 24 | 25 | # 7. Check out Zenodo or upload the release on Zenodo. 26 | ## To upload the release, download a ZIP file from a particular tag. 27 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "setuptools.build_meta" 3 | requires = [ 4 | "setuptools", 5 | ] 6 | 7 | [tool.setuptools] 8 | packages = ["bayeso_benchmarks"] 9 | 10 | [project] 11 | name = "bayeso-benchmarks" 12 | version = "0.2.0" 13 | authors = [ 14 | {name = "Jungtaek Kim", email = "jungtaek.kim.mail@gmail.com"}, 15 | ] 16 | description = "Benchmark functions for Bayesian optimization" 17 | readme = "README.md" 18 | requires-python = ">=3.7" 19 | dependencies = [ 20 | "numpy", 21 | ] 22 | license = {text = "MIT"} 23 | classifiers = [ 24 | "Programming Language :: Python :: 3", 25 | "Intended Audience :: Science/Research", 26 | "License :: OSI Approved :: MIT License", 27 | "Operating System :: OS Independent", 28 | "Topic :: Scientific/Engineering", 29 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 30 | ] 31 | 32 | [project.urls] 33 | Homepage = "https://bayeso.org" 34 | Source = "https://github.com/jungtaekkim/bayeso-benchmarks" 35 | Issues = "https://github.com/jungtaekkim/bayeso-benchmarks/issues" 36 | 37 | [project.optional-dependencies] 38 | dev = [ 39 | "pytest", 40 | "wheel", 41 | "build", 42 | "twine", 43 | "scipy", 44 | "matplotlib", 45 | ] 46 | -------------------------------------------------------------------------------- /tests/test_four_dim_colville.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 30, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.four_dim_colville import * 10 | 11 | class_fun = Colville 12 | str_name = 'colville' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [2304082.], 36 | [2111692.], 37 | [1939322.], 38 | [1223962.], 39 | [1211572.], 40 | [1219202.], 41 | [2304042.], 42 | [2111652.], 43 | [1939282.], 44 | [1103962.], 45 | [911572.], 46 | [739202.], 47 | [23842.], 48 | [11452.], 49 | [19082.], 50 | [1103922.], 51 | [911532.], 52 | [739162.], 53 | [2304042.], 54 | [2111652.], 55 | [1939282.], 56 | [1223922.], 57 | [1211532.], 58 | [1219162.], 59 | [2304002.], 60 | [2111612.], 61 | [1939242.], 62 | [2090692.], 63 | [1900282.], 64 | [1729892.], 65 | [1010572.], 66 | [1000162.], 67 | [1009772.], 68 | [2090652.], 69 | [1900242.], 70 | [1729852.], 71 | [1090572.], 72 | [900162.], 73 | [729772.], 74 | [10452.], 75 | [42.], 76 | [9652.], 77 | [1090532.], 78 | [900122.], 79 | [729732.], 80 | [2090652.], 81 | [1900242.], 82 | [1729852.], 83 | [1010532.], 84 | [1000122.], 85 | [1009732.], 86 | [2090612.], 87 | [1900202.], 88 | [1729812.], 89 | [1899322.], 90 | [1710892.], 91 | [1542482.], 92 | [819202.], 93 | [810772.], 94 | [822362.], 95 | [1899282.], 96 | [1710852.], 97 | [1542442.], 98 | [1099202.], 99 | [910772.], 100 | [742362.], 101 | [19082.], 102 | [10652.], 103 | [22242.], 104 | [1099162.], 105 | [910732.], 106 | [742322.], 107 | [1899282.], 108 | [1710852.], 109 | [1542442.], 110 | [819162.], 111 | [810732.], 112 | [822322.], 113 | [1899242.], 114 | [1710812.], 115 | [1542402.], 116 | ]) 117 | outputs = obj_fun(grids) 118 | 119 | print(grids) 120 | print(outputs) 121 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 122 | 123 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 124 | 125 | def test_call(): 126 | obj_fun = class_fun() 127 | bounds = obj_fun.get_bounds() 128 | 129 | grids = obj_fun.sample_grids(3) 130 | truths_grids = np.array([ 131 | [2304082.], 132 | [2111692.], 133 | [1939322.], 134 | [1223962.], 135 | [1211572.], 136 | [1219202.], 137 | [2304042.], 138 | [2111652.], 139 | [1939282.], 140 | [1103962.], 141 | [911572.], 142 | [739202.], 143 | [23842.], 144 | [11452.], 145 | [19082.], 146 | [1103922.], 147 | [911532.], 148 | [739162.], 149 | [2304042.], 150 | [2111652.], 151 | [1939282.], 152 | [1223922.], 153 | [1211532.], 154 | [1219162.], 155 | [2304002.], 156 | [2111612.], 157 | [1939242.], 158 | [2090692.], 159 | [1900282.], 160 | [1729892.], 161 | [1010572.], 162 | [1000162.], 163 | [1009772.], 164 | [2090652.], 165 | [1900242.], 166 | [1729852.], 167 | [1090572.], 168 | [900162.], 169 | [729772.], 170 | [10452.], 171 | [42.], 172 | [9652.], 173 | [1090532.], 174 | [900122.], 175 | [729732.], 176 | [2090652.], 177 | [1900242.], 178 | [1729852.], 179 | [1010532.], 180 | [1000122.], 181 | [1009732.], 182 | [2090612.], 183 | [1900202.], 184 | [1729812.], 185 | [1899322.], 186 | [1710892.], 187 | [1542482.], 188 | [819202.], 189 | [810772.], 190 | [822362.], 191 | [1899282.], 192 | [1710852.], 193 | [1542442.], 194 | [1099202.], 195 | [910772.], 196 | [742362.], 197 | [19082.], 198 | [10652.], 199 | [22242.], 200 | [1099162.], 201 | [910732.], 202 | [742322.], 203 | [1899282.], 204 | [1710852.], 205 | [1542442.], 206 | [819162.], 207 | [810732.], 208 | [822322.], 209 | [1899242.], 210 | [1710812.], 211 | [1542402.], 212 | ]) 213 | outputs = obj_fun(grids) 214 | 215 | print(grids) 216 | print(outputs) 217 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 218 | 219 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 220 | 221 | def test_name(): 222 | obj_fun = class_fun() 223 | assert obj_fun.name == str_name 224 | 225 | assert obj_fun.__class__.__name__.lower() == str_name 226 | assert obj_fun.__class__.__qualname__.lower() == str_name 227 | -------------------------------------------------------------------------------- /tests/test_global_minimum.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 3, 2023 4 | # 5 | 6 | import numpy as np 7 | import scipy.optimize as scio 8 | import pytest 9 | 10 | from bayeso_benchmarks import Ackley 11 | from bayeso_benchmarks import Branin 12 | from bayeso_benchmarks import GramacyAndLee2012 13 | from bayeso_benchmarks import HolderTable 14 | from bayeso_benchmarks import Kim1 15 | from bayeso_benchmarks import Kim2 16 | from bayeso_benchmarks import Kim3 17 | from bayeso_benchmarks import Rastrigin 18 | from bayeso_benchmarks import Michalewicz 19 | from bayeso_benchmarks import Shubert 20 | 21 | 22 | TEST_EPSILON = 1e-7 23 | 24 | 25 | def _test_global_minimum(obj_fun): 26 | fun_target = lambda bx: np.squeeze(obj_fun.output(bx), axis=1) 27 | 28 | grids = obj_fun.sample_grids(100) 29 | 30 | list_bx = [] 31 | list_by = [] 32 | 33 | for initial in grids: 34 | results = scio.minimize(fun_target, initial, method='L-BFGS-B', bounds=obj_fun.get_bounds()) 35 | 36 | list_bx.append(results.x) 37 | list_by.append(results.fun) 38 | 39 | ind_minimum = np.argmin(np.squeeze(list_by)) 40 | bx_best = list_bx[ind_minimum] 41 | y_best = list_by[ind_minimum] 42 | 43 | print(bx_best) 44 | print(obj_fun.global_minimum) 45 | print(y_best) 46 | 47 | X = np.array(list_bx) 48 | by = np.squeeze(list_by) 49 | indices = np.argsort(by) 50 | X = X[indices] 51 | by = by[indices] 52 | 53 | for bx_candidate, y_candidate in zip(X, by): 54 | if np.abs(obj_fun.global_minimum - y_candidate) < 1e0: 55 | print(bx_candidate, y_candidate) 56 | 57 | assert np.abs(obj_fun.global_minimum - y_best) < TEST_EPSILON 58 | 59 | for global_minimizer in obj_fun.get_global_minimizers(): 60 | assert np.abs(obj_fun.global_minimum - fun_target(global_minimizer)[0]) < TEST_EPSILON 61 | 62 | def test_global_minimum_branin(): 63 | class_fun = Branin 64 | obj_fun = class_fun() 65 | 66 | _test_global_minimum(obj_fun) 67 | 68 | def test_global_minimum_gramacyandlee2012(): 69 | class_fun = GramacyAndLee2012 70 | obj_fun = class_fun() 71 | 72 | _test_global_minimum(obj_fun) 73 | 74 | def test_global_minimum_holdertable(): 75 | class_fun = HolderTable 76 | obj_fun = class_fun() 77 | 78 | _test_global_minimum(obj_fun) 79 | 80 | def test_global_minimum_kim1(): 81 | class_fun = Kim1 82 | obj_fun = class_fun() 83 | 84 | _test_global_minimum(obj_fun) 85 | 86 | def test_global_minimum_kim2(): 87 | class_fun = Kim2 88 | obj_fun = class_fun() 89 | 90 | _test_global_minimum(obj_fun) 91 | 92 | def test_global_minimum_kim3(): 93 | class_fun = Kim3 94 | obj_fun = class_fun() 95 | 96 | _test_global_minimum(obj_fun) 97 | 98 | def test_global_minimum_shubert(): 99 | class_fun = Shubert 100 | obj_fun = class_fun() 101 | 102 | _test_global_minimum(obj_fun) 103 | -------------------------------------------------------------------------------- /tests/test_import.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 4, 2023 4 | # 5 | 6 | 7 | def test_import_benchmarks(): 8 | import bayeso_benchmarks 9 | 10 | def test_all_benchmarks(): 11 | import bayeso_benchmarks 12 | 13 | list_str_names = [ 14 | 'ackley', 15 | 'cosines', 16 | 'levy', 17 | 'rastrigin', 18 | 'rosenbrock', 19 | 'sphere', 20 | 'zakharov', 21 | 'constant', 22 | 'gramacyandlee2012', 23 | 'linear', 24 | 'step', 25 | 'colville', 26 | 'hartmann3d', 27 | 'hartmann6d', 28 | 'beale', 29 | 'bohachevsky', 30 | 'branin', 31 | 'bukin6', 32 | 'dejong5', 33 | 'dropwave', 34 | 'easom', 35 | 'eggholder', 36 | 'goldsteinprice', 37 | 'holdertable', 38 | 'kim1', 39 | 'kim2', 40 | 'kim3', 41 | 'michalewicz', 42 | 'shubert', 43 | 'sixhumpcamel', 44 | 'threehumpcamel', 45 | ] 46 | 47 | names = [] 48 | for class_benchmark in bayeso_benchmarks.all_benchmarks: 49 | print(class_benchmark.__name__.lower()) 50 | names.append(class_benchmark.__name__.lower()) 51 | 52 | for str_name in list_str_names: 53 | assert str_name in names 54 | 55 | qualnames = [] 56 | for class_benchmark in bayeso_benchmarks.all_benchmarks: 57 | print(class_benchmark.__qualname__.lower()) 58 | qualnames.append(class_benchmark.__qualname__.lower()) 59 | 60 | for str_name in list_str_names: 61 | assert str_name in qualnames 62 | 63 | def test_num_benchmarks(): 64 | import bayeso_benchmarks 65 | 66 | assert bayeso_benchmarks.num_benchmarks == 32 67 | 68 | def test_import_benchmark_base(): 69 | import bayeso_benchmarks.benchmark_base 70 | from bayeso_benchmarks.benchmark_base import Function 71 | 72 | def test_import_one_dim_constant(): 73 | import bayeso_benchmarks.one_dim_constant 74 | from bayeso_benchmarks.one_dim_constant import Constant 75 | from bayeso_benchmarks import Constant 76 | 77 | def test_import_one_dim_gramacyandlee2012(): 78 | import bayeso_benchmarks.one_dim_gramacyandlee2012 79 | from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 80 | from bayeso_benchmarks import GramacyAndLee2012 81 | 82 | def test_import_one_dim_linear(): 83 | import bayeso_benchmarks.one_dim_linear 84 | from bayeso_benchmarks.one_dim_linear import Linear 85 | from bayeso_benchmarks import Linear 86 | 87 | def test_import_one_dim_step(): 88 | import bayeso_benchmarks.one_dim_step 89 | from bayeso_benchmarks.one_dim_step import Step 90 | from bayeso_benchmarks import Step 91 | 92 | def test_import_two_dim_beale(): 93 | import bayeso_benchmarks.two_dim_beale 94 | from bayeso_benchmarks.two_dim_beale import Beale 95 | from bayeso_benchmarks import Beale 96 | 97 | def test_import_two_dim_bohachevsky(): 98 | import bayeso_benchmarks.two_dim_bohachevsky 99 | from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky 100 | from bayeso_benchmarks import Bohachevsky 101 | 102 | def test_import_two_dim_branin(): 103 | import bayeso_benchmarks.two_dim_branin 104 | from bayeso_benchmarks.two_dim_branin import Branin 105 | from bayeso_benchmarks import Branin 106 | 107 | def test_import_two_dim_bukin6(): 108 | import bayeso_benchmarks.two_dim_bukin6 109 | from bayeso_benchmarks.two_dim_bukin6 import Bukin6 110 | from bayeso_benchmarks import Bukin6 111 | 112 | def test_import_two_dim_dropwave(): 113 | import bayeso_benchmarks.two_dim_dropwave 114 | from bayeso_benchmarks.two_dim_dropwave import DropWave 115 | from bayeso_benchmarks import DropWave 116 | 117 | def test_import_two_dim_easom(): 118 | import bayeso_benchmarks.two_dim_easom 119 | from bayeso_benchmarks.two_dim_easom import Easom 120 | from bayeso_benchmarks import Easom 121 | 122 | def test_import_two_dim_eggholder(): 123 | import bayeso_benchmarks.two_dim_eggholder 124 | from bayeso_benchmarks.two_dim_eggholder import Eggholder 125 | from bayeso_benchmarks import Eggholder 126 | 127 | def test_import_two_dim_goldsteinprice(): 128 | import bayeso_benchmarks.two_dim_goldsteinprice 129 | from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice 130 | from bayeso_benchmarks import GoldsteinPrice 131 | 132 | def test_import_two_dim_holdertable(): 133 | import bayeso_benchmarks.two_dim_holdertable 134 | from bayeso_benchmarks.two_dim_holdertable import HolderTable 135 | from bayeso_benchmarks import HolderTable 136 | 137 | def test_import_two_dim_kim1(): 138 | import bayeso_benchmarks.two_dim_kim1 139 | from bayeso_benchmarks.two_dim_kim1 import Kim1 140 | from bayeso_benchmarks import Kim1 141 | 142 | def test_import_two_dim_kim2(): 143 | import bayeso_benchmarks.two_dim_kim2 144 | from bayeso_benchmarks.two_dim_kim2 import Kim2 145 | from bayeso_benchmarks import Kim2 146 | 147 | def test_import_two_dim_kim3(): 148 | import bayeso_benchmarks.two_dim_kim3 149 | from bayeso_benchmarks.two_dim_kim3 import Kim3 150 | from bayeso_benchmarks import Kim3 151 | 152 | def test_import_two_dim_michalewicz(): 153 | import bayeso_benchmarks.two_dim_michalewicz 154 | from bayeso_benchmarks.two_dim_michalewicz import Michalewicz 155 | from bayeso_benchmarks import Michalewicz 156 | 157 | def test_import_two_dim_shubert(): 158 | import bayeso_benchmarks.two_dim_shubert 159 | from bayeso_benchmarks.two_dim_shubert import Shubert 160 | from bayeso_benchmarks import Shubert 161 | 162 | def test_import_two_dim_sixhumpcamel(): 163 | import bayeso_benchmarks.two_dim_sixhumpcamel 164 | from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel 165 | from bayeso_benchmarks import SixHumpCamel 166 | 167 | def test_import_two_dim_threehumpcamel(): 168 | import bayeso_benchmarks.two_dim_threehumpcamel 169 | from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel 170 | from bayeso_benchmarks import ThreeHumpCamel 171 | 172 | def test_import_four_dim_colville(): 173 | import bayeso_benchmarks.four_dim_colville 174 | from bayeso_benchmarks.four_dim_colville import Colville 175 | from bayeso_benchmarks import Colville 176 | 177 | def test_import_three_dim_hartmann3d(): 178 | import bayeso_benchmarks.three_dim_hartmann3d 179 | from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D 180 | from bayeso_benchmarks import Hartmann3D 181 | 182 | def test_import_six_dim_hartmann6d(): 183 | import bayeso_benchmarks.six_dim_hartmann6d 184 | from bayeso_benchmarks.six_dim_hartmann6d import Hartmann6D 185 | from bayeso_benchmarks import Hartmann6D 186 | 187 | def test_import_inf_dim_ackley(): 188 | import bayeso_benchmarks.inf_dim_ackley 189 | from bayeso_benchmarks.inf_dim_ackley import Ackley 190 | from bayeso_benchmarks import Ackley 191 | 192 | def test_import_inf_dim_cosines(): 193 | import bayeso_benchmarks.inf_dim_cosines 194 | from bayeso_benchmarks.inf_dim_cosines import Cosines 195 | from bayeso_benchmarks import Cosines 196 | 197 | def test_import_inf_dim_griewank(): 198 | import bayeso_benchmarks.inf_dim_griewank 199 | from bayeso_benchmarks.inf_dim_griewank import Griewank 200 | from bayeso_benchmarks import Griewank 201 | 202 | def test_import_inf_dim_levy(): 203 | import bayeso_benchmarks.inf_dim_levy 204 | from bayeso_benchmarks.inf_dim_levy import Levy 205 | from bayeso_benchmarks import Levy 206 | 207 | def test_import_inf_dim_rastrigin(): 208 | import bayeso_benchmarks.inf_dim_rastrigin 209 | from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin 210 | from bayeso_benchmarks import Rastrigin 211 | 212 | def test_import_inf_dim_rosenbrock(): 213 | import bayeso_benchmarks.inf_dim_rosenbrock 214 | from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock 215 | from bayeso_benchmarks import Rosenbrock 216 | 217 | def test_import_inf_dim_sphere(): 218 | import bayeso_benchmarks.inf_dim_sphere 219 | from bayeso_benchmarks.inf_dim_sphere import Sphere 220 | from bayeso_benchmarks import Sphere 221 | 222 | def test_import_inf_dim_zakharov(): 223 | import bayeso_benchmarks.inf_dim_zakharov 224 | from bayeso_benchmarks.inf_dim_zakharov import Zakharov 225 | from bayeso_benchmarks import Zakharov 226 | -------------------------------------------------------------------------------- /tests/test_inf_dim_ackley.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.inf_dim_ackley import * 10 | 11 | class_fun = Ackley 12 | str_name = 'ackley' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun(2) 19 | 20 | with pytest.raises(TypeError) as error: 21 | class_fun() 22 | with pytest.raises(AssertionError) as error: 23 | class_fun('abc') 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(2.1) 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(2, seed='abc') 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(2, seed=2.1) 30 | 31 | def test_validate_properties(): 32 | obj_fun = class_fun(5) 33 | obj_fun.validate_properties() 34 | 35 | def test_output(): 36 | obj_fun = class_fun(3) 37 | bounds = obj_fun.get_bounds() 38 | 39 | grids = obj_fun.sample_grids(3) 40 | truths_grids = np.array([ 41 | [2.15703112e+01], 42 | [2.11187470e+01], 43 | [2.15703112e+01], 44 | [2.11187470e+01], 45 | [2.02411230e+01], 46 | [2.11187470e+01], 47 | [2.15703112e+01], 48 | [2.11187470e+01], 49 | [2.15703112e+01], 50 | [2.11187470e+01], 51 | [2.02411230e+01], 52 | [2.11187470e+01], 53 | [2.02411230e+01], 54 | [4.44089210e-16], 55 | [2.02411230e+01], 56 | [2.11187470e+01], 57 | [2.02411230e+01], 58 | [2.11187470e+01], 59 | [2.15703112e+01], 60 | [2.11187470e+01], 61 | [2.15703112e+01], 62 | [2.11187470e+01], 63 | [2.02411230e+01], 64 | [2.11187470e+01], 65 | [2.15703112e+01], 66 | [2.11187470e+01], 67 | [2.15703112e+01], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun.output(grids)) 72 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_call(): 76 | obj_fun = class_fun(3) 77 | bounds = obj_fun.get_bounds() 78 | 79 | grids = obj_fun.sample_grids(3) 80 | truths_grids = np.array([ 81 | [2.15703112e+01], 82 | [2.11187470e+01], 83 | [2.15703112e+01], 84 | [2.11187470e+01], 85 | [2.02411230e+01], 86 | [2.11187470e+01], 87 | [2.15703112e+01], 88 | [2.11187470e+01], 89 | [2.15703112e+01], 90 | [2.11187470e+01], 91 | [2.02411230e+01], 92 | [2.11187470e+01], 93 | [2.02411230e+01], 94 | [4.44089210e-16], 95 | [2.02411230e+01], 96 | [2.11187470e+01], 97 | [2.02411230e+01], 98 | [2.11187470e+01], 99 | [2.15703112e+01], 100 | [2.11187470e+01], 101 | [2.15703112e+01], 102 | [2.11187470e+01], 103 | [2.02411230e+01], 104 | [2.11187470e+01], 105 | [2.15703112e+01], 106 | [2.11187470e+01], 107 | [2.15703112e+01], 108 | ]) 109 | 110 | print(grids) 111 | print(obj_fun(grids)) 112 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 113 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 114 | 115 | def test_name(): 116 | obj_fun = class_fun(2) 117 | assert obj_fun.name == str_name + '_2' 118 | 119 | obj_fun = class_fun(4) 120 | assert obj_fun.name == str_name + '_4' 121 | 122 | obj_fun = class_fun(16) 123 | assert obj_fun.name == str_name + '_16' 124 | 125 | assert obj_fun.__class__.__name__.lower() == str_name 126 | assert obj_fun.__class__.__qualname__.lower() == str_name 127 | -------------------------------------------------------------------------------- /tests/test_inf_dim_cosines.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.inf_dim_cosines import * 10 | 11 | class_fun = Cosines 12 | str_name = 'cosines' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun(5) 19 | 20 | with pytest.raises(TypeError) as error: 21 | class_fun() 22 | with pytest.raises(AssertionError) as error: 23 | class_fun('abc') 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(2.1) 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(2, seed='abc') 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(2, seed=2.1) 30 | 31 | def test_validate_properties(): 32 | obj_fun = class_fun(1) 33 | obj_fun.validate_properties() 34 | 35 | def test_output(): 36 | obj_fun = class_fun(3) 37 | bounds = obj_fun.get_bounds() 38 | 39 | grids = obj_fun.sample_grids(3) 40 | truths_grids = np.array([ 41 | [-2.7], 42 | [-2.8], 43 | [-2.7], 44 | [-2.8], 45 | [-2.9], 46 | [-2.8], 47 | [-2.7], 48 | [-2.8], 49 | [-2.7], 50 | [-2.8], 51 | [-2.9], 52 | [-2.8], 53 | [-2.9], 54 | [-3.0], 55 | [-2.9], 56 | [-2.8], 57 | [-2.9], 58 | [-2.8], 59 | [-2.7], 60 | [-2.8], 61 | [-2.7], 62 | [-2.8], 63 | [-2.9], 64 | [-2.8], 65 | [-2.7], 66 | [-2.8], 67 | [-2.7] 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun.output(grids)) 72 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_name(): 76 | obj_fun = class_fun(2) 77 | assert obj_fun.name == str_name + '_2' 78 | 79 | obj_fun = class_fun(4) 80 | assert obj_fun.name == str_name + '_4' 81 | 82 | obj_fun = class_fun(16) 83 | assert obj_fun.name == str_name + '_16' 84 | 85 | assert obj_fun.__class__.__name__.lower() == str_name 86 | assert obj_fun.__class__.__qualname__.lower() == str_name 87 | -------------------------------------------------------------------------------- /tests/test_inf_dim_griewank.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 6, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.inf_dim_griewank import * 10 | 11 | class_fun = Griewank 12 | str_name = 'griewank' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun(16) 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun('abc') 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(4, seed=1.0) 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(4, seed='abc') 30 | 31 | def test_validate_properties(): 32 | obj_fun = class_fun(8) 33 | obj_fun.validate_properties() 34 | 35 | def test_output(): 36 | obj_fun = class_fun(4) 37 | bounds = obj_fun.get_bounds() 38 | 39 | grids = obj_fun.sample_grids(3) 40 | truths_grids = np.array([ 41 | [361.01465247], 42 | [270.33689088], 43 | [361.01465247], 44 | [271.02183025], 45 | [180.01205465], 46 | [271.02183025], 47 | [361.01465247], 48 | [270.33689088], 49 | [361.01465247], 50 | [270.98533321], 51 | [181.66375729], 52 | [270.98533321], 53 | [180.97814841], 54 | [91.98891104], 55 | [180.97814841], 56 | [270.98533321], 57 | [181.66375729], 58 | [270.98533321], 59 | [361.01465247], 60 | [270.33689088], 61 | [361.01465247], 62 | [271.02183025], 63 | [180.01205465], 64 | [271.02183025], 65 | [361.01465247], 66 | [270.33689088], 67 | [361.01465247], 68 | [270.98518323], 69 | [181.67054476], 70 | [270.98518323], 71 | [180.97792496], 72 | [91.99902348], 73 | [180.97792496], 74 | [270.98518323], 75 | [181.67054476], 76 | [270.98518323], 77 | [181.01483126], 78 | [90.3287998], 79 | [181.01483126], 80 | [91.02209662], 81 | [0.], 82 | [91.02209662], 83 | [181.01483126], 84 | [90.3287998], 85 | [181.01483126], 86 | [270.98518323], 87 | [181.67054476], 88 | [270.98518323], 89 | [180.97792496], 90 | [91.99902348], 91 | [180.97792496], 92 | [270.98518323], 93 | [181.67054476], 94 | [270.98518323], 95 | [361.01465247], 96 | [270.33689088], 97 | [361.01465247], 98 | [271.02183025], 99 | [180.01205465], 100 | [271.02183025], 101 | [361.01465247], 102 | [270.33689088], 103 | [361.01465247], 104 | [270.98533321], 105 | [181.66375729], 106 | [270.98533321], 107 | [180.97814841], 108 | [91.98891104], 109 | [180.97814841], 110 | [270.98533321], 111 | [181.66375729], 112 | [270.98533321], 113 | [361.01465247], 114 | [270.33689088], 115 | [361.01465247], 116 | [271.02183025], 117 | [180.01205465], 118 | [271.02183025], 119 | [361.01465247], 120 | [270.33689088], 121 | [361.01465247], 122 | ]) 123 | outputs = obj_fun.output(grids) 124 | 125 | print(grids) 126 | print(outputs) 127 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 128 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 129 | 130 | def test_call(): 131 | obj_fun = class_fun(2) 132 | bounds = obj_fun.get_bounds() 133 | 134 | grids = obj_fun.sample_grids(3) 135 | truths_grids = np.array([ 136 | [180.01205465], 137 | [91.98891104], 138 | [180.01205465], 139 | [91.99902348], 140 | [0.], 141 | [91.99902348], 142 | [180.01205465], 143 | [91.98891104], 144 | [180.01205465], 145 | ]) 146 | outputs = obj_fun(grids) 147 | 148 | print(grids) 149 | print(outputs) 150 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 151 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 152 | 153 | def test_output_constant_noise(): 154 | obj_fun = class_fun(2) 155 | bounds = obj_fun.get_bounds() 156 | 157 | grids = obj_fun.sample_grids(3) 158 | truths_grids = np.array([ 159 | [182.01205465], 160 | [93.98891104], 161 | [182.01205465], 162 | [93.99902348], 163 | [2.], 164 | [93.99902348], 165 | [182.01205465], 166 | [93.98891104], 167 | [182.01205465], 168 | ]) 169 | outputs = obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) 170 | 171 | print(grids) 172 | print(outputs) 173 | print(np.abs(outputs - truths_grids) < TEST_EPSILON + SCALE_NOISE) 174 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON + SCALE_NOISE) 175 | 176 | def test_output_gaussian_noise(): 177 | obj_fun = class_fun(4, seed=SEED) 178 | bounds = obj_fun.get_bounds() 179 | 180 | grids = obj_fun.sample_grids(3) 181 | truths_grids = np.array([ 182 | [362.00808078], 183 | [270.06036228], 184 | [362.31002955], 185 | [274.06788997], 186 | [179.5437479], 187 | [270.55355634], 188 | [364.1730781], 189 | [271.87176034], 190 | [360.0757037], 191 | [272.07045329], 192 | [180.73692191], 193 | [270.0538737], 194 | [181.46207295], 195 | [88.16235055], 196 | [177.52831274], 197 | [269.86075815], 198 | [179.63809505], 199 | [271.61382787], 200 | [359.19860432], 201 | [267.51228348], 202 | [363.94595001], 203 | [270.57027765], 204 | [180.14711106], 205 | [268.17233388], 206 | [359.92588702], 207 | [270.55873606], 208 | [358.71266531], 209 | [271.73657926], 210 | [180.46926738], 211 | [270.40179573], 212 | [179.77451173], 213 | [95.70357985], 214 | [180.95093051], 215 | [268.86976137], 216 | [183.31563459], 217 | [268.54349593], 218 | [181.43255845], 219 | [86.40945955], 220 | [178.35845916], 221 | [91.41581909], 222 | [1.47693316], 223 | [91.36483318], 224 | [180.78353469], 225 | [89.72659241], 226 | [178.05778727], 227 | [269.54549481], 228 | [180.74926722], 229 | [273.09942768], 230 | [181.66516154], 231 | [88.47294317], 232 | [181.6260929], 233 | [270.21501867], 234 | [180.31670076], 235 | [272.20853581], 236 | [363.07665151], 237 | [272.19945112], 238 | [359.33621742], 239 | [270.4034055], 240 | [180.67458151], 241 | [272.97292051], 242 | [360.05630399], 243 | [269.96557293], 244 | [358.80198252], 245 | [268.59291996], 246 | [183.28880894], 247 | [273.69781326], 248 | [180.83412817], 249 | [93.99597684], 250 | [181.70142046], 251 | [269.6950937], 252 | [182.3865485], 253 | [274.06140634], 254 | [360.94300039], 255 | [273.46617819], 256 | [355.77516226], 257 | [272.66563526], 258 | [180.18614879], 259 | [270.42381555], 260 | [361.19817402], 261 | [266.36175305], 262 | [360.57530869], 263 | ]) 264 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 265 | 266 | print(grids) 267 | print(outputs) 268 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 269 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 270 | 271 | def test_output_sparse_gaussian_noise(): 272 | obj_fun = class_fun(4, seed=SEED) 273 | bounds = obj_fun.get_bounds() 274 | 275 | grids = obj_fun.sample_grids(3) 276 | truths_grids = np.array([ 277 | [361.01465247], 278 | [270.33689088], 279 | [362.31002955], 280 | [274.06788997], 281 | [179.5437479], 282 | [270.55355634], 283 | [361.01465247], 284 | [270.33689088], 285 | [361.01465247], 286 | [270.98533321], 287 | [181.66375729], 288 | [270.0538737], 289 | [180.97814841], 290 | [91.98891104], 291 | [180.97814841], 292 | [270.98533321], 293 | [181.66375729], 294 | [271.61382787], 295 | [359.19860432], 296 | [270.33689088], 297 | [361.01465247], 298 | [271.02183025], 299 | [180.14711106], 300 | [271.02183025], 301 | [361.01465247], 302 | [270.55873606], 303 | [358.71266531], 304 | [270.98518323], 305 | [181.67054476], 306 | [270.98518323], 307 | [180.97792496], 308 | [91.99902348], 309 | [180.97792496], 310 | [270.98518323], 311 | [181.67054476], 312 | [268.54349593], 313 | [181.01483126], 314 | [90.3287998], 315 | [178.35845916], 316 | [91.41581909], 317 | [0.], 318 | [91.02209662], 319 | [180.78353469], 320 | [89.72659241], 321 | [181.01483126], 322 | [269.54549481], 323 | [180.74926722], 324 | [270.98518323], 325 | [180.97792496], 326 | [88.47294317], 327 | [180.97792496], 328 | [270.98518323], 329 | [180.31670076], 330 | [270.98518323], 331 | [361.01465247], 332 | [270.33689088], 333 | [361.01465247], 334 | [271.02183025], 335 | [180.67458151], 336 | [271.02183025], 337 | [361.01465247], 338 | [269.96557293], 339 | [358.80198252], 340 | [270.98533321], 341 | [181.66375729], 342 | [273.69781326], 343 | [180.97814841], 344 | [93.99597684], 345 | [180.97814841], 346 | [269.6950937], 347 | [181.66375729], 348 | [270.98533321], 349 | [361.01465247], 350 | [273.46617819], 351 | [361.01465247], 352 | [272.66563526], 353 | [180.01205465], 354 | [271.02183025], 355 | [361.19817402], 356 | [270.33689088], 357 | [361.01465247], 358 | ]) 359 | outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) 360 | 361 | print(grids) 362 | print(outputs) 363 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 364 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 365 | 366 | def test_output_student_t_noise(): 367 | obj_fun = class_fun(1, seed=SEED) 368 | bounds = obj_fun.get_bounds() 369 | 370 | grids = obj_fun.sample_grids(3) 371 | truths_grids = np.array([ 372 | [93.14825808], 373 | [-2.16338047], 374 | [94.63714051], 375 | ]) 376 | outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) 377 | 378 | print(grids) 379 | print(outputs) 380 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 381 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 382 | 383 | def test_output_sparse_student_t_noise(): 384 | obj_fun = class_fun(2, seed=SEED) 385 | bounds = obj_fun.get_bounds() 386 | 387 | grids = obj_fun.sample_grids(3) 388 | truths_grids = np.array([ 389 | [181.16128925], 390 | [89.82553057], 391 | [180.01205465], 392 | [91.99902348], 393 | [0.], 394 | [91.99902348], 395 | [176.08376221], 396 | [91.98891104], 397 | [180.01205465], 398 | ]) 399 | outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) 400 | 401 | print(grids) 402 | print(outputs) 403 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 404 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 405 | 406 | def test_name(): 407 | obj_fun = class_fun(2) 408 | assert obj_fun.name == str_name + '_2' 409 | 410 | obj_fun = class_fun(4) 411 | assert obj_fun.name == str_name + '_4' 412 | 413 | obj_fun = class_fun(16) 414 | assert obj_fun.name == str_name + '_16' 415 | 416 | assert obj_fun.__class__.__name__.lower() == str_name 417 | assert obj_fun.__class__.__qualname__.lower() == str_name 418 | -------------------------------------------------------------------------------- /tests/test_inf_dim_rosenbrock.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.inf_dim_rosenbrock import * 10 | 11 | class_fun = Rosenbrock 12 | str_name = 'rosenbrock' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun(2) 19 | 20 | with pytest.raises(TypeError) as error: 21 | class_fun() 22 | with pytest.raises(AssertionError) as error: 23 | class_fun('abc') 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(2.1) 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(2, seed='abc') 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(2, seed=2.1) 30 | 31 | def test_validate_properties(): 32 | obj_fun = class_fun(5) 33 | obj_fun.validate_properties() 34 | 35 | def test_output(): 36 | obj_fun = class_fun(3) 37 | bounds = obj_fun.get_bounds() 38 | 39 | grids = obj_fun.sample_grids(3) 40 | truths_grids = np.array([ 41 | [7.81185245e+03], 42 | [5.67443514e+03], 43 | [4.37587862e+03], 44 | [4.32635663e+03], 45 | [2.18893931e+03], 46 | [8.90382790e+02], 47 | [7.80366045e+03], 48 | [5.66624314e+03], 49 | [4.36768662e+03], 50 | [2.18893931e+03], 51 | [1.76950891e+03], 52 | [2.18893931e+03], 53 | [4.21430400e+02], 54 | [2.00000000e+00], 55 | [4.21430400e+02], 56 | [2.18074731e+03], 57 | [1.76131691e+03], 58 | [2.18074731e+03], 59 | [4.36768662e+03], 60 | [2.23026930e+03], 61 | [9.31712780e+02], 62 | [4.31816463e+03], 63 | [2.18074731e+03], 64 | [8.82190790e+02], 65 | [4.35949462e+03], 66 | [2.22207730e+03], 67 | [9.23520780e+02], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun.output(grids)) 72 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_name(): 76 | obj_fun = class_fun(2) 77 | assert obj_fun.name == str_name + '_2' 78 | 79 | obj_fun = class_fun(4) 80 | assert obj_fun.name == str_name + '_4' 81 | 82 | obj_fun = class_fun(16) 83 | assert obj_fun.name == str_name + '_16' 84 | 85 | assert obj_fun.__class__.__name__.lower() == str_name 86 | assert obj_fun.__class__.__qualname__.lower() == str_name 87 | -------------------------------------------------------------------------------- /tests/test_inf_dim_sphere.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.inf_dim_sphere import * 10 | 11 | class_fun = Sphere 12 | str_name = 'sphere' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun(2) 19 | 20 | with pytest.raises(TypeError) as error: 21 | class_fun() 22 | with pytest.raises(AssertionError) as error: 23 | class_fun('abc') 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(2.1) 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(2, seed='abc') 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(2, seed=2.1) 30 | 31 | def test_validate_properties(): 32 | obj_fun = class_fun(5) 33 | obj_fun.validate_properties() 34 | 35 | def test_output(): 36 | obj_fun = class_fun(3) 37 | bounds = obj_fun.get_bounds() 38 | 39 | grids = obj_fun.sample_grids(3) 40 | truths_grids = np.array([ 41 | [78.6432], 42 | [52.4288], 43 | [78.6432], 44 | [52.4288], 45 | [26.2144], 46 | [52.4288], 47 | [78.6432], 48 | [52.4288], 49 | [78.6432], 50 | [52.4288], 51 | [26.2144], 52 | [52.4288], 53 | [26.2144], 54 | [0.], 55 | [26.2144], 56 | [52.4288], 57 | [26.2144], 58 | [52.4288], 59 | [78.6432], 60 | [52.4288], 61 | [78.6432], 62 | [52.4288], 63 | [26.2144], 64 | [52.4288], 65 | [78.6432], 66 | [52.4288], 67 | [78.6432], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun.output(grids)) 72 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_name(): 76 | obj_fun = class_fun(2) 77 | assert obj_fun.name == str_name + '_2' 78 | 79 | obj_fun = class_fun(4) 80 | assert obj_fun.name == str_name + '_4' 81 | 82 | obj_fun = class_fun(16) 83 | assert obj_fun.name == str_name + '_16' 84 | 85 | assert obj_fun.__class__.__name__.lower() == str_name 86 | assert obj_fun.__class__.__qualname__.lower() == str_name 87 | -------------------------------------------------------------------------------- /tests/test_inf_dim_zakharov.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 4, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.inf_dim_zakharov import * 10 | 11 | class_fun = Zakharov 12 | str_name = 'zakharov' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun(16) 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun('abc') 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(4, seed=1.0) 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(4, seed='abc') 30 | 31 | def test_validate_properties(): 32 | obj_fun = class_fun(8) 33 | obj_fun.validate_properties() 34 | 35 | def test_output(): 36 | obj_fun = class_fun(4) 37 | bounds = obj_fun.get_bounds() 38 | 39 | grids = obj_fun.sample_grids(3) 40 | truths_grids = np.array([ 41 | [391350.], 42 | [10181.25], 43 | [825.], 44 | [36014.94140625], 45 | [66.50390625], 46 | [70149.31640625], 47 | [220.3125], 48 | [24726.5625], 49 | [572920.3125], 50 | [204441.50390625], 51 | [1627.44140625], 52 | [6094.62890625], 53 | [10162.5], 54 | [693.75], 55 | [160537.5], 56 | [160.25390625], 57 | [70130.56640625], 58 | [954882.12890625], 59 | [94270.3125], 60 | [201.5625], 61 | [24820.3125], 62 | [1721.19140625], 63 | [6075.87890625], 64 | [318961.81640625], 65 | [900.], 66 | [160631.25], 67 | [1502175.], 68 | [94176.5625], 69 | [107.8125], 70 | [24726.5625], 71 | [1627.44140625], 72 | [5982.12890625], 73 | [318868.06640625], 74 | [806.25], 75 | [160537.5], 76 | [1502081.25], 77 | [35996.19140625], 78 | [47.75390625], 79 | [70130.56640625], 80 | [89.0625], 81 | [24595.3125], 82 | [572789.0625], 83 | [6075.87890625], 84 | [318849.31640625], 85 | [2256404.00390625], 86 | [10256.25], 87 | [787.5], 88 | [160631.25], 89 | [141.50390625], 90 | [70111.81640625], 91 | [954863.37890625], 92 | [24801.5625], 93 | [572882.8125], 94 | [3264651.5625], 95 | [10275.], 96 | [806.25], 97 | [160650.], 98 | [160.25390625], 99 | [70130.56640625], 100 | [954882.12890625], 101 | [24820.3125], 102 | [572901.5625], 103 | [3264670.3125], 104 | [1721.19140625], 105 | [6075.87890625], 106 | [318961.81640625], 107 | [787.5], 108 | [160518.75], 109 | [1502062.5], 110 | [70224.31640625], 111 | [954863.37890625], 112 | [4578033.69140625], 113 | [295.3125], 114 | [24801.5625], 115 | [572995.3125], 116 | [6169.62890625], 117 | [318943.06640625], 118 | [2256497.75390625], 119 | [160725.], 120 | [1502156.25], 121 | [6252900.], 122 | ]) 123 | outputs = obj_fun.output(grids) 124 | 125 | print(grids) 126 | print(outputs) 127 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 128 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 129 | 130 | def test_call(): 131 | obj_fun = class_fun(2) 132 | bounds = obj_fun.get_bounds() 133 | 134 | grids = obj_fun.sample_grids(3) 135 | truths_grids = np.array([ 136 | [3270.3125], 137 | [243.06640625], 138 | [125.], 139 | [31.25], 140 | [224.31640625], 141 | [3326.5625], 142 | [3345.3125], 143 | [16250.87890625], 144 | [51050.], 145 | ]) 146 | outputs = obj_fun(grids) 147 | 148 | print(grids) 149 | print(outputs) 150 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 151 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 152 | 153 | def test_output_constant_noise(): 154 | obj_fun = class_fun(2) 155 | bounds = obj_fun.get_bounds() 156 | 157 | grids = obj_fun.sample_grids(3) 158 | truths_grids = np.array([ 159 | [3.27231250e+03], 160 | [2.45066406e+02], 161 | [1.27000000e+02], 162 | [3.32500000e+01], 163 | [2.26316406e+02], 164 | [3.32856250e+03], 165 | [3.34731250e+03], 166 | [1.62528789e+04], 167 | [5.10520000e+04], 168 | ]) 169 | 170 | print(grids) 171 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 172 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 173 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 174 | 175 | def test_output_gaussian_noise(): 176 | obj_fun = class_fun(4, seed=SEED) 177 | bounds = obj_fun.get_bounds() 178 | 179 | grids = obj_fun.sample_grids(3) 180 | truths_grids = np.array([ 181 | [391350.99342831], 182 | [10180.9734714], 183 | [826.29537708], 184 | [36017.98746596], 185 | [66.0355995], 186 | [70148.84813234], 187 | [223.47092563], 188 | [24728.09736946], 189 | [572919.37355123], 190 | [204442.58902634], 191 | [1626.51457086], 192 | [6093.69744674], 193 | [10162.98392454], 194 | [689.92343951], 195 | [160534.05016433], 196 | [159.12933119], 197 | [70128.54074401], 198 | [954882.75740092], 199 | [94268.49645185], 200 | [198.7378926], 201 | [24823.24379754], 202 | [1720.73985365], 203 | [6076.01396266], 204 | [318958.96690988], 205 | [898.91123455], 206 | [160631.47184518], 207 | [1502172.69801285], 208 | [94177.31389604], 209 | [106.61122262], 210 | [24725.9791125], 211 | [1626.23799303], 212 | [5985.83346262], 213 | [318868.0394118], 214 | [804.13457814], 215 | [160539.14508982], 216 | [1502078.8083127], 217 | [35996.60913344], 218 | [43.834566], 219 | [70127.91003415], 220 | [89.45622247], 221 | [24596.78943316], 222 | [572789.40523656], 223 | [6075.64760969], 224 | [318848.71419886], 225 | [2256401.04686227], 226 | [10254.81031158], 227 | [786.57872246], 228 | [160633.36424445], 229 | [142.19114283], 230 | [70108.29032594], 231 | [954864.02707419], 232 | [24800.79233544], 233 | [572881.458656], 234 | [3264652.78585258], 235 | [10277.06199904], 236 | [808.11256024], 237 | [160648.32156495], 238 | [159.6354815], 239 | [70131.22893311], 240 | [954884.0799965], 241 | [24819.35415152], 242 | [572901.19118205], 243 | [3264668.09983005], 244 | [1718.798993], 245 | [6077.50395789], 246 | [318964.52888631], 247 | [787.35597976], 248 | [160520.7570658], 249 | [1502063.22327205], 250 | [70223.02616674], 251 | [954864.10169746], 252 | [4578036.76747938], 253 | [295.24084792], 254 | [24804.69178731], 255 | [572990.07300979], 256 | [6171.27271126], 257 | [318943.24050039], 258 | [2256497.15589155], 259 | [160725.18352155], 260 | [1502152.27486217], 261 | [6252899.56065622], 262 | ]) 263 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 264 | 265 | print(grids) 266 | print(outputs) 267 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 268 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 269 | 270 | def test_output_sparse_gaussian_noise(): 271 | obj_fun = class_fun(4, seed=SEED) 272 | bounds = obj_fun.get_bounds() 273 | 274 | grids = obj_fun.sample_grids(3) 275 | truths_grids = np.array([ 276 | [391350.], 277 | [10181.25], 278 | [826.29537708], 279 | [36017.98746596], 280 | [66.0355995], 281 | [70148.84813234], 282 | [220.3125], 283 | [24726.5625], 284 | [572920.3125], 285 | [204441.50390625], 286 | [1627.44140625], 287 | [6093.69744674], 288 | [10162.5], 289 | [693.75], 290 | [160537.5], 291 | [160.25390625], 292 | [70130.56640625], 293 | [954882.75740092], 294 | [94268.49645185], 295 | [201.5625], 296 | [24820.3125], 297 | [1721.19140625], 298 | [6076.01396266], 299 | [318961.81640625], 300 | [900.], 301 | [160631.47184518], 302 | [1502172.69801285], 303 | [94176.5625], 304 | [107.8125], 305 | [24726.5625], 306 | [1627.44140625], 307 | [5982.12890625], 308 | [318868.06640625], 309 | [806.25], 310 | [160537.5], 311 | [1502078.8083127], 312 | [35996.19140625], 313 | [47.75390625], 314 | [70127.91003415], 315 | [89.45622247], 316 | [24595.3125], 317 | [572789.0625], 318 | [6075.64760969], 319 | [318848.71419886], 320 | [2256404.00390625], 321 | [10254.81031158], 322 | [786.57872246], 323 | [160631.25], 324 | [141.50390625], 325 | [70108.29032594], 326 | [954863.37890625], 327 | [24801.5625], 328 | [572881.458656], 329 | [3264651.5625], 330 | [10275.], 331 | [806.25], 332 | [160650.], 333 | [160.25390625], 334 | [70131.22893311], 335 | [954882.12890625], 336 | [24820.3125], 337 | [572901.19118205], 338 | [3264668.09983005], 339 | [1721.19140625], 340 | [6075.87890625], 341 | [318964.52888631], 342 | [787.5], 343 | [160520.7570658], 344 | [1502062.5], 345 | [70223.02616674], 346 | [954863.37890625], 347 | [4578033.69140625], 348 | [295.3125], 349 | [24804.69178731], 350 | [572995.3125], 351 | [6171.27271126], 352 | [318943.06640625], 353 | [2256497.75390625], 354 | [160725.18352155], 355 | [1502156.25], 356 | [6252900.], 357 | ]) 358 | outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) 359 | 360 | print(grids) 361 | print(outputs) 362 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 363 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 364 | 365 | def test_output_student_t_noise(): 366 | obj_fun = class_fun(1, seed=SEED) 367 | bounds = obj_fun.get_bounds() 368 | 369 | grids = obj_fun.sample_grids(3) 370 | truths_grids = np.array([ 371 | [71.4617346], 372 | [8.09052578], 373 | [752.63811703], 374 | ]) 375 | outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) 376 | 377 | print(grids) 378 | print(outputs) 379 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 380 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 381 | 382 | def test_output_sparse_student_t_noise(): 383 | obj_fun = class_fun(2, seed=SEED) 384 | bounds = obj_fun.get_bounds() 385 | 386 | grids = obj_fun.sample_grids(3) 387 | truths_grids = np.array([ 388 | [3271.4617346], 389 | [240.90302578], 390 | [125.], 391 | [31.25], 392 | [224.31640625], 393 | [3326.5625], 394 | [3341.38420756], 395 | [16250.87890625], 396 | [51050.], 397 | ]) 398 | outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) 399 | 400 | print(grids) 401 | print(outputs) 402 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 403 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 404 | 405 | def test_name(): 406 | obj_fun = class_fun(2) 407 | assert obj_fun.name == str_name + '_2' 408 | 409 | obj_fun = class_fun(4) 410 | assert obj_fun.name == str_name + '_4' 411 | 412 | obj_fun = class_fun(16) 413 | assert obj_fun.name == str_name + '_16' 414 | 415 | assert obj_fun.__class__.__name__.lower() == str_name 416 | assert obj_fun.__class__.__qualname__.lower() == str_name 417 | -------------------------------------------------------------------------------- /tests/test_one_dim_constant.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.one_dim_constant import * 10 | 11 | class_fun = Constant 12 | str_name = 'constant' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | bounds = np.array([[0.0, 10.0]]) 19 | obj_fun = class_fun() 20 | obj_fun = class_fun(bounds=bounds, constant=2.0) 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(bounds=2) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(bounds=np.array([0.0, 10.0])) 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(bounds=[0.0, 10.0]) 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(bounds=np.array([[10.0, 0.0]])) 30 | with pytest.raises(AssertionError) as error: 31 | class_fun(constant=2) 32 | with pytest.raises(AssertionError) as error: 33 | class_fun(constant='abc') 34 | with pytest.raises(AssertionError) as error: 35 | class_fun(seed='abc') 36 | with pytest.raises(AssertionError) as error: 37 | class_fun(seed=2.1) 38 | 39 | def test_validate_properties(): 40 | obj_fun = class_fun() 41 | obj_fun.validate_properties() 42 | 43 | def test_output(): 44 | obj_fun = class_fun() 45 | bounds = obj_fun.get_bounds() 46 | 47 | grids = obj_fun.sample_grids(3) 48 | truths_grids = np.array([ 49 | [0.0], 50 | [0.0], 51 | [0.0], 52 | ]) 53 | 54 | print(grids) 55 | print(obj_fun.output(grids)) 56 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 57 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 58 | 59 | def test_call(): 60 | obj_fun = class_fun() 61 | bounds = obj_fun.get_bounds() 62 | 63 | grids = obj_fun.sample_grids(3) 64 | truths_grids = np.array([ 65 | [0.0], 66 | [0.0], 67 | [0.0], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun(grids)) 72 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_name(): 76 | obj_fun = class_fun() 77 | assert obj_fun.name == str_name 78 | 79 | assert obj_fun.__class__.__name__.lower() == str_name 80 | assert obj_fun.__class__.__qualname__.lower() == str_name 81 | -------------------------------------------------------------------------------- /tests/test_one_dim_gramacyandlee2012.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.one_dim_gramacyandlee2012 import * 10 | 11 | class_fun = GramacyAndLee2012 12 | str_name = 'gramacyandlee2012' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [0.0625], 36 | [0.0625], 37 | [5.0625], 38 | ]) 39 | 40 | print(grids) 41 | print(obj_fun.output(grids)) 42 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 43 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 44 | 45 | def test_name(): 46 | obj_fun = class_fun() 47 | assert obj_fun.name == str_name 48 | 49 | assert obj_fun.__class__.__name__.lower() == str_name 50 | assert obj_fun.__class__.__qualname__.lower() == str_name 51 | -------------------------------------------------------------------------------- /tests/test_one_dim_linear.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.one_dim_linear import * 10 | 11 | class_fun = Linear 12 | str_name = 'linear' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | bounds = np.array([[0.0, 10.0]]) 19 | obj_fun = class_fun() 20 | obj_fun = class_fun(bounds=bounds, slope=2.0) 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(bounds=2) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(bounds=np.array([0.0, 10.0])) 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(bounds=[0.0, 10.0]) 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(bounds=np.array([[10.0, 0.0]])) 30 | with pytest.raises(AssertionError) as error: 31 | class_fun(slope=2) 32 | with pytest.raises(AssertionError) as error: 33 | class_fun(slope='abc') 34 | with pytest.raises(AssertionError) as error: 35 | class_fun(seed='abc') 36 | with pytest.raises(AssertionError) as error: 37 | class_fun(seed=2.1) 38 | 39 | def test_validate_properties(): 40 | obj_fun = class_fun() 41 | obj_fun.validate_properties() 42 | 43 | obj_fun = class_fun(bounds=np.array([[2.0, 10.0]]), slope=2.0) 44 | obj_fun.validate_properties() 45 | 46 | obj_fun = class_fun(bounds=np.array([[2.0, 10.0]]), slope=-2.0) 47 | obj_fun.validate_properties() 48 | 49 | obj_fun = class_fun(bounds=np.array([[-10.0, 2.0]]), slope=2.0) 50 | obj_fun.validate_properties() 51 | 52 | obj_fun = class_fun(bounds=np.array([[-10.0, 2.0]]), slope=-2.0) 53 | obj_fun.validate_properties() 54 | 55 | def test_output(): 56 | obj_fun = class_fun() 57 | bounds = obj_fun.get_bounds() 58 | 59 | grids = obj_fun.sample_grids(3) 60 | truths_grids = np.array([ 61 | [-10.0], 62 | [0.0], 63 | [10.0], 64 | ]) 65 | 66 | print(grids) 67 | print(obj_fun.output(grids)) 68 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 69 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 70 | 71 | def test_name(): 72 | obj_fun = class_fun() 73 | assert obj_fun.name == str_name 74 | 75 | assert obj_fun.__class__.__name__.lower() == str_name 76 | assert obj_fun.__class__.__qualname__.lower() == str_name 77 | -------------------------------------------------------------------------------- /tests/test_one_dim_step.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.one_dim_step import * 10 | 11 | class_fun = Step 12 | str_name = 'step' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | obj_fun = class_fun(steps=[-5., -3., 0., 1.], step_values=[4., 3., -1.]) 20 | 21 | with pytest.raises(AssertionError) as error: 22 | class_fun(steps='abc') 23 | with pytest.raises(AssertionError) as error: 24 | class_fun(step_values='abc') 25 | with pytest.raises(AssertionError) as error: 26 | class_fun(steps=[1., 2., 3., 4.], step_values=[1., 2., 3., 4.]) 27 | with pytest.raises(AssertionError) as error: 28 | class_fun(steps=[1, 2, 3, 4], step_values=[1., 2., 3.]) 29 | with pytest.raises(AssertionError) as error: 30 | class_fun(steps=[1., 2., 3., 4.], step_values=[1, 2, 3]) 31 | with pytest.raises(AssertionError) as error: 32 | class_fun(steps=[1., 2., 5., 3.], step_values=[1., 2., 3.]) 33 | with pytest.raises(AssertionError) as error: 34 | class_fun(seed='abc') 35 | with pytest.raises(AssertionError) as error: 36 | class_fun(seed=2.1) 37 | 38 | def test_validate_properties(): 39 | obj_fun = class_fun() 40 | obj_fun.validate_properties() 41 | 42 | def test_output(): 43 | obj_fun = class_fun() 44 | bounds = obj_fun.get_bounds() 45 | 46 | grids = obj_fun.sample_grids(5) 47 | truths_grids = np.array([ 48 | [-2.0], 49 | [0.0], 50 | [1.0], 51 | [-1.0], 52 | [-1.0], 53 | ]) 54 | 55 | print(grids) 56 | print(obj_fun.output(grids)) 57 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 58 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 59 | 60 | def test_name(): 61 | obj_fun = class_fun() 62 | assert obj_fun.name == str_name 63 | 64 | assert obj_fun.__class__.__name__.lower() == str_name 65 | assert obj_fun.__class__.__qualname__.lower() == str_name 66 | -------------------------------------------------------------------------------- /tests/test_three_dim_hartmann3d.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.three_dim_hartmann3d import * 10 | 11 | class_fun = Hartmann3D 12 | str_name = 'hartmann3d' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [-6.79741166e-02], 36 | [-1.36461045e-01], 37 | [-9.13324430e-02], 38 | [-9.71082067e-02], 39 | [-1.85406663e-01], 40 | [-9.02038776e-02], 41 | [-3.09547170e-02], 42 | [-7.29043824e-02], 43 | [-8.47693855e-02], 44 | [-1.80480228e-02], 45 | [-8.39060933e-01], 46 | [-1.99426284e+00], 47 | [-2.57290548e-02], 48 | [-6.28022015e-01], 49 | [-1.95703928e+00], 50 | [-8.19356834e-03], 51 | [-2.25915245e-01], 52 | [-1.82665019e+00], 53 | [-2.73536768e-04], 54 | [-2.26230774e+00], 55 | [-3.34829168e-01], 56 | [-2.04016877e-04], 57 | [-1.48565839e+00], 58 | [-3.25957854e-01], 59 | [-3.77271851e-05], 60 | [-2.24631259e-01], 61 | [-3.00476074e-01], 62 | ]) 63 | 64 | print(grids) 65 | print(obj_fun.output(grids)) 66 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 67 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 68 | 69 | def test_call(): 70 | obj_fun = class_fun() 71 | bounds = obj_fun.get_bounds() 72 | 73 | grids = obj_fun.sample_grids(3) 74 | truths_grids = np.array([ 75 | [-6.79741166e-02], 76 | [-1.36461045e-01], 77 | [-9.13324430e-02], 78 | [-9.71082067e-02], 79 | [-1.85406663e-01], 80 | [-9.02038776e-02], 81 | [-3.09547170e-02], 82 | [-7.29043824e-02], 83 | [-8.47693855e-02], 84 | [-1.80480228e-02], 85 | [-8.39060933e-01], 86 | [-1.99426284e+00], 87 | [-2.57290548e-02], 88 | [-6.28022015e-01], 89 | [-1.95703928e+00], 90 | [-8.19356834e-03], 91 | [-2.25915245e-01], 92 | [-1.82665019e+00], 93 | [-2.73536768e-04], 94 | [-2.26230774e+00], 95 | [-3.34829168e-01], 96 | [-2.04016877e-04], 97 | [-1.48565839e+00], 98 | [-3.25957854e-01], 99 | [-3.77271851e-05], 100 | [-2.24631259e-01], 101 | [-3.00476074e-01], 102 | ]) 103 | 104 | print(grids) 105 | print(obj_fun(grids)) 106 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 107 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 108 | 109 | def test_name(): 110 | obj_fun = class_fun() 111 | assert obj_fun.name == str_name 112 | 113 | assert obj_fun.__class__.__name__.lower() == str_name 114 | assert obj_fun.__class__.__qualname__.lower() == str_name 115 | -------------------------------------------------------------------------------- /tests/test_two_dim_beale.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_beale import * 10 | 11 | class_fun = Beale 12 | str_name = 'beale' 13 | 14 | TEST_EPSILON = 1e-3 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [1.81853613e+05], 36 | [1.42031250e+01], 37 | [1.78131832e+05], 38 | [1.32328125e+02], 39 | [1.42031250e+01], 40 | [1.75781250e+01], 41 | [1.69680832e+05], 42 | [1.42031250e+01], 43 | [1.74813363e+05], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_bohachevsky.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_bohachevsky import * 10 | 11 | class_fun = Bohachevsky 12 | str_name = 'bohachevsky' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [30000.], 36 | [20000.], 37 | [30000.], 38 | [10000.], 39 | [0.], 40 | [10000.], 41 | [30000.], 42 | [20000.], 43 | [30000.], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_branin.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_branin import * 10 | 11 | class_fun = Branin 12 | str_name = 'branin' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(a='abc') 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(b='abc') 26 | with pytest.raises(AssertionError) as error: 27 | class_fun(c='abc') 28 | with pytest.raises(AssertionError) as error: 29 | class_fun(r='abc') 30 | with pytest.raises(AssertionError) as error: 31 | class_fun(s='abc') 32 | with pytest.raises(AssertionError) as error: 33 | class_fun(t='abc') 34 | with pytest.raises(AssertionError) as error: 35 | class_fun(seed=1.0) 36 | with pytest.raises(AssertionError) as error: 37 | class_fun(seed='abc') 38 | 39 | def test_validate_properties(): 40 | obj_fun = class_fun() 41 | obj_fun.validate_properties() 42 | 43 | def test_output(): 44 | obj_fun = class_fun() 45 | bounds = obj_fun.get_bounds() 46 | 47 | grids = obj_fun.sample_grids(3) 48 | truths_grids = np.array([ 49 | [308.12909601], 50 | [10.30790849], 51 | [10.96088904], 52 | [106.56869776], 53 | [24.12996441], 54 | [22.16653996], 55 | [17.50829952], 56 | [150.45202034], 57 | [145.87219088], 58 | ]) 59 | 60 | print(grids) 61 | print(obj_fun.output(grids)) 62 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 63 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 64 | 65 | def test_call(): 66 | obj_fun = class_fun() 67 | bounds = obj_fun.get_bounds() 68 | 69 | grids = obj_fun.sample_grids(3) 70 | truths_grids = np.array([ 71 | [308.12909601], 72 | [10.30790849], 73 | [10.96088904], 74 | [106.56869776], 75 | [24.12996441], 76 | [22.16653996], 77 | [17.50829952], 78 | [150.45202034], 79 | [145.87219088], 80 | ]) 81 | 82 | print(grids) 83 | print(obj_fun(grids)) 84 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 85 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 86 | 87 | def test_output_constant_noise(): 88 | obj_fun = class_fun() 89 | bounds = obj_fun.get_bounds() 90 | 91 | grids = obj_fun.sample_grids(3) 92 | truths_grids = np.array([ 93 | [308.12909601], 94 | [10.30790849], 95 | [10.96088904], 96 | [106.56869776], 97 | [24.12996441], 98 | [22.16653996], 99 | [17.50829952], 100 | [150.45202034], 101 | [145.87219088], 102 | ]) 103 | 104 | print(grids) 105 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 106 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 107 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 108 | 109 | def test_output_gaussian_noise(): 110 | obj_fun = class_fun(seed=SEED) 111 | bounds = obj_fun.get_bounds() 112 | 113 | grids = obj_fun.sample_grids(3) 114 | truths_grids = np.array([ 115 | [309.12252432], 116 | [10.03137988], 117 | [12.25626611], 118 | [109.61475748], 119 | [23.66165766], 120 | [21.69826604], 121 | [20.66672515], 122 | [151.9868898], 123 | [144.93324211], 124 | ]) 125 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 126 | 127 | print(grids) 128 | print(outputs) 129 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 130 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 131 | 132 | def test_output_sparse_gaussian_noise(): 133 | obj_fun = class_fun(seed=SEED) 134 | bounds = obj_fun.get_bounds() 135 | 136 | grids = obj_fun.sample_grids(3) 137 | truths_grids = np.array([ 138 | [309.12252432], 139 | [10.03137988], 140 | [10.96088904], 141 | [106.56869776], 142 | [24.12996441], 143 | [21.69826604], 144 | [17.50829952], 145 | [151.9868898], 146 | [144.93324211], 147 | ]) 148 | outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) 149 | 150 | print(grids) 151 | print(outputs) 152 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 153 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 154 | 155 | def test_output_student_t_noise(): 156 | obj_fun = class_fun(seed=SEED) 157 | bounds = obj_fun.get_bounds() 158 | 159 | grids = obj_fun.sample_grids(3) 160 | truths_grids = np.array([ 161 | [309.27833061], 162 | [8.14452801], 163 | [13.59900607], 164 | [104.98514624], 165 | [25.60278992], 166 | [25.95324732], 167 | [13.58000707], 168 | [149.34002319], 169 | [144.72897096], 170 | ]) 171 | outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) 172 | 173 | print(grids) 174 | print(outputs) 175 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 176 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 177 | 178 | def test_output_sparse_student_t_noise(): 179 | obj_fun = class_fun(seed=SEED) 180 | bounds = obj_fun.get_bounds() 181 | 182 | grids = obj_fun.sample_grids(3) 183 | truths_grids = np.array([ 184 | [309.27833061], 185 | [8.14452801], 186 | [10.96088904], 187 | [106.56869776], 188 | [24.12996441], 189 | [22.16653996], 190 | [13.58000707], 191 | [150.45202034], 192 | [145.87219088], 193 | ]) 194 | outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) 195 | 196 | print(grids) 197 | print(outputs) 198 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 199 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 200 | 201 | def test_name(): 202 | obj_fun = class_fun() 203 | assert obj_fun.name == str_name 204 | 205 | assert obj_fun.__class__.__name__.lower() == str_name 206 | assert obj_fun.__class__.__qualname__.lower() == str_name 207 | -------------------------------------------------------------------------------- /tests/test_two_dim_bukin6.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 6, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_bukin6 import * 10 | 11 | class_fun = Bukin6 12 | str_name = 'bukin6' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(seed='abc') 26 | 27 | def test_validate_properties(): 28 | obj_fun = class_fun() 29 | obj_fun.validate_properties() 30 | 31 | def test_output(): 32 | obj_fun = class_fun() 33 | bounds = obj_fun.get_bounds() 34 | 35 | grids = obj_fun.sample_grids(3) 36 | truths_grids = np.array([ 37 | [229.17878475], 38 | [200.0], 39 | [180.32756377], 40 | [150.05], 41 | [100.0], 42 | [50.05], 43 | [86.65254038], 44 | [141.42135624], 45 | [165.88123952], 46 | ]) 47 | 48 | print(grids) 49 | print(obj_fun.output(grids)) 50 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 51 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 52 | 53 | def test_call(): 54 | obj_fun = class_fun() 55 | bounds = obj_fun.get_bounds() 56 | 57 | grids = obj_fun.sample_grids(3) 58 | truths_grids = np.array([ 59 | [229.17878475], 60 | [200.0], 61 | [180.32756377], 62 | [150.05], 63 | [100.0], 64 | [50.05], 65 | [86.65254038], 66 | [141.42135624], 67 | [165.88123952], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun(grids)) 72 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_output_constant_noise(): 76 | obj_fun = class_fun() 77 | bounds = obj_fun.get_bounds() 78 | 79 | grids = obj_fun.sample_grids(3) 80 | truths_grids = np.array([ 81 | [231.17878475], 82 | [202.0], 83 | [182.32756377], 84 | [152.05], 85 | [102.0], 86 | [52.05], 87 | [88.65254038], 88 | [143.42135624], 89 | [167.88123952], 90 | ]) 91 | 92 | print(grids) 93 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 94 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 95 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 96 | 97 | def test_output_gaussian_noise(): 98 | obj_fun = class_fun(seed=SEED) 99 | bounds = obj_fun.get_bounds() 100 | 101 | grids = obj_fun.sample_grids(3) 102 | truths_grids = np.array([ 103 | [230.17221305], 104 | [199.7234714], 105 | [181.62294085], 106 | [153.09605971], 107 | [99.53169325], 108 | [49.58172609], 109 | [89.81096601], 110 | [142.9562257], 111 | [164.94229075], 112 | ]) 113 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 114 | 115 | print(grids) 116 | print(outputs) 117 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 118 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 119 | 120 | def test_output_sparse_gaussian_noise(): 121 | obj_fun = class_fun(seed=SEED) 122 | bounds = obj_fun.get_bounds() 123 | 124 | grids = obj_fun.sample_grids(3) 125 | truths_grids = np.array([ 126 | [230.17221305], 127 | [199.7234714], 128 | [180.32756377], 129 | [150.05], 130 | [100.0], 131 | [49.58172609], 132 | [86.65254038], 133 | [142.9562257 ], 134 | [164.94229075], 135 | ]) 136 | outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) 137 | 138 | print(grids) 139 | print(outputs) 140 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 141 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 142 | 143 | def test_output_student_t_noise(): 144 | obj_fun = class_fun(seed=SEED) 145 | bounds = obj_fun.get_bounds() 146 | 147 | grids = obj_fun.sample_grids(3) 148 | truths_grids = np.array([ 149 | [230.32801935], 150 | [197.83661953], 151 | [182.96568081], 152 | [148.46644847], 153 | [101.4728255], 154 | [53.83670737], 155 | [82.72424794], 156 | [140.30935909], 157 | [164.7380196], 158 | ]) 159 | outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) 160 | 161 | print(grids) 162 | print(outputs) 163 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 164 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 165 | 166 | def test_output_sparse_student_t_noise(): 167 | obj_fun = class_fun(seed=SEED) 168 | bounds = obj_fun.get_bounds() 169 | 170 | grids = obj_fun.sample_grids(3) 171 | truths_grids = np.array([ 172 | [230.32801935], 173 | [197.83661953], 174 | [180.32756377], 175 | [150.05], 176 | [100.0], 177 | [50.05], 178 | [82.72424794], 179 | [141.42135624], 180 | [165.88123952], 181 | ]) 182 | outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) 183 | 184 | print(grids) 185 | print(outputs) 186 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 187 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 188 | 189 | def test_name(): 190 | obj_fun = class_fun() 191 | assert obj_fun.name == str_name 192 | 193 | assert obj_fun.__class__.__name__.lower() == str_name 194 | assert obj_fun.__class__.__qualname__.lower() == str_name 195 | -------------------------------------------------------------------------------- /tests/test_two_dim_dejong5.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_dejong5 import * 10 | 11 | class_fun = DeJong5 12 | str_name = 'dejong5' 13 | 14 | TEST_EPSILON = 1e-3 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [499.99985236], 36 | [499.99917292], 37 | [499.99985236], 38 | [499.99917292], 39 | [12.67050581], 40 | [499.99917292], 41 | [499.99985236], 42 | [499.99917292], 43 | [499.99985236], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_dropwave.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_dropwave import * 10 | 11 | class_fun = DropWave 12 | str_name = 'dropwave' 13 | 14 | TEST_EPSILON = 1e-3 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [-0.05229446], 36 | [-0.07797539], 37 | [-0.05229446], 38 | [-0.07797539], 39 | [-1.0], 40 | [-0.07797539], 41 | [-0.05229446], 42 | [-0.07797539], 43 | [-0.05229446], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_easom.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 3, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_easom import * 10 | 11 | class_fun = Easom 12 | str_name = 'easom' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(seed='abc') 26 | 27 | def test_validate_properties(): 28 | obj_fun = class_fun() 29 | obj_fun.validate_properties() 30 | 31 | def test_output(): 32 | obj_fun = class_fun() 33 | bounds = obj_fun.get_bounds() 34 | 35 | grids = obj_fun.sample_grids(3) 36 | truths_grids = np.array([ 37 | [0.0], 38 | [0.0], 39 | [0.0], 40 | [0.0], 41 | [-2.67528799e-09], 42 | [0.0], 43 | [0.0], 44 | [0.0], 45 | [0.0], 46 | ]) 47 | 48 | print(grids) 49 | print(obj_fun.output(grids)) 50 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 51 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 52 | 53 | def test_call(): 54 | obj_fun = class_fun() 55 | bounds = obj_fun.get_bounds() 56 | 57 | grids = obj_fun.sample_grids(3) 58 | truths_grids = np.array([ 59 | [0.0], 60 | [0.0], 61 | [0.0], 62 | [0.0], 63 | [-2.67528799e-09], 64 | [0.0], 65 | [0.0], 66 | [0.0], 67 | [0.0], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun(grids)) 72 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_output_constant_noise(): 76 | obj_fun = class_fun() 77 | bounds = obj_fun.get_bounds() 78 | 79 | grids = obj_fun.sample_grids(3) 80 | truths_grids = np.array([ 81 | [2.0], 82 | [2.0], 83 | [2.0], 84 | [2.0], 85 | [2.0], 86 | [2.0], 87 | [2.0], 88 | [2.0], 89 | [2.0], 90 | ]) 91 | 92 | print(grids) 93 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 94 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 95 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 96 | 97 | def test_output_gaussian_noise(): 98 | obj_fun = class_fun(seed=SEED) 99 | bounds = obj_fun.get_bounds() 100 | 101 | grids = obj_fun.sample_grids(3) 102 | truths_grids = np.array([ 103 | [0.99342831], 104 | [-0.2765286], 105 | [1.29537708], 106 | [3.04605971], 107 | [-0.46830675], 108 | [-0.46827391], 109 | [3.15842563], 110 | [1.53486946], 111 | [-0.93894877], 112 | ]) 113 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 114 | 115 | print(grids) 116 | print(outputs) 117 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 118 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 119 | 120 | def test_output_sparse_gaussian_noise(): 121 | obj_fun = class_fun(seed=SEED) 122 | bounds = obj_fun.get_bounds() 123 | 124 | grids = obj_fun.sample_grids(3) 125 | truths_grids = np.array([ 126 | [9.93428306e-01], 127 | [-2.76528602e-01], 128 | [0.0], 129 | [0.0], 130 | [-2.67528799e-09], 131 | [-4.68273914e-01], 132 | [0.0], 133 | [1.53486946], 134 | [-9.38948772e-01], 135 | ]) 136 | outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) 137 | 138 | print(grids) 139 | print(outputs) 140 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 141 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 142 | 143 | def test_output_student_t_noise(): 144 | obj_fun = class_fun(seed=SEED) 145 | bounds = obj_fun.get_bounds() 146 | 147 | grids = obj_fun.sample_grids(3) 148 | truths_grids = np.array([ 149 | [1.1492346], 150 | [-2.16338047], 151 | [2.63811703], 152 | [-1.58355153], 153 | [1.4728255], 154 | [3.78670737], 155 | [-3.92829244], 156 | [-1.11199715], 157 | [-1.14321992], 158 | ]) 159 | outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) 160 | 161 | print(grids) 162 | print(outputs) 163 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 164 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 165 | 166 | def test_output_sparse_student_t_noise(): 167 | obj_fun = class_fun(seed=SEED) 168 | bounds = obj_fun.get_bounds() 169 | 170 | grids = obj_fun.sample_grids(3) 171 | truths_grids = np.array([ 172 | [1.14923460], 173 | [-2.16338047], 174 | [0.0], 175 | [0.0], 176 | [-2.67528799e-09], 177 | [0.0], 178 | [-3.92829244], 179 | [0.0], 180 | [0.0], 181 | ]) 182 | outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) 183 | 184 | print(grids) 185 | print(outputs) 186 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 187 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 188 | 189 | def test_name(): 190 | obj_fun = class_fun() 191 | assert obj_fun.name == str_name 192 | 193 | assert obj_fun.__class__.__name__.lower() == str_name 194 | assert obj_fun.__class__.__qualname__.lower() == str_name 195 | -------------------------------------------------------------------------------- /tests/test_two_dim_eggholder.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 13, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_eggholder import * 10 | 11 | class_fun = Eggholder 12 | str_name = 'eggholder' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [737.27824186], 36 | [192.69874664], 37 | [522.47207216], 38 | [-554.93052378], 39 | [-25.46033719], 40 | [-165.56113678], 41 | [1049.1316235], 42 | [557.15651626], 43 | [-126.16793738], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_goldsteinprice.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_goldsteinprice import * 10 | 11 | class_fun = GoldsteinPrice 12 | str_name = 'goldsteinprice' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [2.43760e+04], 36 | [6.66000e+04], 37 | [3.16600e+05], 38 | [1.26600e+05], 39 | [6.00000e+02], 40 | [1.73600e+03], 41 | [9.56600e+05], 42 | [2.24616e+05], 43 | [7.67280e+04], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_holdertable.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_holdertable import * 10 | 11 | class_fun = HolderTable 12 | str_name = 'holdertable' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [-15.14022386], 36 | [0.], 37 | [-15.14022386], 38 | [-4.827514], 39 | [-0.], 40 | [-4.827514], 41 | [-15.14022386], 42 | [0.], 43 | [-15.14022386], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_kim1.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_kim1 import * 10 | 11 | class_fun = Kim1 12 | str_name = 'kim1' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(seed='abc') 26 | 27 | def test_validate_properties(): 28 | obj_fun = class_fun() 29 | obj_fun.validate_properties() 30 | 31 | def test_output(): 32 | obj_fun = class_fun() 33 | bounds = obj_fun.get_bounds() 34 | 35 | grids = obj_fun.sample_grids(3) 36 | truths_grids = np.array([ 37 | [9.91424384], 38 | [2.97034052], 39 | [4.2184372], 40 | [8.54390332], 41 | [1.6], 42 | [2.84809668], 43 | [7.35424384], 44 | [0.41034052], 45 | [1.6584372], 46 | ]) 47 | 48 | for elem in obj_fun.output(grids): 49 | print('{},'.format(elem)) 50 | 51 | print(grids) 52 | print(obj_fun.output(grids)) 53 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 54 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 55 | 56 | def test_output_constant_noise(): 57 | obj_fun = class_fun() 58 | bounds = obj_fun.get_bounds() 59 | 60 | grids = obj_fun.sample_grids(3) 61 | truths_grids = np.array([ 62 | [11.91424384], 63 | [4.97034052], 64 | [6.2184372], 65 | [10.54390332], 66 | [3.6], 67 | [4.84809668], 68 | [9.35424384], 69 | [2.41034052], 70 | [3.6584372], 71 | ]) 72 | 73 | for elem in obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE): 74 | print('{},'.format(elem)) 75 | 76 | print(grids) 77 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 78 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 79 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 80 | 81 | def test_output_gaussian_noise(): 82 | obj_fun = class_fun(seed=SEED) 83 | bounds = obj_fun.get_bounds() 84 | 85 | grids = obj_fun.sample_grids(3) 86 | truths_grids = np.array([ 87 | [10.90767214], 88 | [2.69381192], 89 | [5.51381428], 90 | [11.58996303], 91 | [1.13169325], 92 | [2.37982277], 93 | [10.51266947], 94 | [1.94520998], 95 | [0.71948843], 96 | ]) 97 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 98 | 99 | for elem in outputs: 100 | print('{},'.format(elem)) 101 | 102 | print(grids) 103 | print(outputs) 104 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 105 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 106 | 107 | def test_name(): 108 | obj_fun = class_fun() 109 | assert obj_fun.name == str_name 110 | 111 | assert obj_fun.__class__.__name__.lower() == str_name 112 | assert obj_fun.__class__.__qualname__.lower() == str_name 113 | -------------------------------------------------------------------------------- /tests/test_two_dim_kim2.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_kim2 import * 10 | 11 | class_fun = Kim2 12 | str_name = 'kim2' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(seed='abc') 26 | 27 | def test_validate_properties(): 28 | obj_fun = class_fun() 29 | obj_fun.validate_properties() 30 | 31 | def test_output(): 32 | obj_fun = class_fun() 33 | bounds = obj_fun.get_bounds() 34 | 35 | grids = obj_fun.sample_grids(3) 36 | truths_grids = np.array([ 37 | [101.67527989], 38 | [35.75642525], 39 | [74.69517061], 40 | [72.83885464], 41 | [6.92], 42 | [45.85874536], 43 | [85.29127989], 44 | [19.37242525], 45 | [58.31117061], 46 | ]) 47 | 48 | for elem in obj_fun.output(grids): 49 | print('{},'.format(elem)) 50 | 51 | print(grids) 52 | print(obj_fun.output(grids)) 53 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 54 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 55 | 56 | def test_output_constant_noise(): 57 | obj_fun = class_fun() 58 | bounds = obj_fun.get_bounds() 59 | 60 | grids = obj_fun.sample_grids(3) 61 | truths_grids = np.array([ 62 | [103.67527989], 63 | [37.75642525], 64 | [76.69517061], 65 | [74.83885464], 66 | [8.92], 67 | [47.85874536], 68 | [87.29127989], 69 | [21.37242525], 70 | [60.31117061], 71 | ]) 72 | 73 | for elem in obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE): 74 | print('{},'.format(elem)) 75 | 76 | print(grids) 77 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 78 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 79 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 80 | 81 | def test_output_gaussian_noise(): 82 | obj_fun = class_fun(seed=SEED) 83 | bounds = obj_fun.get_bounds() 84 | 85 | grids = obj_fun.sample_grids(3) 86 | truths_grids = np.array([ 87 | [102.6687082], 88 | [35.47989665], 89 | [75.99054769], 90 | [75.88491435], 91 | [6.45169325], 92 | [45.39047145], 93 | [88.44970553], 94 | [20.90729471], 95 | [57.37222184], 96 | ]) 97 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 98 | 99 | for elem in outputs: 100 | print('{},'.format(elem)) 101 | 102 | print(grids) 103 | print(outputs) 104 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 105 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 106 | 107 | def test_name(): 108 | obj_fun = class_fun() 109 | assert obj_fun.name == str_name 110 | 111 | assert obj_fun.__class__.__name__.lower() == str_name 112 | assert obj_fun.__class__.__qualname__.lower() == str_name 113 | -------------------------------------------------------------------------------- /tests/test_two_dim_kim3.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_kim3 import * 10 | 11 | class_fun = Kim3 12 | str_name = 'kim3' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(seed='abc') 26 | 27 | def test_validate_properties(): 28 | obj_fun = class_fun() 29 | obj_fun.validate_properties() 30 | 31 | def test_output(): 32 | obj_fun = class_fun() 33 | bounds = obj_fun.get_bounds() 34 | 35 | grids = obj_fun.sample_grids(3) 36 | truths_grids = np.array([ 37 | [208.90875507], 38 | [72.1885316], 39 | [145.18351361], 40 | [145.56021506], 41 | [8.83995458], 42 | [81.83497908], 43 | [176.14075507], 44 | [39.4205316], 45 | [112.41551361], 46 | ]) 47 | 48 | for elem in obj_fun.output(grids): 49 | print('{},'.format(elem)) 50 | 51 | print(grids) 52 | print(obj_fun.output(grids)) 53 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 54 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 55 | 56 | def test_output_constant_noise(): 57 | obj_fun = class_fun() 58 | bounds = obj_fun.get_bounds() 59 | 60 | grids = obj_fun.sample_grids(3) 61 | truths_grids = np.array([ 62 | [210.90875507], 63 | [74.1885316], 64 | [147.18351361], 65 | [147.56021506], 66 | [10.83995458], 67 | [83.83497908], 68 | [178.14075507], 69 | [41.4205316], 70 | [114.41551361], 71 | ]) 72 | 73 | for elem in obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE): 74 | print('{},'.format(elem)) 75 | 76 | print(grids) 77 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 78 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 79 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 80 | 81 | def test_output_gaussian_noise(): 82 | obj_fun = class_fun(seed=SEED) 83 | bounds = obj_fun.get_bounds() 84 | 85 | grids = obj_fun.sample_grids(3) 86 | truths_grids = np.array([ 87 | [209.90218338], 88 | [71.912003], 89 | [146.47889068], 90 | [148.60627477], 91 | [8.37164783], 92 | [81.36670517], 93 | [179.2991807], 94 | [40.95540106], 95 | [111.47656484], 96 | ]) 97 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 98 | 99 | for elem in outputs: 100 | print('{},'.format(elem)) 101 | 102 | print(grids) 103 | print(outputs) 104 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 105 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 106 | 107 | def test_name(): 108 | obj_fun = class_fun() 109 | assert obj_fun.name == str_name 110 | 111 | assert obj_fun.__class__.__name__.lower() == str_name 112 | assert obj_fun.__class__.__qualname__.lower() == str_name 113 | -------------------------------------------------------------------------------- /tests/test_two_dim_michalewicz.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_michalewicz import * 10 | 11 | class_fun = Michalewicz 12 | str_name = 'michalewicz' 13 | 14 | TEST_EPSILON = 1e-3 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [-0.00000000e+00], 36 | [-9.76562500e-04], 37 | [-0.00000000e+00], 38 | [-1.00000000e+00], 39 | [-1.00097656e+00], 40 | [-1.00000000e+00], 41 | [-0.00000000e+00], 42 | [-9.76562500e-04], 43 | [-0.00000000e+00], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_shubert.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 3, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_shubert import * 10 | 11 | class_fun = Shubert 12 | str_name = 'shubert' 13 | 14 | TEST_EPSILON = 1e-5 15 | SCALE_NOISE = 2.0 16 | SEED = 42 17 | 18 | 19 | def test_init(): 20 | obj_fun = class_fun() 21 | 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=1.0) 24 | with pytest.raises(AssertionError) as error: 25 | class_fun(seed='abc') 26 | 27 | def test_validate_properties(): 28 | obj_fun = class_fun() 29 | obj_fun.validate_properties() 30 | 31 | def test_output(): 32 | obj_fun = class_fun() 33 | bounds = obj_fun.get_bounds() 34 | 35 | grids = obj_fun.sample_grids(3) 36 | truths_grids = np.array([ 37 | [0.06674108], 38 | [1.15175294], 39 | [0.86375707], 40 | [1.15175294], 41 | [19.87583625], 42 | [14.90588261], 43 | [0.86375707], 44 | [14.90588261], 45 | [11.17866608], 46 | ]) 47 | 48 | print(grids) 49 | print(obj_fun.output(grids)) 50 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 51 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 52 | 53 | def test_call(): 54 | obj_fun = class_fun() 55 | bounds = obj_fun.get_bounds() 56 | 57 | grids = obj_fun.sample_grids(3) 58 | truths_grids = np.array([ 59 | [0.06674108], 60 | [1.15175294], 61 | [0.86375707], 62 | [1.15175294], 63 | [19.87583625], 64 | [14.90588261], 65 | [0.86375707], 66 | [14.90588261], 67 | [11.17866608], 68 | ]) 69 | 70 | print(grids) 71 | print(obj_fun(grids)) 72 | print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 73 | assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) 74 | 75 | def test_output_constant_noise(): 76 | obj_fun = class_fun() 77 | bounds = obj_fun.get_bounds() 78 | 79 | grids = obj_fun.sample_grids(3) 80 | truths_grids = np.array([ 81 | [2.06674108], 82 | [3.15175294], 83 | [2.86375707], 84 | [3.15175294], 85 | [21.87583625], 86 | [16.90588261], 87 | [2.86375707], 88 | [16.90588261], 89 | [13.17866608], 90 | ]) 91 | 92 | print(grids) 93 | print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) 94 | print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 95 | assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) 96 | 97 | def test_output_gaussian_noise(): 98 | obj_fun = class_fun(seed=SEED) 99 | bounds = obj_fun.get_bounds() 100 | 101 | grids = obj_fun.sample_grids(3) 102 | truths_grids = np.array([ 103 | [1.06016939], 104 | [0.87522434], 105 | [2.15913415], 106 | [4.19781266], 107 | [19.4075295], 108 | [14.4376087], 109 | [4.02218271], 110 | [16.44075207], 111 | [10.2397173], 112 | ]) 113 | outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) 114 | 115 | print(grids) 116 | print(outputs) 117 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 118 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 119 | 120 | def test_output_sparse_gaussian_noise(): 121 | obj_fun = class_fun(seed=SEED) 122 | bounds = obj_fun.get_bounds() 123 | 124 | grids = obj_fun.sample_grids(3) 125 | truths_grids = np.array([ 126 | [1.06016939], 127 | [0.87522434], 128 | [0.86375707], 129 | [1.15175294], 130 | [19.87583625], 131 | [14.4376087], 132 | [0.86375707], 133 | [16.44075207], 134 | [10.2397173], 135 | ]) 136 | outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) 137 | 138 | print(grids) 139 | print(outputs) 140 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 141 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 142 | 143 | def test_output_student_t_noise(): 144 | obj_fun = class_fun(seed=SEED) 145 | bounds = obj_fun.get_bounds() 146 | 147 | grids = obj_fun.sample_grids(3) 148 | truths_grids = np.array([ 149 | [1.21597568], 150 | [-1.01162753], 151 | [3.50187411], 152 | [-0.43179858], 153 | [21.34866175], 154 | [18.69258998], 155 | [-3.06453537], 156 | [13.79388546], 157 | [10.03544615], 158 | ]) 159 | outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) 160 | 161 | print(grids) 162 | print(outputs) 163 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 164 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 165 | 166 | def test_output_sparse_student_t_noise(): 167 | obj_fun = class_fun(seed=SEED) 168 | bounds = obj_fun.get_bounds() 169 | 170 | grids = obj_fun.sample_grids(3) 171 | truths_grids = np.array([ 172 | [1.21597568], 173 | [-1.01162753], 174 | [0.86375707], 175 | [1.15175294], 176 | [19.87583625], 177 | [14.90588261], 178 | [-3.06453537], 179 | [14.90588261], 180 | [11.17866608], 181 | ]) 182 | outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) 183 | 184 | print(grids) 185 | print(outputs) 186 | print(np.abs(outputs - truths_grids) < TEST_EPSILON) 187 | assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) 188 | 189 | def test_name(): 190 | obj_fun = class_fun() 191 | assert obj_fun.name == str_name 192 | 193 | assert obj_fun.__class__.__name__.lower() == str_name 194 | assert obj_fun.__class__.__qualname__.lower() == str_name 195 | -------------------------------------------------------------------------------- /tests/test_two_dim_sixhumpcamel.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_sixhumpcamel import * 10 | 11 | class_fun = SixHumpCamel 12 | str_name = 'sixhumpcamel' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [162.9], 36 | [48.], 37 | [150.9], 38 | [108.9], 39 | [0.], 40 | [108.9], 41 | [150.9], 42 | [48.], 43 | [162.9], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_two_dim_threehumpcamel.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: December 4, 2022 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks.two_dim_threehumpcamel import * 10 | 11 | class_fun = ThreeHumpCamel 12 | str_name = 'threehumpcamel' 13 | 14 | TEST_EPSILON = 1e-5 15 | 16 | 17 | def test_init(): 18 | obj_fun = class_fun() 19 | 20 | with pytest.raises(AssertionError) as error: 21 | class_fun(seed='abc') 22 | with pytest.raises(AssertionError) as error: 23 | class_fun(seed=2.1) 24 | 25 | def test_validate_properties(): 26 | obj_fun = class_fun() 27 | obj_fun.validate_properties() 28 | 29 | def test_output(): 30 | obj_fun = class_fun() 31 | bounds = obj_fun.get_bounds() 32 | 33 | grids = obj_fun.sample_grids(3) 34 | truths_grids = np.array([ 35 | [2047.91666667], 36 | [25.0], 37 | [1997.91666667], 38 | [1997.91666667], 39 | [0.0], 40 | [1997.91666667], 41 | [1997.91666667], 42 | [25.0], 43 | [2047.91666667], 44 | ]) 45 | 46 | print(grids) 47 | print(obj_fun.output(grids)) 48 | print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 49 | assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) 50 | 51 | def test_name(): 52 | obj_fun = class_fun() 53 | assert obj_fun.name == str_name 54 | 55 | assert obj_fun.__class__.__name__.lower() == str_name 56 | assert obj_fun.__class__.__qualname__.lower() == str_name 57 | -------------------------------------------------------------------------------- /tests/test_utils.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 6, 2023 4 | # 5 | 6 | import numpy as np 7 | import pytest 8 | 9 | from bayeso_benchmarks import utils 10 | 11 | TEST_EPSILON = 1e-5 12 | 13 | 14 | def test_get_benchmark(): 15 | with pytest.raises(TypeError) as error: 16 | benchmark = utils.get_benchmark() 17 | with pytest.raises(ValueError) as error: 18 | benchmark = utils.get_benchmark('abc', seed=None) 19 | 20 | with pytest.raises(AssertionError) as error: 21 | benchmark = utils.get_benchmark('ackley') 22 | with pytest.raises(AssertionError) as error: 23 | benchmark = utils.get_benchmark('ackley', seed='abc') 24 | 25 | benchmark = utils.get_benchmark('ackley', dim=4, seed=42) 26 | print(benchmark.output(np.array([0.0, 0.0, 0.0, 0.0]))) 27 | 28 | with pytest.raises(AssertionError) as error: 29 | benchmark = utils.get_benchmark('cosines') 30 | 31 | benchmark = utils.get_benchmark('cosines', dim=4, seed=None) 32 | 33 | with pytest.raises(AssertionError) as error: 34 | benchmark = utils.get_benchmark('griewank') 35 | 36 | benchmark = utils.get_benchmark('griewank', dim=4, seed=None) 37 | 38 | with pytest.raises(AssertionError) as error: 39 | benchmark = utils.get_benchmark('levy') 40 | 41 | benchmark = utils.get_benchmark('levy', dim=2, seed=None) 42 | 43 | with pytest.raises(AssertionError) as error: 44 | benchmark = utils.get_benchmark('rastrigin') 45 | 46 | benchmark = utils.get_benchmark('rastrigin', dim=8, seed=None) 47 | 48 | with pytest.raises(AssertionError) as error: 49 | benchmark = utils.get_benchmark('rosenbrock') 50 | 51 | benchmark = utils.get_benchmark('rosenbrock', dim=8, seed=None) 52 | 53 | with pytest.raises(AssertionError) as error: 54 | benchmark = utils.get_benchmark('sphere') 55 | 56 | benchmark = utils.get_benchmark('sphere', dim=16, seed=None) 57 | 58 | with pytest.raises(AssertionError) as error: 59 | benchmark = utils.get_benchmark('zakharov') 60 | 61 | benchmark = utils.get_benchmark('zakharov', dim=16, seed=None) 62 | 63 | with pytest.raises(AssertionError) as error: 64 | benchmark = utils.get_benchmark('constant') 65 | with pytest.raises(AssertionError) as error: 66 | benchmark = utils.get_benchmark('constant', constant=None) 67 | with pytest.raises(AssertionError) as error: 68 | benchmark = utils.get_benchmark('constant', bounds=None) 69 | with pytest.raises(AssertionError) as error: 70 | benchmark = utils.get_benchmark('constant', bounds=np.array([0.0, 10.0]), constant=10.0, seed=None) 71 | 72 | benchmark = utils.get_benchmark('constant', bounds=np.array([[0.0, 10.0]]), constant=10.0, seed=None) 73 | 74 | benchmark = utils.get_benchmark('gramacyandlee2012') 75 | 76 | with pytest.raises(AssertionError) as error: 77 | benchmark = utils.get_benchmark('linear') 78 | 79 | benchmark = utils.get_benchmark('linear', bounds=np.array([[0.0, 10.0]]), slope=-1.2, seed=None) 80 | 81 | with pytest.raises(AssertionError) as error: 82 | benchmark = utils.get_benchmark('step') 83 | 84 | benchmark = utils.get_benchmark('step', steps=[0.0, 3.0, 7.0, 10.0], step_values=[-2.1, 4.0, 10.0], seed=None) 85 | 86 | benchmark = utils.get_benchmark('beale') 87 | benchmark = utils.get_benchmark('bohachevsky') 88 | 89 | benchmark = utils.get_benchmark('branin') 90 | print(benchmark.output(np.array([1.0, 1.0]))) 91 | 92 | benchmark = utils.get_benchmark('bukin6') 93 | benchmark = utils.get_benchmark('dejong5') 94 | benchmark = utils.get_benchmark('dropwave') 95 | benchmark = utils.get_benchmark('easom') 96 | benchmark = utils.get_benchmark('eggholder') 97 | benchmark = utils.get_benchmark('goldsteinprice') 98 | benchmark = utils.get_benchmark('holdertable') 99 | benchmark = utils.get_benchmark('kim1') 100 | benchmark = utils.get_benchmark('kim2') 101 | benchmark = utils.get_benchmark('kim3') 102 | benchmark = utils.get_benchmark('michalewicz') 103 | benchmark = utils.get_benchmark('shubert') 104 | benchmark = utils.get_benchmark('sixhumpcamel') 105 | benchmark = utils.get_benchmark('threehumpcamel') 106 | 107 | benchmark = utils.get_benchmark('colville') 108 | benchmark = utils.get_benchmark('hartmann3d') 109 | benchmark = utils.get_benchmark('hartmann6d') 110 | 111 | def test_pdf_two_dim_normal(): 112 | bx = np.array([0.0, 1.0]) 113 | mu = np.array([1.0, 1.0]) 114 | Cov = np.array([ 115 | [2.0, 1.0], 116 | [1.0, 2.0], 117 | ]) 118 | 119 | with pytest.raises(AssertionError) as error: 120 | value = utils.pdf_two_dim_normal(np.array([1.0, 1.0, 1.0]), mu, Cov) 121 | with pytest.raises(AssertionError) as error: 122 | value = utils.pdf_two_dim_normal(np.array([2.0]), mu, Cov) 123 | with pytest.raises(AssertionError) as error: 124 | value = utils.pdf_two_dim_normal(bx, np.array([1.0, 1.0, 1.0]), Cov) 125 | with pytest.raises(AssertionError) as error: 126 | value = utils.pdf_two_dim_normal(bx, np.array([3.0]), Cov) 127 | 128 | value = utils.pdf_two_dim_normal(bx, mu, Cov) 129 | print(value) 130 | 131 | assert np.abs(0.06584073599896273 - value) < TEST_EPSILON 132 | -------------------------------------------------------------------------------- /tests/test_version.py: -------------------------------------------------------------------------------- 1 | # 2 | # author: Jungtaek Kim (jtkim@postech.ac.kr) 3 | # last updated: January 27, 2023 4 | # 5 | 6 | 7 | STR_VERSION = '0.2.0' 8 | 9 | 10 | def test_version_bayeso(): 11 | import bayeso_benchmarks 12 | assert bayeso_benchmarks.__version__ == STR_VERSION 13 | 14 | def test_version_setup(): 15 | import pkg_resources 16 | assert pkg_resources.require('bayeso-benchmarks')[0].version == STR_VERSION 17 | --------------------------------------------------------------------------------