diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 77101b0..91d201a 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -12,7 +12,8 @@ jobs: - '3.8' - '3.9' - '3.10' - runs-on: ubuntu-latest + - '3.11' + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 diff --git a/LICENSE b/LICENSE index c150506..60c4a91 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2022 Jungtaek Kim +Copyright (c) 2019-2023 Jungtaek Kim Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d81f761..6bb47f7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,16 @@ -# BayesO Benchmarks +
+ +
+ +# BayesO Benchmarks: Benchmark Functions for Bayesian Optimization [![Build Status](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml/badge.svg)](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -Benchmarks for Bayesian optimization. +This repository provides the implementation of benchmark functions for Bayesian optimization. The details of benchmark functions can be found in [these notes](https://jungtaek.github.io/notes/benchmarks_bo.pdf). +* [https://bayeso.org](https://bayeso.org) + ## Installation We recommend installing it with `virtualenv`. You can choose one of three installation options. @@ -64,8 +70,5 @@ Y = obj_fun.output(X) Y_noise = obj_fun.output_gaussian_noise(X) ``` -## Author -* [Jungtaek Kim](https://jungtaek.github.io) (POSTECH) - ## License [MIT License](LICENSE) diff --git a/bayeso_benchmarks/__init__.py b/bayeso_benchmarks/__init__.py index e112df7..d9eb7e4 100644 --- a/bayeso_benchmarks/__init__.py +++ b/bayeso_benchmarks/__init__.py @@ -1,16 +1,20 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: October 23, 2021 +# last updated: January 6, 2023 # -__version__ = '0.1.6' +__version__ = '0.1.7' from bayeso_benchmarks.inf_dim_ackley import Ackley from bayeso_benchmarks.inf_dim_cosines import Cosines +from bayeso_benchmarks.inf_dim_griewank import Griewank +from bayeso_benchmarks.inf_dim_levy import Levy +from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock from bayeso_benchmarks.inf_dim_sphere import Sphere +from bayeso_benchmarks.inf_dim_zakharov import Zakharov from bayeso_benchmarks.one_dim_constant import Constant from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 @@ -20,8 +24,10 @@ from bayeso_benchmarks.two_dim_beale import Beale from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky from bayeso_benchmarks.two_dim_branin import Branin +from bayeso_benchmarks.two_dim_bukin6 import Bukin6 from bayeso_benchmarks.two_dim_dejong5 import DeJong5 from bayeso_benchmarks.two_dim_dropwave import DropWave +from bayeso_benchmarks.two_dim_easom import Easom from bayeso_benchmarks.two_dim_eggholder import Eggholder from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice from bayeso_benchmarks.two_dim_holdertable import HolderTable @@ -29,8 +35,47 @@ from bayeso_benchmarks.two_dim_kim2 import Kim2 from bayeso_benchmarks.two_dim_kim3 import Kim3 from bayeso_benchmarks.two_dim_michalewicz import Michalewicz +from bayeso_benchmarks.two_dim_shubert import Shubert from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel +from bayeso_benchmarks.four_dim_colville import Colville from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D from bayeso_benchmarks.six_dim_hartmann6d import Hartmann6D + + +all_benchmarks = [ + Ackley, + Cosines, + Griewank, + Levy, + Rastrigin, + Rosenbrock, + Sphere, + Zakharov, + Constant, + GramacyAndLee2012, + Linear, + Step, + Beale, + Bohachevsky, + Branin, + Bukin6, + DeJong5, + DropWave, + Easom, + Eggholder, + GoldsteinPrice, + HolderTable, + Kim1, + Kim2, + Kim3, + Michalewicz, + Shubert, + SixHumpCamel, + ThreeHumpCamel, + Colville, + Hartmann3D, + Hartmann6D, +] +num_benchmarks = len(all_benchmarks) diff --git a/bayeso_benchmarks/benchmark_base.py b/bayeso_benchmarks/benchmark_base.py index acda74a..c3d5472 100644 --- a/bayeso_benchmarks/benchmark_base.py +++ b/bayeso_benchmarks/benchmark_base.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: May 1, 2021 +# last updated: December 13, 2022 # import numpy as np @@ -8,14 +8,15 @@ EPSILON = 1e-4 -class Function(object): +class Function: def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, function, dim_problem=None, seed=None): assert isinstance(dimensionality, int) or dimensionality is np.inf assert isinstance(bounds, np.ndarray) assert isinstance(global_minimizers, np.ndarray) assert isinstance(global_minimum, float) assert callable(function) - assert isinstance(dim_problem, int) or dim_problem is None + assert isinstance(dim_problem, (type(None), int)) + assert isinstance(seed, (type(None), int)) assert len(bounds.shape) == 2 assert bounds.shape[1] == 2 assert (bounds[:, 0] <= bounds[:, 1]).all() @@ -30,6 +31,7 @@ def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, fu self.random_state = np.random.RandomState(seed) self.validate_properties() + self.set_name() @property def dimensionality(self): @@ -47,6 +49,14 @@ def global_minimizers(self): def global_minimum(self): return self._global_minimum + def set_name(self): + name = self.__class__.__name__.lower() + + if self.dimensionality is np.inf: + self.name = f'{name}_{self.dim_problem}' + else: + self.name = name + def get_bounds(self): if self.dimensionality is np.inf: return np.array(list(self.bounds) * self.dim_problem) @@ -134,7 +144,7 @@ def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01): noise = self.random_state.randn(num_X) mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity - noise *= mask.astype(np.float) + noise *= mask.astype(float) by += scale_noise * noise Y = np.expand_dims(by, axis=1) @@ -172,7 +182,7 @@ def output_sparse_student_t_noise(self, X, scale_noise=0.1, dof=4.0, sparsity=0. noise = self.random_state.standard_t(dof, size=num_X) mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity - noise *= mask.astype(np.float) + noise *= mask.astype(float) by += scale_noise * noise Y = np.expand_dims(by, axis=1) @@ -228,3 +238,6 @@ def sample_uniform(self, num_points, seed=None): points = bounds[:, 0] + (bounds[:, 1] - bounds[:, 0]) * points return points + + def __call__(self, X): + return self.output(X) diff --git a/bayeso_benchmarks/four_dim_colville.py b/bayeso_benchmarks/four_dim_colville.py new file mode 100644 index 0000000..1416c3d --- /dev/null +++ b/bayeso_benchmarks/four_dim_colville.py @@ -0,0 +1,48 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: December 30, 2022 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = 100.0 * (bx[0]**2 - bx[1])**2 + y += (bx[0] - 1.0)**2 + y += (bx[2] - 1.0)**2 + y += 90.0 * (bx[2]**2 - bx[3])**2 + y += 10.1 * ((bx[1] - 1.0)**2 + (bx[3] - 1.0)**2) + y += 19.8 * (bx[1] - 1.0) * (bx[3] - 1.0) + + return y + + +class Colville(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 4 + bounds = np.array([ + [-10.0, 10.0], + [-10.0, 10.0], + [-10.0, 10.0], + [-10.0, 10.0], + ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + + global_minimizers = np.array([ + [1.0, 1.0, 1.0, 1.0], + ]) + global_minimum = 0.0 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Colville, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_griewank.py b/bayeso_benchmarks/inf_dim_griewank.py new file mode 100644 index 0000000..c20eb46 --- /dev/null +++ b/bayeso_benchmarks/inf_dim_griewank.py @@ -0,0 +1,45 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 6, 2023 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + first_term = np.sum(bx**2 / 4000.0) + + second_term = 1.0 + for ind in range(1, dim_bx + 1): + second_term *= np.cos(bx[ind - 1] / np.sqrt(ind)) + + y = first_term - second_term + 1.0 + return y + + +class Griewank(Function): + def __init__(self, dim_problem, seed=None): + assert isinstance(dim_problem, int) + assert isinstance(seed, (type(None), int)) + + dim_bx = np.inf + bounds = np.array([ + [-600.0, 600.0], + ]) + global_minimizers = np.array([ + [0.0], + ]) + global_minimum = 0.0 + dim_problem = dim_problem + + function = lambda bx: fun_target(bx, dim_problem) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Griewank, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_levy.py b/bayeso_benchmarks/inf_dim_levy.py new file mode 100644 index 0000000..833e81e --- /dev/null +++ b/bayeso_benchmarks/inf_dim_levy.py @@ -0,0 +1,51 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: December 29, 2022 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx, +): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + bw = [] + for x in bx: + w = 1.0 + (x - 1.0) / 4.0 + bw.append(w) + bw = np.array(bw) + + y = np.sin(np.pi * bw[0])**2 + + for w in bw[:-1]: + y += (w - 1.0)**2 * (1.0 + 10.0 * np.sin(np.pi * w + 1.0)**2) + + y += (bw[-1] - 1.0)**2 * (1.0 + np.sin(2.0 * np.pi * bw[-1])**2) + return y + + +class Levy(Function): + def __init__(self, dim_problem, seed=None): + assert isinstance(dim_problem, int) + assert isinstance(seed, (type(None), int)) + + dim_bx = np.inf + bounds = np.array([ + [-10.0, 10.0], + ]) + global_minimizers = np.array([ + [1.0], + ]) + global_minimum = 0.0 + dim_problem = dim_problem + + function = lambda bx: fun_target(bx, dim_problem) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Levy, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_rastrigin.py b/bayeso_benchmarks/inf_dim_rastrigin.py new file mode 100644 index 0000000..43faa7e --- /dev/null +++ b/bayeso_benchmarks/inf_dim_rastrigin.py @@ -0,0 +1,43 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: December 20, 2022 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = 10.0 * dim_bx + + for ind in range(0, dim_bx): + y += bx[ind]**2 - 10.0 * np.cos(2.0 * np.pi * bx[ind]) + + return y + + +class Rastrigin(Function): + def __init__(self, dim_problem, seed=None): + assert isinstance(dim_problem, int) + assert isinstance(seed, (type(None), int)) + + dim_bx = np.inf + bounds = np.array([ + [-5.12, 5.12], + ]) + global_minimizers = np.array([ + [0.0], + ]) + global_minimum = 0.0 + dim_problem = dim_problem + + function = lambda bx: fun_target(bx, dim_problem) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Rastrigin, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/inf_dim_zakharov.py b/bayeso_benchmarks/inf_dim_zakharov.py new file mode 100644 index 0000000..bdb9918 --- /dev/null +++ b/bayeso_benchmarks/inf_dim_zakharov.py @@ -0,0 +1,48 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 4, 2023 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + first_term = np.sum(bx**2) + + inner_term = 0.0 + for ind in range(1, dim_bx + 1): + inner_term += 0.5 * ind * bx[ind - 1] + + second_term = inner_term**2 + third_term = inner_term**4 + + y = first_term + second_term + third_term + return y + + +class Zakharov(Function): + def __init__(self, dim_problem, seed=None): + assert isinstance(dim_problem, int) + assert isinstance(seed, (type(None), int)) + + dim_bx = np.inf + bounds = np.array([ + [-5.0, 10.0], + ]) + global_minimizers = np.array([ + [0.0], + ]) + global_minimum = 0.0 + dim_problem = dim_problem + + function = lambda bx: fun_target(bx, dim_problem) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) + except: + super(Zakharov, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed) diff --git a/bayeso_benchmarks/one_dim_constant.py b/bayeso_benchmarks/one_dim_constant.py index cd59f76..102a7d6 100644 --- a/bayeso_benchmarks/one_dim_constant.py +++ b/bayeso_benchmarks/one_dim_constant.py @@ -19,7 +19,7 @@ def fun_target(bx, dim_bx, constant): class Constant(Function): def __init__(self, - bounds = np.array([ + bounds=np.array([ [-10.0, 10.0], ]), constant=0.0, diff --git a/bayeso_benchmarks/one_dim_gramacyandlee2012.py b/bayeso_benchmarks/one_dim_gramacyandlee2012.py index 5559f1d..aa2ab1c 100644 --- a/bayeso_benchmarks/one_dim_gramacyandlee2012.py +++ b/bayeso_benchmarks/one_dim_gramacyandlee2012.py @@ -24,6 +24,9 @@ def __init__(self, seed=None): bounds = np.array([ [0.5, 2.5], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [0.54856405], ]) diff --git a/bayeso_benchmarks/one_dim_step.py b/bayeso_benchmarks/one_dim_step.py index 9610fe9..2fb01e0 100644 --- a/bayeso_benchmarks/one_dim_step.py +++ b/bayeso_benchmarks/one_dim_step.py @@ -49,6 +49,9 @@ def __init__(self, bounds = np.array([ [np.min(steps), np.max(steps)], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [steps[np.argmin(step_values)]], ]) diff --git a/bayeso_benchmarks/six_dim_hartmann6d.py b/bayeso_benchmarks/six_dim_hartmann6d.py index 690e396..3bc9b29 100644 --- a/bayeso_benchmarks/six_dim_hartmann6d.py +++ b/bayeso_benchmarks/six_dim_hartmann6d.py @@ -38,24 +38,20 @@ def fun_target(bx, dim_bx): class Hartmann6D(Function): - def __init__(self, - bounds=np.array([ + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 6 + bounds = np.array([ [0.0, 1.0], [0.0, 1.0], [0.0, 1.0], [0.0, 1.0], [0.0, 1.0], [0.0, 1.0], - ]), - seed=None - ): - assert isinstance(bounds, np.ndarray) - assert isinstance(seed, (type(None), int)) - assert len(bounds.shape) == 2 - assert bounds.shape[1] == 2 - - dim_bx = 6 + ]) assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 global_minimizers = np.array([ [0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573], diff --git a/bayeso_benchmarks/three_dim_hartmann3d.py b/bayeso_benchmarks/three_dim_hartmann3d.py index 0e528a3..8379272 100644 --- a/bayeso_benchmarks/three_dim_hartmann3d.py +++ b/bayeso_benchmarks/three_dim_hartmann3d.py @@ -38,21 +38,17 @@ def fun_target(bx, dim_bx): class Hartmann3D(Function): - def __init__(self, - bounds=np.array([ - [0.0, 1.0], - [0.0, 1.0], - [0.0, 1.0], - ]), - seed=None - ): - assert isinstance(bounds, np.ndarray) + def __init__(self, seed=None): assert isinstance(seed, (type(None), int)) - assert len(bounds.shape) == 2 - assert bounds.shape[1] == 2 dim_bx = 3 + bounds = np.array([ + [0.0, 1.0], + [0.0, 1.0], + [0.0, 1.0], + ]) assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 global_minimizers = np.array([ [0.114614, 0.555649, 0.852547], diff --git a/bayeso_benchmarks/two_dim_beale.py b/bayeso_benchmarks/two_dim_beale.py index 3abc875..e98e8da 100644 --- a/bayeso_benchmarks/two_dim_beale.py +++ b/bayeso_benchmarks/two_dim_beale.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-4.5, 4.5], [-4.5, 4.5], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [3.0, 0.5], ]) diff --git a/bayeso_benchmarks/two_dim_bohachevsky.py b/bayeso_benchmarks/two_dim_bohachevsky.py index c82364c..b421f76 100644 --- a/bayeso_benchmarks/two_dim_bohachevsky.py +++ b/bayeso_benchmarks/two_dim_bohachevsky.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-100.0, 100.0], [-100.0, 100.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [0.0, 0.0], ]) diff --git a/bayeso_benchmarks/two_dim_branin.py b/bayeso_benchmarks/two_dim_branin.py index 28979fc..3f0df1e 100644 --- a/bayeso_benchmarks/two_dim_branin.py +++ b/bayeso_benchmarks/two_dim_branin.py @@ -45,6 +45,9 @@ def __init__(self, [-5, 10], [0, 15], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [-np.pi, 12.275], [np.pi, 2.275], diff --git a/bayeso_benchmarks/two_dim_bukin6.py b/bayeso_benchmarks/two_dim_bukin6.py new file mode 100644 index 0000000..07c9e51 --- /dev/null +++ b/bayeso_benchmarks/two_dim_bukin6.py @@ -0,0 +1,40 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 6, 2023 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = 100.0 * np.sqrt(np.abs(bx[1] - 0.01 * bx[0]**2)) + 0.01 * np.abs(bx[0] + 10.0) + return y + + +class Bukin6(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 2 + bounds = np.array([ + [-15, -5], + [-3, 3], + ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + + global_minimizers = np.array([ + [-10.0, 1.0], + ]) + global_minimum = 0.0 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Bukin6, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_dejong5.py b/bayeso_benchmarks/two_dim_dejong5.py index 0199891..bdb0d63 100644 --- a/bayeso_benchmarks/two_dim_dejong5.py +++ b/bayeso_benchmarks/two_dim_dejong5.py @@ -35,6 +35,9 @@ def __init__(self, seed=None): [-65.536, 65.536], [-65.536, 65.536], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [-31.97707837, -31.97795471], [-31.99140499, -31.99140499], diff --git a/bayeso_benchmarks/two_dim_dropwave.py b/bayeso_benchmarks/two_dim_dropwave.py index 405eb67..447c1ec 100644 --- a/bayeso_benchmarks/two_dim_dropwave.py +++ b/bayeso_benchmarks/two_dim_dropwave.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-5.12, 5.12], [-5.12, 5.12], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [0.0, 0.0], ]) diff --git a/bayeso_benchmarks/two_dim_easom.py b/bayeso_benchmarks/two_dim_easom.py new file mode 100644 index 0000000..2ccc071 --- /dev/null +++ b/bayeso_benchmarks/two_dim_easom.py @@ -0,0 +1,40 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 3, 2023 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = -1.0 * np.cos(bx[0]) * np.cos(bx[1]) * np.exp(-1.0 * (bx[0] - np.pi)**2 - (bx[1] - np.pi)**2) + return y + + +class Easom(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 2 + bounds = np.array([ + [-100, 100], + [-100, 100], + ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + + global_minimizers = np.array([ + [np.pi, np.pi], + ]) + global_minimum = -1.0 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Easom, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_eggholder.py b/bayeso_benchmarks/two_dim_eggholder.py index 5395e62..8dc145c 100644 --- a/bayeso_benchmarks/two_dim_eggholder.py +++ b/bayeso_benchmarks/two_dim_eggholder.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: January 13, 2023 # import numpy as np @@ -17,20 +17,16 @@ def fun_target(bx, dim_bx): class Eggholder(Function): - def __init__(self, - bounds=np.array([ - [-512.0, 512.0], - [-512.0, 512.0], - ]), - seed=None - ): - assert isinstance(bounds, np.ndarray) + def __init__(self, seed=None): assert isinstance(seed, (type(None), int)) - assert len(bounds.shape) == 2 - assert bounds.shape[1] == 2 dim_bx = 2 + bounds = np.array([ + [-512.0, 512.0], + [-512.0, 512.0], + ]) assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 global_minimizers = np.array([ [512.0, 404.2319], diff --git a/bayeso_benchmarks/two_dim_goldsteinprice.py b/bayeso_benchmarks/two_dim_goldsteinprice.py index 940499f..22ce195 100644 --- a/bayeso_benchmarks/two_dim_goldsteinprice.py +++ b/bayeso_benchmarks/two_dim_goldsteinprice.py @@ -33,6 +33,9 @@ def __init__(self, seed=None): [-2.0, 2.0], [-2.0, 2.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [0.0, -1.0], ]) diff --git a/bayeso_benchmarks/two_dim_holdertable.py b/bayeso_benchmarks/two_dim_holdertable.py index 6011272..62f904a 100644 --- a/bayeso_benchmarks/two_dim_holdertable.py +++ b/bayeso_benchmarks/two_dim_holdertable.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-10.0, 10.0], [-10.0, 10.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [8.05502347, 9.66459002], [8.05502347, -9.66459002], diff --git a/bayeso_benchmarks/two_dim_kim1.py b/bayeso_benchmarks/two_dim_kim1.py index 11b6595..ea82e06 100644 --- a/bayeso_benchmarks/two_dim_kim1.py +++ b/bayeso_benchmarks/two_dim_kim1.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-16.0, 16.0], [-16.0, 16.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [4.72130726, 3.17086303], ]) diff --git a/bayeso_benchmarks/two_dim_kim2.py b/bayeso_benchmarks/two_dim_kim2.py index 27ec15f..e6aa747 100644 --- a/bayeso_benchmarks/two_dim_kim2.py +++ b/bayeso_benchmarks/two_dim_kim2.py @@ -30,6 +30,9 @@ def __init__(self, seed=None): [-128.0, 128.0], [-128.0, 128.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [-2.1013466, 34.14526252], ]) diff --git a/bayeso_benchmarks/two_dim_kim3.py b/bayeso_benchmarks/two_dim_kim3.py index bb0ffd7..a899fc9 100644 --- a/bayeso_benchmarks/two_dim_kim3.py +++ b/bayeso_benchmarks/two_dim_kim3.py @@ -40,6 +40,9 @@ def __init__(self, seed=None): [-256.0, 256.0], [-256.0, 256.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [48.12477173, 34.19859065], ]) diff --git a/bayeso_benchmarks/two_dim_michalewicz.py b/bayeso_benchmarks/two_dim_michalewicz.py index 886a5f9..a3f464c 100644 --- a/bayeso_benchmarks/two_dim_michalewicz.py +++ b/bayeso_benchmarks/two_dim_michalewicz.py @@ -30,6 +30,9 @@ def __init__(self, seed=None): [0.0, np.pi], [0.0, np.pi], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [2.20290552, 1.57079632], ]) diff --git a/bayeso_benchmarks/two_dim_shubert.py b/bayeso_benchmarks/two_dim_shubert.py new file mode 100644 index 0000000..cb600d0 --- /dev/null +++ b/bayeso_benchmarks/two_dim_shubert.py @@ -0,0 +1,48 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 3, 2023 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + first_term = 0.0 + for ind in range(1, 6): + first_term += ind * np.cos((ind + 1.0) * bx[0] + ind) + + second_term = 0.0 + for ind in range(1, 6): + second_term += ind * np.cos((ind + 1.0) * bx[1] + ind) + + y = first_term * second_term + return y + + +class Shubert(Function): + def __init__(self, seed=None): + assert isinstance(seed, (type(None), int)) + + dim_bx = 2 + bounds = np.array([ + [-10, 10], + [-10, 10], + ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + + global_minimizers = np.array([ + [-7.08350641, -7.70831374], + ]) + global_minimum = -186.73090883 + function = lambda bx: fun_target(bx, dim_bx) + + try: + super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) + except: + super(Shubert, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed) diff --git a/bayeso_benchmarks/two_dim_sixhumpcamel.py b/bayeso_benchmarks/two_dim_sixhumpcamel.py index 80c6283..767c064 100644 --- a/bayeso_benchmarks/two_dim_sixhumpcamel.py +++ b/bayeso_benchmarks/two_dim_sixhumpcamel.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-3.0, 3.0], [-2.0, 2.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [0.0898, -0.7126], [-0.0898, 0.7126], diff --git a/bayeso_benchmarks/two_dim_threehumpcamel.py b/bayeso_benchmarks/two_dim_threehumpcamel.py index 9bf97e8..5c3e92c 100644 --- a/bayeso_benchmarks/two_dim_threehumpcamel.py +++ b/bayeso_benchmarks/two_dim_threehumpcamel.py @@ -25,6 +25,9 @@ def __init__(self, seed=None): [-5.0, 5.0], [-5.0, 5.0], ]) + assert bounds.shape[0] == dim_bx + assert bounds.shape[1] == 2 + global_minimizers = np.array([ [0.0, 0.0], ]) diff --git a/bayeso_benchmarks/utils.py b/bayeso_benchmarks/utils.py index 7374b7d..4fc6189 100644 --- a/bayeso_benchmarks/utils.py +++ b/bayeso_benchmarks/utils.py @@ -1,10 +1,65 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: October 27, 2021 +# last updated: January 4, 2023 # import numpy as np +import bayeso_benchmarks as bb + + +def get_benchmark(str_fun, seed=None, **kwargs): + count = 0 + + for class_benchmark in bb.all_benchmarks: + if str_fun == class_benchmark.__name__.lower(): + target_class = class_benchmark + count += 1 + + if count == 0: + raise ValueError('missing str_fun.') + elif count > 1: + raise ValueError('duplicate class name.') + + if str_fun in [ + 'ackley', + 'cosines', + 'griewank', + 'levy', + 'rastrigin', + 'rosenbrock', + 'sphere', + 'zakharov', + ]: + assert 'dim' in kwargs + dim = kwargs['dim'] + + benchmark = target_class(dim, seed=seed) + elif str_fun == 'constant': + assert 'bounds' in kwargs + assert 'constant' in kwargs + bounds = kwargs['bounds'] + constant = kwargs['constant'] + + benchmark = target_class(bounds=bounds, constant=constant, seed=seed) + elif str_fun == 'linear': + assert 'bounds' in kwargs + assert 'slope' in kwargs + bounds = kwargs['bounds'] + slope = kwargs['slope'] + + benchmark = target_class(bounds=bounds, slope=slope, seed=seed) + elif str_fun == 'step': + assert 'steps' in kwargs + assert 'step_values' in kwargs + steps = kwargs['steps'] + step_values = kwargs['step_values'] + + benchmark = target_class(steps=steps, step_values=step_values, seed=seed) + else: + benchmark = target_class(seed=seed) + + return benchmark def pdf_two_dim_normal(bx, mu, Cov): assert bx.shape[0] == mu.shape[0] == Cov.shape[0] == Cov.shape[1] == 2 diff --git a/examples/plot_benchmarks.py b/examples/plot_benchmarks.py index 3813462..d025f02 100644 --- a/examples/plot_benchmarks.py +++ b/examples/plot_benchmarks.py @@ -8,9 +8,13 @@ def plot_1d(obj_fun, str_x_axis=r'$x$', str_y_axis=r'$f(x)$', str_figures='../figures', + show_figure=False, + bounds=None, # for zooming in on part of a figure ): print(str_fun) - bounds = obj_fun.get_bounds() + + if bounds is None: + bounds = obj_fun.get_bounds() print(bounds) assert bounds.shape[0] == 1 @@ -43,7 +47,10 @@ def plot_1d(obj_fun, transparent=True, bbox_inches='tight') - plt.show() + if show_figure: + plt.show() + + plt.close('all') def plot_2d(obj_fun, str_fun, @@ -51,14 +58,36 @@ def plot_2d(obj_fun, str_x2_axis=r'$x_2$', str_y_axis=r'$f(\mathbf{x})$', str_figures='../figures', + show_figure=False, + bounds=None, # for zooming in on part of a figure ): print(str_fun) - bounds = obj_fun.get_bounds() + + if bounds is None: + bounds = obj_fun.get_bounds() print(bounds) assert bounds.shape[0] == 2 - X1 = np.linspace(bounds[0, 0], bounds[0, 1], 200) - X2 = np.linspace(bounds[1, 0], bounds[1, 1], 200) + num_grids = 300 + + X1 = np.linspace(bounds[0, 0], bounds[0, 1], num_grids) + X2 = np.linspace(bounds[1, 0], bounds[1, 1], num_grids) + + if obj_fun.name == 'easom': + num_grids_additional = 300 + + X1 = np.concatenate([ + X1, + np.linspace(np.pi - 3.0, np.pi + 3.0, num_grids_additional) + ], axis=0) + X2 = np.concatenate([ + X2, + np.linspace(np.pi - 3.0, np.pi + 3.0, num_grids_additional) + ], axis=0) + + X1 = np.sort(X1) + X2 = np.sort(X2) + X1, X2 = np.meshgrid(X1, X2) X = np.concatenate((X1[..., np.newaxis], X2[..., np.newaxis]), axis=2) X = np.reshape(X, (X.shape[0] * X.shape[1], X.shape[2])) @@ -106,14 +135,17 @@ def plot_2d(obj_fun, transparent=True, bbox_inches='tight') - plt.show() + if show_figure: + plt.show() + + plt.close('all') if __name__ == '__main__': # one dim. from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 as target_class obj_fun = target_class() - plot_1d(obj_fun, 'gramacyandlee2012') + plot_1d(obj_fun, 'gramacyandlee2012_1d') from bayeso_benchmarks.inf_dim_ackley import Ackley as target_class obj_fun = target_class(1) @@ -123,10 +155,27 @@ def plot_2d(obj_fun, obj_fun = target_class(1) plot_1d(obj_fun, 'cosines_1d') + from bayeso_benchmarks.inf_dim_griewank import Griewank as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'griewank_1d') + plot_1d(obj_fun, 'griewank_zoom_in_1d', bounds=np.array([[-50, 50]])) + + from bayeso_benchmarks.inf_dim_levy import Levy as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'levy_1d') + + from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'rastrigin_1d') + from bayeso_benchmarks.inf_dim_sphere import Sphere as target_class obj_fun = target_class(1) plot_1d(obj_fun, 'sphere_1d') + from bayeso_benchmarks.inf_dim_zakharov import Zakharov as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'zakharov_1d') + # two dim. from bayeso_benchmarks.two_dim_beale import Beale as target_class obj_fun = target_class() @@ -140,6 +189,10 @@ def plot_2d(obj_fun, obj_fun = target_class() plot_2d(obj_fun, 'branin_2d') + from bayeso_benchmarks.two_dim_bukin6 import Bukin6 as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'bukin6_2d') + from bayeso_benchmarks.two_dim_dejong5 import DeJong5 as target_class obj_fun = target_class() plot_2d(obj_fun, 'dejong5_2d') @@ -148,6 +201,10 @@ def plot_2d(obj_fun, obj_fun = target_class() plot_2d(obj_fun, 'dropwave_2d') + from bayeso_benchmarks.two_dim_easom import Easom as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'easom_2d') + from bayeso_benchmarks.two_dim_eggholder import Eggholder as target_class obj_fun = target_class() plot_2d(obj_fun, 'eggholder_2d') @@ -176,6 +233,10 @@ def plot_2d(obj_fun, obj_fun = target_class() plot_2d(obj_fun, 'michalewicz_2d') + from bayeso_benchmarks.two_dim_shubert import Shubert as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'shubert_2d') + from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel as target_class obj_fun = target_class() plot_2d(obj_fun, 'sixhumpcamel_2d') @@ -192,6 +253,19 @@ def plot_2d(obj_fun, obj_fun = target_class(2) plot_2d(obj_fun, 'cosines_2d') + from bayeso_benchmarks.inf_dim_griewank import Griewank as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'griewank_2d') + plot_2d(obj_fun, 'griewank_zoom_in_2d', bounds=np.array([[-50, 50], [-50, 50]])) + + from bayeso_benchmarks.inf_dim_levy import Levy as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'levy_2d') + + from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'rastrigin_2d') + from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock as target_class obj_fun = target_class(2) plot_2d(obj_fun, 'rosenbrock_2d') @@ -199,3 +273,7 @@ def plot_2d(obj_fun, from bayeso_benchmarks.inf_dim_sphere import Sphere as target_class obj_fun = target_class(2) plot_2d(obj_fun, 'sphere_2d') + + from bayeso_benchmarks.inf_dim_zakharov import Zakharov as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'zakharov_2d') diff --git a/figures/ackley_1d.pdf b/figures/ackley_1d.pdf index 610fef5..40e40ce 100644 Binary files a/figures/ackley_1d.pdf and b/figures/ackley_1d.pdf differ diff --git a/figures/ackley_2d.pdf b/figures/ackley_2d.pdf index 92e2f9a..82675f5 100644 Binary files a/figures/ackley_2d.pdf and b/figures/ackley_2d.pdf differ diff --git a/figures/beale_2d.pdf b/figures/beale_2d.pdf index d06fee7..ed2b8c3 100644 Binary files a/figures/beale_2d.pdf and b/figures/beale_2d.pdf differ diff --git a/figures/bohachevsky_2d.pdf b/figures/bohachevsky_2d.pdf index 92bfd5e..1a8c69e 100644 Binary files a/figures/bohachevsky_2d.pdf and b/figures/bohachevsky_2d.pdf differ diff --git a/figures/branin_2d.pdf b/figures/branin_2d.pdf index 7328230..63e7f35 100644 Binary files a/figures/branin_2d.pdf and b/figures/branin_2d.pdf differ diff --git a/figures/bukin6_2d.pdf b/figures/bukin6_2d.pdf new file mode 100644 index 0000000..0e25cdc Binary files /dev/null and b/figures/bukin6_2d.pdf differ diff --git a/figures/cosines_1d.pdf b/figures/cosines_1d.pdf index 05020b8..0e2c752 100644 Binary files a/figures/cosines_1d.pdf and b/figures/cosines_1d.pdf differ diff --git a/figures/cosines_2d.pdf b/figures/cosines_2d.pdf index 931316b..df6e0e1 100644 Binary files a/figures/cosines_2d.pdf and b/figures/cosines_2d.pdf differ diff --git a/figures/dejong5_2d.pdf b/figures/dejong5_2d.pdf index 8e2fd33..26762ad 100644 Binary files a/figures/dejong5_2d.pdf and b/figures/dejong5_2d.pdf differ diff --git a/figures/dropwave_2d.pdf b/figures/dropwave_2d.pdf index 82d8ebf..ed7b147 100644 Binary files a/figures/dropwave_2d.pdf and b/figures/dropwave_2d.pdf differ diff --git a/figures/easom_2d.pdf b/figures/easom_2d.pdf new file mode 100644 index 0000000..bd36c1d Binary files /dev/null and b/figures/easom_2d.pdf differ diff --git a/figures/eggholder_2d.pdf b/figures/eggholder_2d.pdf index 15dcc12..33af4fd 100644 Binary files a/figures/eggholder_2d.pdf and b/figures/eggholder_2d.pdf differ diff --git a/figures/goldsteinprice_2d.pdf b/figures/goldsteinprice_2d.pdf index af8faee..a092f85 100644 Binary files a/figures/goldsteinprice_2d.pdf and b/figures/goldsteinprice_2d.pdf differ diff --git a/figures/gramacyandlee2012.pdf b/figures/gramacyandlee2012_1d.pdf similarity index 98% rename from figures/gramacyandlee2012.pdf rename to figures/gramacyandlee2012_1d.pdf index 4affb26..4e7becf 100644 Binary files a/figures/gramacyandlee2012.pdf and b/figures/gramacyandlee2012_1d.pdf differ diff --git a/figures/griewank_1d.pdf b/figures/griewank_1d.pdf new file mode 100644 index 0000000..d52cc1a Binary files /dev/null and b/figures/griewank_1d.pdf differ diff --git a/figures/griewank_2d.pdf b/figures/griewank_2d.pdf new file mode 100644 index 0000000..fd5e8f4 Binary files /dev/null and b/figures/griewank_2d.pdf differ diff --git a/figures/griewank_zoom_in_1d.pdf b/figures/griewank_zoom_in_1d.pdf new file mode 100644 index 0000000..84e8a2d Binary files /dev/null and b/figures/griewank_zoom_in_1d.pdf differ diff --git a/figures/griewank_zoom_in_2d.pdf b/figures/griewank_zoom_in_2d.pdf new file mode 100644 index 0000000..431235a Binary files /dev/null and b/figures/griewank_zoom_in_2d.pdf differ diff --git a/figures/holdertable_2d.pdf b/figures/holdertable_2d.pdf index ea5948b..1687296 100644 Binary files a/figures/holdertable_2d.pdf and b/figures/holdertable_2d.pdf differ diff --git a/figures/kim1_2d.pdf b/figures/kim1_2d.pdf index 5f8b90e..e12c60f 100644 Binary files a/figures/kim1_2d.pdf and b/figures/kim1_2d.pdf differ diff --git a/figures/kim2_2d.pdf b/figures/kim2_2d.pdf index 4172c3e..591fc98 100644 Binary files a/figures/kim2_2d.pdf and b/figures/kim2_2d.pdf differ diff --git a/figures/kim3_2d.pdf b/figures/kim3_2d.pdf index 8a1b595..c1caa12 100644 Binary files a/figures/kim3_2d.pdf and b/figures/kim3_2d.pdf differ diff --git a/figures/levy_1d.pdf b/figures/levy_1d.pdf new file mode 100644 index 0000000..c298ccc Binary files /dev/null and b/figures/levy_1d.pdf differ diff --git a/figures/levy_2d.pdf b/figures/levy_2d.pdf new file mode 100644 index 0000000..80fe9e4 Binary files /dev/null and b/figures/levy_2d.pdf differ diff --git a/figures/michalewicz_2d.pdf b/figures/michalewicz_2d.pdf index 8f88935..ef98398 100644 Binary files a/figures/michalewicz_2d.pdf and b/figures/michalewicz_2d.pdf differ diff --git a/figures/rastrigin_1d.pdf b/figures/rastrigin_1d.pdf new file mode 100644 index 0000000..c1265bb Binary files /dev/null and b/figures/rastrigin_1d.pdf differ diff --git a/figures/rastrigin_2d.pdf b/figures/rastrigin_2d.pdf new file mode 100644 index 0000000..816cfe0 Binary files /dev/null and b/figures/rastrigin_2d.pdf differ diff --git a/figures/rosenbrock_2d.pdf b/figures/rosenbrock_2d.pdf index ed00706..90c2f80 100644 Binary files a/figures/rosenbrock_2d.pdf and b/figures/rosenbrock_2d.pdf differ diff --git a/figures/shubert_2d.pdf b/figures/shubert_2d.pdf new file mode 100644 index 0000000..9e8e3fc Binary files /dev/null and b/figures/shubert_2d.pdf differ diff --git a/figures/sixhumpcamel_2d.pdf b/figures/sixhumpcamel_2d.pdf index 524e667..60f401e 100644 Binary files a/figures/sixhumpcamel_2d.pdf and b/figures/sixhumpcamel_2d.pdf differ diff --git a/figures/sphere_1d.pdf b/figures/sphere_1d.pdf index 45f36d6..dde04de 100644 Binary files a/figures/sphere_1d.pdf and b/figures/sphere_1d.pdf differ diff --git a/figures/sphere_2d.pdf b/figures/sphere_2d.pdf index 3671f3d..59808fc 100644 Binary files a/figures/sphere_2d.pdf and b/figures/sphere_2d.pdf differ diff --git a/figures/threehumpcamel_2d.pdf b/figures/threehumpcamel_2d.pdf index bf5378f..4d992a3 100644 Binary files a/figures/threehumpcamel_2d.pdf and b/figures/threehumpcamel_2d.pdf differ diff --git a/figures/zakharov_1d.pdf b/figures/zakharov_1d.pdf new file mode 100644 index 0000000..03a01d7 Binary files /dev/null and b/figures/zakharov_1d.pdf differ diff --git a/figures/zakharov_2d.pdf b/figures/zakharov_2d.pdf new file mode 100644 index 0000000..a41f76f Binary files /dev/null and b/figures/zakharov_2d.pdf differ diff --git a/setup.py b/setup.py index f5f770d..85c2dd4 100644 --- a/setup.py +++ b/setup.py @@ -8,10 +8,10 @@ setup( name='bayeso-benchmarks', - version='0.1.6', + version='0.1.7', author='Jungtaek Kim', author_email='jtkim@postech.ac.kr', - url='https://github.com/jungtaekkim/bayeso-benchmarks', + url='https://bayeso.org', license='MIT', description='Benchmarks for Bayesian optimization', packages=list_packages, diff --git a/tests/test_four_dim_colville.py b/tests/test_four_dim_colville.py new file mode 100644 index 0000000..80c16f7 --- /dev/null +++ b/tests/test_four_dim_colville.py @@ -0,0 +1,226 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: December 30, 2022 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.four_dim_colville import * + +class_fun = Colville +str_name = 'colville' + +TEST_EPSILON = 1e-5 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + with pytest.raises(AssertionError) as error: + class_fun(seed=2.1) + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [2304082.], + [2111692.], + [1939322.], + [1223962.], + [1211572.], + [1219202.], + [2304042.], + [2111652.], + [1939282.], + [1103962.], + [911572.], + [739202.], + [23842.], + [11452.], + [19082.], + [1103922.], + [911532.], + [739162.], + [2304042.], + [2111652.], + [1939282.], + [1223922.], + [1211532.], + [1219162.], + [2304002.], + [2111612.], + [1939242.], + [2090692.], + [1900282.], + [1729892.], + [1010572.], + [1000162.], + [1009772.], + [2090652.], + [1900242.], + [1729852.], + [1090572.], + [900162.], + [729772.], + [10452.], + [42.], + [9652.], + [1090532.], + [900122.], + [729732.], + [2090652.], + [1900242.], + [1729852.], + [1010532.], + [1000122.], + [1009732.], + [2090612.], + [1900202.], + [1729812.], + [1899322.], + [1710892.], + [1542482.], + [819202.], + [810772.], + [822362.], + [1899282.], + [1710852.], + [1542442.], + [1099202.], + [910772.], + [742362.], + [19082.], + [10652.], + [22242.], + [1099162.], + [910732.], + [742322.], + [1899282.], + [1710852.], + [1542442.], + [819162.], + [810732.], + [822322.], + [1899242.], + [1710812.], + [1542402.], + ]) + outputs = obj_fun(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [2304082.], + [2111692.], + [1939322.], + [1223962.], + [1211572.], + [1219202.], + [2304042.], + [2111652.], + [1939282.], + [1103962.], + [911572.], + [739202.], + [23842.], + [11452.], + [19082.], + [1103922.], + [911532.], + [739162.], + [2304042.], + [2111652.], + [1939282.], + [1223922.], + [1211532.], + [1219162.], + [2304002.], + [2111612.], + [1939242.], + [2090692.], + [1900282.], + [1729892.], + [1010572.], + [1000162.], + [1009772.], + [2090652.], + [1900242.], + [1729852.], + [1090572.], + [900162.], + [729772.], + [10452.], + [42.], + [9652.], + [1090532.], + [900122.], + [729732.], + [2090652.], + [1900242.], + [1729852.], + [1010532.], + [1000122.], + [1009732.], + [2090612.], + [1900202.], + [1729812.], + [1899322.], + [1710892.], + [1542482.], + [819202.], + [810772.], + [822362.], + [1899282.], + [1710852.], + [1542442.], + [1099202.], + [910772.], + [742362.], + [19082.], + [10652.], + [22242.], + [1099162.], + [910732.], + [742322.], + [1899282.], + [1710852.], + [1542442.], + [819162.], + [810732.], + [822322.], + [1899242.], + [1710812.], + [1542402.], + ]) + outputs = obj_fun(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_global_minimum.py b/tests/test_global_minimum.py index 8269c03..734bd03 100644 --- a/tests/test_global_minimum.py +++ b/tests/test_global_minimum.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: July 12, 2021 +# last updated: January 3, 2023 # import numpy as np @@ -14,7 +14,9 @@ from bayeso_benchmarks import Kim1 from bayeso_benchmarks import Kim2 from bayeso_benchmarks import Kim3 +from bayeso_benchmarks import Rastrigin from bayeso_benchmarks import Michalewicz +from bayeso_benchmarks import Shubert TEST_EPSILON = 1e-7 @@ -36,7 +38,7 @@ def _test_global_minimum(obj_fun): ind_minimum = np.argmin(np.squeeze(list_by)) bx_best = list_bx[ind_minimum] - y_best = list_by[ind_minimum][0] + y_best = list_by[ind_minimum] print(bx_best) print(obj_fun.global_minimum) @@ -93,8 +95,8 @@ def test_global_minimum_kim3(): _test_global_minimum(obj_fun) -def test_global_minimum_michalewicz(): - class_fun = Michalewicz +def test_global_minimum_shubert(): + class_fun = Shubert obj_fun = class_fun() _test_global_minimum(obj_fun) diff --git a/tests/test_import.py b/tests/test_import.py index 100bee6..d5fa8ef 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,12 +1,70 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: January 4, 2023 # def test_import_benchmarks(): import bayeso_benchmarks +def test_all_benchmarks(): + import bayeso_benchmarks + + list_str_names = [ + 'ackley', + 'cosines', + 'levy', + 'rastrigin', + 'rosenbrock', + 'sphere', + 'zakharov', + 'constant', + 'gramacyandlee2012', + 'linear', + 'step', + 'colville', + 'hartmann3d', + 'hartmann6d', + 'beale', + 'bohachevsky', + 'branin', + 'bukin6', + 'dejong5', + 'dropwave', + 'easom', + 'eggholder', + 'goldsteinprice', + 'holdertable', + 'kim1', + 'kim2', + 'kim3', + 'michalewicz', + 'shubert', + 'sixhumpcamel', + 'threehumpcamel', + ] + + names = [] + for class_benchmark in bayeso_benchmarks.all_benchmarks: + print(class_benchmark.__name__.lower()) + names.append(class_benchmark.__name__.lower()) + + for str_name in list_str_names: + assert str_name in names + + qualnames = [] + for class_benchmark in bayeso_benchmarks.all_benchmarks: + print(class_benchmark.__qualname__.lower()) + qualnames.append(class_benchmark.__qualname__.lower()) + + for str_name in list_str_names: + assert str_name in qualnames + +def test_num_benchmarks(): + import bayeso_benchmarks + + assert bayeso_benchmarks.num_benchmarks == 32 + def test_import_benchmark_base(): import bayeso_benchmarks.benchmark_base from bayeso_benchmarks.benchmark_base import Function @@ -46,11 +104,21 @@ def test_import_two_dim_branin(): from bayeso_benchmarks.two_dim_branin import Branin from bayeso_benchmarks import Branin +def test_import_two_dim_bukin6(): + import bayeso_benchmarks.two_dim_bukin6 + from bayeso_benchmarks.two_dim_bukin6 import Bukin6 + from bayeso_benchmarks import Bukin6 + def test_import_two_dim_dropwave(): import bayeso_benchmarks.two_dim_dropwave from bayeso_benchmarks.two_dim_dropwave import DropWave from bayeso_benchmarks import DropWave +def test_import_two_dim_easom(): + import bayeso_benchmarks.two_dim_easom + from bayeso_benchmarks.two_dim_easom import Easom + from bayeso_benchmarks import Easom + def test_import_two_dim_eggholder(): import bayeso_benchmarks.two_dim_eggholder from bayeso_benchmarks.two_dim_eggholder import Eggholder @@ -86,6 +154,11 @@ def test_import_two_dim_michalewicz(): from bayeso_benchmarks.two_dim_michalewicz import Michalewicz from bayeso_benchmarks import Michalewicz +def test_import_two_dim_shubert(): + import bayeso_benchmarks.two_dim_shubert + from bayeso_benchmarks.two_dim_shubert import Shubert + from bayeso_benchmarks import Shubert + def test_import_two_dim_sixhumpcamel(): import bayeso_benchmarks.two_dim_sixhumpcamel from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel @@ -96,6 +169,11 @@ def test_import_two_dim_threehumpcamel(): from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel from bayeso_benchmarks import ThreeHumpCamel +def test_import_four_dim_colville(): + import bayeso_benchmarks.four_dim_colville + from bayeso_benchmarks.four_dim_colville import Colville + from bayeso_benchmarks import Colville + def test_import_three_dim_hartmann3d(): import bayeso_benchmarks.three_dim_hartmann3d from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D @@ -111,6 +189,26 @@ def test_import_inf_dim_ackley(): from bayeso_benchmarks.inf_dim_ackley import Ackley from bayeso_benchmarks import Ackley +def test_import_inf_dim_cosines(): + import bayeso_benchmarks.inf_dim_cosines + from bayeso_benchmarks.inf_dim_cosines import Cosines + from bayeso_benchmarks import Cosines + +def test_import_inf_dim_griewank(): + import bayeso_benchmarks.inf_dim_griewank + from bayeso_benchmarks.inf_dim_griewank import Griewank + from bayeso_benchmarks import Griewank + +def test_import_inf_dim_levy(): + import bayeso_benchmarks.inf_dim_levy + from bayeso_benchmarks.inf_dim_levy import Levy + from bayeso_benchmarks import Levy + +def test_import_inf_dim_rastrigin(): + import bayeso_benchmarks.inf_dim_rastrigin + from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin + from bayeso_benchmarks import Rastrigin + def test_import_inf_dim_rosenbrock(): import bayeso_benchmarks.inf_dim_rosenbrock from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock @@ -120,3 +218,8 @@ def test_import_inf_dim_sphere(): import bayeso_benchmarks.inf_dim_sphere from bayeso_benchmarks.inf_dim_sphere import Sphere from bayeso_benchmarks import Sphere + +def test_import_inf_dim_zakharov(): + import bayeso_benchmarks.inf_dim_zakharov + from bayeso_benchmarks.inf_dim_zakharov import Zakharov + from bayeso_benchmarks import Zakharov diff --git a/tests/test_inf_dim_ackley.py b/tests/test_inf_dim_ackley.py index f78150f..285a087 100644 --- a/tests/test_inf_dim_ackley.py +++ b/tests/test_inf_dim_ackley.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.inf_dim_ackley import * class_fun = Ackley +str_name = 'ackley' TEST_EPSILON = 1e-5 @@ -70,3 +71,56 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun(3) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [2.15703112e+01], + [2.11187470e+01], + [2.15703112e+01], + [2.11187470e+01], + [2.02411230e+01], + [2.11187470e+01], + [2.15703112e+01], + [2.11187470e+01], + [2.15703112e+01], + [2.11187470e+01], + [2.02411230e+01], + [2.11187470e+01], + [2.02411230e+01], + [4.44089210e-16], + [2.02411230e+01], + [2.11187470e+01], + [2.02411230e+01], + [2.11187470e+01], + [2.15703112e+01], + [2.11187470e+01], + [2.15703112e+01], + [2.11187470e+01], + [2.02411230e+01], + [2.11187470e+01], + [2.15703112e+01], + [2.11187470e+01], + [2.15703112e+01], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_cosines.py b/tests/test_inf_dim_cosines.py index 3c12c46..c274d56 100644 --- a/tests/test_inf_dim_cosines.py +++ b/tests/test_inf_dim_cosines.py @@ -1,15 +1,15 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np import pytest from bayeso_benchmarks.inf_dim_cosines import * -# last updated: February 8, 2021 class_fun = Cosines +str_name = 'cosines' TEST_EPSILON = 1e-5 @@ -71,3 +71,16 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_griewank.py b/tests/test_inf_dim_griewank.py new file mode 100644 index 0000000..1a2322f --- /dev/null +++ b/tests/test_inf_dim_griewank.py @@ -0,0 +1,417 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 6, 2023 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.inf_dim_griewank import * + +class_fun = Griewank +str_name = 'griewank' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun(16) + + with pytest.raises(AssertionError) as error: + class_fun(1.0) + with pytest.raises(AssertionError) as error: + class_fun('abc') + with pytest.raises(AssertionError) as error: + class_fun(4, seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(4, seed='abc') + +def test_validate_properties(): + obj_fun = class_fun(8) + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun(4) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [361.01465247], + [270.33689088], + [361.01465247], + [271.02183025], + [180.01205465], + [271.02183025], + [361.01465247], + [270.33689088], + [361.01465247], + [270.98533321], + [181.66375729], + [270.98533321], + [180.97814841], + [91.98891104], + [180.97814841], + [270.98533321], + [181.66375729], + [270.98533321], + [361.01465247], + [270.33689088], + [361.01465247], + [271.02183025], + [180.01205465], + [271.02183025], + [361.01465247], + [270.33689088], + [361.01465247], + [270.98518323], + [181.67054476], + [270.98518323], + [180.97792496], + [91.99902348], + [180.97792496], + [270.98518323], + [181.67054476], + [270.98518323], + [181.01483126], + [90.3287998], + [181.01483126], + [91.02209662], + [0.], + [91.02209662], + [181.01483126], + [90.3287998], + [181.01483126], + [270.98518323], + [181.67054476], + [270.98518323], + [180.97792496], + [91.99902348], + [180.97792496], + [270.98518323], + [181.67054476], + [270.98518323], + [361.01465247], + [270.33689088], + [361.01465247], + [271.02183025], + [180.01205465], + [271.02183025], + [361.01465247], + [270.33689088], + [361.01465247], + [270.98533321], + [181.66375729], + [270.98533321], + [180.97814841], + [91.98891104], + [180.97814841], + [270.98533321], + [181.66375729], + [270.98533321], + [361.01465247], + [270.33689088], + [361.01465247], + [271.02183025], + [180.01205465], + [271.02183025], + [361.01465247], + [270.33689088], + [361.01465247], + ]) + outputs = obj_fun.output(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun(2) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [180.01205465], + [91.98891104], + [180.01205465], + [91.99902348], + [0.], + [91.99902348], + [180.01205465], + [91.98891104], + [180.01205465], + ]) + outputs = obj_fun(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun(2) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [182.01205465], + [93.98891104], + [182.01205465], + [93.99902348], + [2.], + [93.99902348], + [182.01205465], + [93.98891104], + [182.01205465], + ]) + outputs = obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(4, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [362.00808078], + [270.06036228], + [362.31002955], + [274.06788997], + [179.5437479], + [270.55355634], + [364.1730781], + [271.87176034], + [360.0757037], + [272.07045329], + [180.73692191], + [270.0538737], + [181.46207295], + [88.16235055], + [177.52831274], + [269.86075815], + [179.63809505], + [271.61382787], + [359.19860432], + [267.51228348], + [363.94595001], + [270.57027765], + [180.14711106], + [268.17233388], + [359.92588702], + [270.55873606], + [358.71266531], + [271.73657926], + [180.46926738], + [270.40179573], + [179.77451173], + [95.70357985], + [180.95093051], + [268.86976137], + [183.31563459], + [268.54349593], + [181.43255845], + [86.40945955], + [178.35845916], + [91.41581909], + [1.47693316], + [91.36483318], + [180.78353469], + [89.72659241], + [178.05778727], + [269.54549481], + [180.74926722], + [273.09942768], + [181.66516154], + [88.47294317], + [181.6260929], + [270.21501867], + [180.31670076], + [272.20853581], + [363.07665151], + [272.19945112], + [359.33621742], + [270.4034055], + [180.67458151], + [272.97292051], + [360.05630399], + [269.96557293], + [358.80198252], + [268.59291996], + [183.28880894], + [273.69781326], + [180.83412817], + [93.99597684], + [181.70142046], + [269.6950937], + [182.3865485], + [274.06140634], + [360.94300039], + [273.46617819], + [355.77516226], + [272.66563526], + [180.18614879], + [270.42381555], + [361.19817402], + [266.36175305], + [360.57530869], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(4, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [361.01465247], + [270.33689088], + [362.31002955], + [274.06788997], + [179.5437479], + [270.55355634], + [361.01465247], + [270.33689088], + [361.01465247], + [270.98533321], + [181.66375729], + [270.0538737], + [180.97814841], + [91.98891104], + [180.97814841], + [270.98533321], + [181.66375729], + [271.61382787], + [359.19860432], + [270.33689088], + [361.01465247], + [271.02183025], + [180.14711106], + [271.02183025], + [361.01465247], + [270.55873606], + [358.71266531], + [270.98518323], + [181.67054476], + [270.98518323], + [180.97792496], + [91.99902348], + [180.97792496], + [270.98518323], + [181.67054476], + [268.54349593], + [181.01483126], + [90.3287998], + [178.35845916], + [91.41581909], + [0.], + [91.02209662], + [180.78353469], + [89.72659241], + [181.01483126], + [269.54549481], + [180.74926722], + [270.98518323], + [180.97792496], + [88.47294317], + [180.97792496], + [270.98518323], + [180.31670076], + [270.98518323], + [361.01465247], + [270.33689088], + [361.01465247], + [271.02183025], + [180.67458151], + [271.02183025], + [361.01465247], + [269.96557293], + [358.80198252], + [270.98533321], + [181.66375729], + [273.69781326], + [180.97814841], + [93.99597684], + [180.97814841], + [269.6950937], + [181.66375729], + [270.98533321], + [361.01465247], + [273.46617819], + [361.01465247], + [272.66563526], + [180.01205465], + [271.02183025], + [361.19817402], + [270.33689088], + [361.01465247], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(1, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [93.14825808], + [-2.16338047], + [94.63714051], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(2, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [181.16128925], + [89.82553057], + [180.01205465], + [91.99902348], + [0.], + [91.99902348], + [176.08376221], + [91.98891104], + [180.01205465], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_levy.py b/tests/test_inf_dim_levy.py new file mode 100644 index 0000000..0391023 --- /dev/null +++ b/tests/test_inf_dim_levy.py @@ -0,0 +1,1784 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: December 29, 2022 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.inf_dim_levy import * + +class_fun = Levy +str_name = 'levy' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun(16) + + with pytest.raises(AssertionError) as error: + class_fun(1.0) + with pytest.raises(AssertionError) as error: + class_fun('abc') + with pytest.raises(AssertionError) as error: + class_fun(4, seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(4, seed='abc') + +def test_validate_properties(): + obj_fun = class_fun(8) + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun(4) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [254.89842686], + [239.89842686], + [249.89842686], + [175.23146246], + [160.23146246], + [170.23146246], + [228.53220902], + [213.53220902], + [223.53220902], + [175.23146246], + [160.23146246], + [170.23146246], + [95.56449806], + [80.56449806], + [90.56449806], + [148.86524462], + [133.86524462], + [143.86524462], + [228.53220902], + [213.53220902], + [223.53220902], + [148.86524462], + [133.86524462], + [143.86524462], + [202.16599118], + [187.16599118], + [197.16599118], + [175.23146246], + [160.23146246], + [170.23146246], + [95.56449806], + [80.56449806], + [90.56449806], + [148.86524462], + [133.86524462], + [143.86524462], + [95.56449806], + [80.56449806], + [90.56449806], + [15.89753366], + [0.89753366], + [10.89753366], + [69.19828022], + [54.19828022], + [64.19828022], + [148.86524462], + [133.86524462], + [143.86524462], + [69.19828022], + [54.19828022], + [64.19828022], + [122.49902679], + [107.49902679], + [117.49902679], + [228.53220902], + [213.53220902], + [223.53220902], + [148.86524462], + [133.86524462], + [143.86524462], + [202.16599118], + [187.16599118], + [197.16599118], + [148.86524462], + [133.86524462], + [143.86524462], + [69.19828022], + [54.19828022], + [64.19828022], + [122.49902679], + [107.49902679], + [117.49902679], + [202.16599118], + [187.16599118], + [197.16599118], + [122.49902679], + [107.49902679], + [117.49902679], + [175.79977335], + [160.79977335], + [170.79977335], + ]) + outputs = obj_fun.output(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun(6) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [414.41404476], + [399.41404476], + [409.41404476], + [334.74708036], + [319.74708036], + [329.74708036], + [388.04782692], + [373.04782692], + [383.04782692], + [334.74708036], + [319.74708036], + [329.74708036], + [255.08011596], + [240.08011596], + [250.08011596], + [308.38086253], + [293.38086253], + [303.38086253], + [388.04782692], + [373.04782692], + [383.04782692], + [308.38086253], + [293.38086253], + [303.38086253], + [361.68160909], + [346.68160909], + [356.68160909], + [334.74708036], + [319.74708036], + [329.74708036], + [255.08011596], + [240.08011596], + [250.08011596], + [308.38086253], + [293.38086253], + [303.38086253], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [160.41315157], + [170.41315157], + [228.71389813], + [213.71389813], + [223.71389813], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [388.04782692], + [373.04782692], + [383.04782692], + [308.38086253], + [293.38086253], + [303.38086253], + [361.68160909], + [346.68160909], + [356.68160909], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [334.74708036], + [319.74708036], + [329.74708036], + [255.08011596], + [240.08011596], + [250.08011596], + [308.38086253], + [293.38086253], + [303.38086253], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [160.41315157], + [170.41315157], + [228.71389813], + [213.71389813], + [223.71389813], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [160.41315157], + [170.41315157], + [228.71389813], + [213.71389813], + [223.71389813], + [175.41315157], + [160.41315157], + [170.41315157], + [95.74618717], + [80.74618717], + [90.74618717], + [149.04693373], + [134.04693373], + [144.04693373], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [388.04782692], + [373.04782692], + [383.04782692], + [308.38086253], + [293.38086253], + [303.38086253], + [361.68160909], + [346.68160909], + [356.68160909], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [335.31539125], + [320.31539125], + [330.31539125], + [255.64842686], + [240.64842686], + [250.64842686], + [308.94917342], + [293.94917342], + [303.94917342], + [334.74708036], + [319.74708036], + [329.74708036], + [255.08011596], + [240.08011596], + [250.08011596], + [308.38086253], + [293.38086253], + [303.38086253], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [160.41315157], + [170.41315157], + [228.71389813], + [213.71389813], + [223.71389813], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [160.41315157], + [170.41315157], + [228.71389813], + [213.71389813], + [223.71389813], + [175.41315157], + [160.41315157], + [170.41315157], + [95.74618717], + [80.74618717], + [90.74618717], + [149.04693373], + [134.04693373], + [144.04693373], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [160.41315157], + [170.41315157], + [228.71389813], + [213.71389813], + [223.71389813], + [175.41315157], + [160.41315157], + [170.41315157], + [95.74618717], + [80.74618717], + [90.74618717], + [149.04693373], + [134.04693373], + [144.04693373], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [175.41315157], + [160.41315157], + [170.41315157], + [95.74618717], + [80.74618717], + [90.74618717], + [149.04693373], + [134.04693373], + [144.04693373], + [95.74618717], + [80.74618717], + [90.74618717], + [16.07922277], + [1.07922277], + [11.07922277], + [69.37996933], + [54.37996933], + [64.37996933], + [149.04693373], + [134.04693373], + [144.04693373], + [69.37996933], + [54.37996933], + [64.37996933], + [122.6807159], + [107.6807159], + [117.6807159], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [149.04693373], + [134.04693373], + [144.04693373], + [69.37996933], + [54.37996933], + [64.37996933], + [122.6807159], + [107.6807159], + [117.6807159], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [175.98146246], + [160.98146246], + [170.98146246], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [149.04693373], + [134.04693373], + [144.04693373], + [69.37996933], + [54.37996933], + [64.37996933], + [122.6807159], + [107.6807159], + [117.6807159], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [175.98146246], + [160.98146246], + [170.98146246], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [175.98146246], + [160.98146246], + [170.98146246], + [255.64842686], + [240.64842686], + [250.64842686], + [175.98146246], + [160.98146246], + [170.98146246], + [229.28220902], + [214.28220902], + [224.28220902], + [388.04782692], + [373.04782692], + [383.04782692], + [308.38086253], + [293.38086253], + [303.38086253], + [361.68160909], + [346.68160909], + [356.68160909], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [335.31539125], + [320.31539125], + [330.31539125], + [255.64842686], + [240.64842686], + [250.64842686], + [308.94917342], + [293.94917342], + [303.94917342], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [149.04693373], + [134.04693373], + [144.04693373], + [69.37996933], + [54.37996933], + [64.37996933], + [122.6807159], + [107.6807159], + [117.6807159], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [175.98146246], + [160.98146246], + [170.98146246], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [175.98146246], + [160.98146246], + [170.98146246], + [255.64842686], + [240.64842686], + [250.64842686], + [175.98146246], + [160.98146246], + [170.98146246], + [229.28220902], + [214.28220902], + [224.28220902], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [335.31539125], + [320.31539125], + [330.31539125], + [255.64842686], + [240.64842686], + [250.64842686], + [308.94917342], + [293.94917342], + [303.94917342], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [175.98146246], + [160.98146246], + [170.98146246], + [255.64842686], + [240.64842686], + [250.64842686], + [175.98146246], + [160.98146246], + [170.98146246], + [229.28220902], + [214.28220902], + [224.28220902], + [335.31539125], + [320.31539125], + [330.31539125], + [255.64842686], + [240.64842686], + [250.64842686], + [308.94917342], + [293.94917342], + [303.94917342], + [255.64842686], + [240.64842686], + [250.64842686], + [175.98146246], + [160.98146246], + [170.98146246], + [229.28220902], + [214.28220902], + [224.28220902], + [308.94917342], + [293.94917342], + [303.94917342], + [229.28220902], + [214.28220902], + [224.28220902], + [282.58295558], + [267.58295558], + [277.58295558], + ]) + outputs = obj_fun(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun(2) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [97.38280895], + [17.71584455], + [71.01659112], + [82.38280895], + [2.71584455], + [56.01659112], + [92.38280895], + [12.71584455], + [66.01659112], + ]) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(4, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [255.89185516], + [239.62189825], + [251.19380393], + [178.27752217], + [159.76315571], + [169.76318854], + [231.69063465], + [215.06707848], + [222.59326025], + [176.31658254], + [159.30462707], + [169.30000295], + [96.0484226], + [76.73793757], + [87.1146624], + [147.74066956], + [131.83958238], + [144.49373929], + [226.71616087], + [210.70760162], + [226.46350656], + [148.41369202], + [134.00030103], + [141.01574825], + [201.07722574], + [187.38783636], + [194.86400403], + [175.98285849], + [159.03018508], + [169.64807496], + [94.36108484], + [84.26905443], + [90.53750361], + [146.74982276], + [135.51033445], + [141.42355732], + [95.98222525], + [76.64515781], + [87.90812596], + [16.29125613], + [2.37446682], + [11.24027022], + [68.96698366], + [53.59607283], + [61.24123624], + [147.42555621], + [132.94396708], + [145.97948907], + [69.8855168], + [50.67219991], + [64.84644816], + [121.72886223], + [106.14518279], + [118.72237936], + [230.59420807], + [215.39476926], + [221.85377397], + [148.24681987], + [134.52777149], + [145.81633488], + [201.20764271], + [186.79467323], + [194.95332124], + [146.47283137], + [135.49029627], + [146.57772468], + [69.05425998], + [56.20534602], + [64.92155227], + [121.20878728], + [108.221818], + [120.57509992], + [202.09433911], + [190.2952785], + [191.92650098], + [124.1428318], + [107.67312092], + [116.90101209], + [175.9832949], + [156.82463552], + [170.36042957], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(6, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [415.40747307], + [399.41404476], + [410.70942184], + [334.74708036], + [319.27877361], + [329.74708036], + [388.04782692], + [373.04782692], + [382.10887815], + [335.83220045], + [318.82024498], + [329.74708036], + [255.08011596], + [240.08011596], + [250.08011596], + [308.38086253], + [291.35520029], + [303.38086253], + [388.04782692], + [373.04782692], + [383.04782692], + [307.92930993], + [293.51591894], + [303.38086253], + [360.59284364], + [346.68160909], + [354.37962193], + [334.74708036], + [318.54580298], + [329.74708036], + [255.08011596], + [243.78467233], + [250.08011596], + [308.38086253], + [293.38086253], + [303.38086253], + [255.08011596], + [236.16077572], + [247.42374387], + [175.80687404], + [160.41315157], + [170.75588813], + [228.71389813], + [213.71389813], + [223.71389813], + [308.38086253], + [292.45958498], + [305.49510698], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [265.66080069], + [277.01464469], + [388.04782692], + [373.04782692], + [381.36939188], + [308.38086253], + [293.38086253], + [305.33195278], + [361.68160909], + [346.31029114], + [356.68160909], + [308.38086253], + [295.00591417], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [361.60995701], + [346.68160909], + [351.44211888], + [282.01464469], + [267.01464469], + [276.41662999], + [335.31539125], + [320.31539125], + [329.87604748], + [334.74708036], + [319.74708036], + [328.71053992], + [255.08011596], + [239.07660188], + [250.08011596], + [308.38086253], + [293.38086253], + [303.38086253], + [255.08011596], + [240.08011596], + [250.08011596], + [175.41315157], + [159.62893526], + [170.41315157], + [229.30613868], + [214.23600867], + [223.72412504], + [308.38086253], + [293.38086253], + [303.38086253], + [228.0284691], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [255.08011596], + [240.08011596], + [246.24257353], + [175.36012382], + [160.41315157], + [175.33963579], + [228.71389813], + [213.71389813], + [223.71389813], + [175.41315157], + [160.41315157], + [170.41315157], + [95.74618717], + [80.74618717], + [90.74618717], + [149.04693373], + [134.04693373], + [144.04693373], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [130.94560687], + [144.18405968], + [202.34768029], + [188.29486515], + [195.50883182], + [311.48073134], + [291.81435594], + [302.73673949], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [263.79967822], + [277.01464469], + [228.71389813], + [215.27754387], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [188.04057671], + [197.34768029], + [282.47915209], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [194.9650733], + [256.96153407], + [238.69906352], + [252.22259606], + [388.04782692], + [373.04782692], + [384.97457918], + [308.38086253], + [293.38086253], + [303.38086253], + [361.68160909], + [345.17413676], + [356.68160909], + [308.38086253], + [293.38086253], + [304.06316648], + [228.71389813], + [215.36826463], + [223.73990191], + [282.01464469], + [267.01464469], + [277.01464469], + [362.93294378], + [346.68160909], + [354.53982409], + [282.97958952], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.31539125], + [308.38086253], + [292.48783262], + [303.38086253], + [228.71389813], + [211.22242057], + [223.71389813], + [282.01464469], + [265.24692982], + [277.3220949], + [228.71389813], + [211.42795753], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [268.04474006], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [271.64396182], + [277.01464469], + [335.31539125], + [317.08995951], + [330.31539125], + [284.19254588], + [267.01464469], + [277.01464469], + [200.91707287], + [187.34768029], + [197.34768029], + [255.64842686], + [240.73957054], + [249.34522616], + [335.31539125], + [320.31539125], + [330.31539125], + [256.02133549], + [240.64842686], + [250.64842686], + [308.94917342], + [293.71970054], + [303.94917342], + [334.74708036], + [319.74708036], + [329.74708036], + [255.08011596], + [240.08011596], + [253.61102444], + [308.38086253], + [293.38086253], + [305.21658642], + [255.08011596], + [240.08011596], + [247.04137603], + [175.41315157], + [160.41315157], + [170.41315157], + [229.60153698], + [213.71389813], + [223.71389813], + [308.38086253], + [293.38086253], + [301.33208724], + [228.71389813], + [211.21833176], + [226.97872074], + [282.01464469], + [267.01464469], + [277.01464469], + [255.08011596], + [240.08011596], + [252.40644347], + [175.41315157], + [160.41315157], + [170.41315157], + [229.11201752], + [213.71389813], + [223.71389813], + [174.64252437], + [160.64018626], + [170.41315157], + [95.74618717], + [78.27055617], + [90.74618717], + [145.14275813], + [134.04693373], + [144.04693373], + [228.71389813], + [213.71389813], + [223.71389813], + [148.06093186], + [134.04693373], + [144.04693373], + [202.34768029], + [185.9618611], + [199.14688004], + [308.99546157], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [283.23538522], + [267.01464469], + [277.01464469], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [133.61157132], + [146.24448743], + [202.34768029], + [187.34768029], + [197.34768029], + [282.01464469], + [268.37855063], + [276.39411118], + [202.34768029], + [187.34768029], + [197.54167222], + [255.64842686], + [239.01198549], + [250.64842686], + [253.0680812], + [240.08011596], + [250.08011596], + [175.41315157], + [161.6613912], + [171.66984258], + [228.71389813], + [213.71389813], + [223.71389813], + [174.05882814], + [160.41315157], + [170.41315157], + [95.74618717], + [80.10341549], + [90.74618717], + [147.91948463], + [132.40249294], + [144.04693373], + [229.20383127], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [141.23200618], + [202.34768029], + [187.34768029], + [197.96949542], + [175.41315157], + [162.12847081], + [170.09327451], + [95.74618717], + [78.74112844], + [90.74618717], + [149.04693373], + [134.04693373], + [142.39247184], + [96.7848802], + [83.81166499], + [90.74618717], + [16.07922277], + [2.45951075], + [11.07922277], + [69.8281543], + [54.37996933], + [64.37996933], + [149.04693373], + [134.04693373], + [144.04693373], + [69.37996933], + [54.37996933], + [68.68633425], + [122.6807159], + [107.6807159], + [117.6807159], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [129.79914228], + [142.99542369], + [200.82941497], + [187.64846787], + [197.34768029], + [152.79927541], + [134.04693373], + [144.04693373], + [67.58313999], + [54.37996933], + [64.37996933], + [122.6807159], + [107.6807159], + [117.6807159], + [198.92141123], + [187.34768029], + [197.34768029], + [122.6807159], + [104.49186058], + [117.6807159], + [175.99194986], + [161.07542365], + [170.08133151], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [279.56999833], + [228.71389813], + [213.71389813], + [223.71389813], + [149.04693373], + [134.04693373], + [144.04693373], + [202.34768029], + [187.34768029], + [196.849752], + [282.01464469], + [267.01464469], + [279.75190781], + [202.34768029], + [187.34768029], + [197.34768029], + [252.13094788], + [240.64842686], + [250.64842686], + [228.17508446], + [215.14898264], + [223.71389813], + [149.19512329], + [134.04693373], + [144.04693373], + [198.94091541], + [187.34768029], + [197.34768029], + [149.04693373], + [134.04693373], + [144.04693373], + [66.77103033], + [54.37996933], + [64.37996933], + [120.80095632], + [107.6807159], + [117.6807159], + [202.34768029], + [189.25796493], + [197.34768029], + [122.6807159], + [106.62020066], + [116.09497023], + [175.76740174], + [160.98146246], + [170.98146246], + [282.01464469], + [267.01464469], + [277.08517179], + [202.34768029], + [187.34768029], + [197.12302419], + [255.20648766], + [241.87676026], + [250.64842686], + [202.34768029], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [179.27139788], + [160.48339038], + [172.13457638], + [256.27092716], + [240.64842686], + [250.64842686], + [175.72562727], + [159.07038158], + [170.98146246], + [229.28220902], + [214.28220902], + [224.28220902], + [386.75468116], + [370.88473092], + [383.04782692], + [308.38086253], + [293.36491724], + [303.38086253], + [361.68160909], + [346.68160909], + [356.68160909], + [308.38086253], + [293.38086253], + [303.38086253], + [226.96266162], + [210.94829867], + [223.71389813], + [282.01464469], + [264.21750954], + [277.01464469], + [361.68160909], + [345.70735832], + [356.68160909], + [282.01464469], + [267.01464469], + [275.35274446], + [335.31539125], + [320.31539125], + [330.31539125], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.91256274], + [282.01464469], + [267.01464469], + [277.01464469], + [227.38865061], + [213.71389813], + [223.71389813], + [149.04693373], + [130.79184885], + [144.04693373], + [202.34768029], + [185.53904704], + [197.34768029], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [361.68160909], + [346.68160909], + [356.68160909], + [282.01464469], + [267.01464469], + [275.42085418], + [335.31539125], + [319.90930048], + [330.31539125], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [198.02288562], + [255.64842686], + [239.67321441], + [249.78331048], + [335.31539125], + [320.31539125], + [330.31539125], + [255.64842686], + [240.64842686], + [250.64842686], + [308.94917342], + [293.94917342], + [299.87292435], + [308.38086253], + [293.38086253], + [303.38086253], + [228.71389813], + [213.71389813], + [223.71389813], + [282.01464469], + [267.01464469], + [277.01464469], + [228.71389813], + [215.25562852], + [220.75672564], + [151.33444182], + [134.04693373], + [144.04693373], + [203.61324403], + [187.34768029], + [197.7114128], + [282.01464469], + [267.01464469], + [275.31495595], + [202.34768029], + [185.63551264], + [197.49081277], + [255.64842686], + [240.64842686], + [250.64842686], + [228.71389813], + [213.71389813], + [223.71389813], + [147.0894063], + [134.04693373], + [144.80153472], + [203.86165753], + [187.34768029], + [199.08689213], + [149.04693373], + [134.04693373], + [147.80052536], + [69.37996933], + [51.89065993], + [64.37996933], + [122.6807159], + [107.6807159], + [117.6807159], + [202.90761755], + [187.34768029], + [197.34768029], + [122.6807159], + [107.6807159], + [117.6807159], + [176.94348092], + [161.42923051], + [170.98146246], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [186.32524894], + [197.34768029], + [255.39685302], + [240.64842686], + [250.64842686], + [202.34768029], + [190.40678093], + [197.34768029], + [122.6807159], + [107.6807159], + [114.37100255], + [175.98146246], + [160.98146246], + [168.40154066], + [253.05826931], + [239.97685746], + [250.64842686], + [175.98146246], + [160.98146246], + [170.48997633], + [229.28220902], + [214.28220902], + [224.28220902], + [361.68160909], + [348.07402182], + [356.68160909], + [282.01464469], + [267.01464469], + [277.01464469], + [335.31539125], + [320.31539125], + [330.34324984], + [281.96639452], + [267.01464469], + [277.01464469], + [201.20035628], + [186.25396241], + [197.28217375], + [255.64842686], + [239.22273529], + [250.64842686], + [334.80543682], + [320.31539125], + [325.01345164], + [255.64842686], + [243.14059724], + [250.64842686], + [308.26379823], + [293.94917342], + [303.94917342], + [282.01464469], + [267.01464469], + [277.01464469], + [202.34768029], + [187.34768029], + [197.34768029], + [255.64842686], + [240.64842686], + [250.64842686], + [202.34768029], + [188.77367715], + [197.34768029], + [122.6807159], + [109.10263583], + [117.6807159], + [175.25953013], + [160.98146246], + [168.8193358], + [255.64842686], + [240.64842686], + [250.64842686], + [175.98146246], + [160.98146246], + [170.98146246], + [228.91240475], + [214.28220902], + [226.38022747], + [335.31539125], + [320.31539125], + [330.31539125], + [255.64842686], + [240.64842686], + [250.64842686], + [304.7853146], + [293.94917342], + [304.37120835], + [255.64842686], + [240.64842686], + [250.64842686], + [175.90619305], + [160.98146246], + [171.20991776], + [229.28220902], + [213.5549846], + [224.28220902], + [308.94917342], + [293.94917342], + [303.94917342], + [229.28220902], + [214.28220902], + [224.28220902], + [282.58295558], + [267.58295558], + [277.58295558], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(1, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [16.7742346], + [-1.53838047], + [13.26311703], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(2, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [96.53204355], + [13.55246408], + [69.01659112], + [80.38280895], + [0.71584455], + [54.01659112], + [86.45451651], + [10.71584455], + [64.01659112], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_rastrigin.py b/tests/test_inf_dim_rastrigin.py new file mode 100644 index 0000000..9219b55 --- /dev/null +++ b/tests/test_inf_dim_rastrigin.py @@ -0,0 +1,1784 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: December 20, 2022 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.inf_dim_rastrigin import * + +class_fun = Rastrigin +str_name = 'rastrigin' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun(16) + + with pytest.raises(AssertionError) as error: + class_fun(1.0) + with pytest.raises(AssertionError) as error: + class_fun('abc') + with pytest.raises(AssertionError) as error: + class_fun(4, seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(4, seed='abc') + +def test_validate_properties(): + obj_fun = class_fun(8) + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun(4) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [28.92471373], + [0.00000000], + [28.92471373], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + ]) + outputs = obj_fun.output(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun(6) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [28.92471373], + [0.00000000], + [28.92471373], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + ]) + outputs = obj_fun(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun(2) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [59.84942745], + [30.92471373], + [59.84942745], + [30.92471373], + [2.0], + [30.92471373], + [59.84942745], + [30.92471373], + [59.84942745], + ]) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(4, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [116.69228321], + [86.49761258], + [116.99423198], + [89.82020089], + [57.38112070], + [86.30586726], + [118.85728053], + [88.30901064], + [114.75990613], + [87.85926126], + [56.92259207], + [85.84268167], + [58.33335199], + [25.09815324], + [54.39959179], + [85.64956612], + [55.82376521], + [87.40263584], + [113.88280675], + [83.94953377], + [118.63015244], + [86.32258858], + [57.98448386], + [83.92464480], + [114.61008945], + [86.99598636], + [113.39686775], + [87.52553721], + [56.64815007], + [86.19075368], + [56.64601423], + [32.62927009], + [57.82243300], + [84.65871932], + [59.49451728], + [84.33245388], + [58.26715464], + [25.00537348], + [55.19305535], + [29.31843620], + [1.47693316], + [29.26745029], + [57.61813089], + [28.32250633], + [54.89238347], + [85.33445276], + [56.92814991], + [88.88838563], + [58.53666403], + [25.39863342], + [58.49759539], + [86.00397662], + [56.49558345], + [87.99749376], + [117.76085395], + [88.63670142], + [114.02041986], + [86.15571643], + [58.51195431], + [88.72523143], + [114.74050643], + [86.40282322], + [113.48618496], + [84.38172793], + [59.47447910], + [89.48662123], + [57.70540721], + [30.93177952], + [58.57269950], + [85.48390167], + [58.57221866], + [89.85021431], + [115.62720282], + [89.90342849], + [110.45936469], + [88.41794619], + [58.02352159], + [86.17612648], + [115.88237646], + [82.79900335], + [115.25951113], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(6, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [174.54171066], + [144.62356863], + [174.84365943], + [144.62356863], + [115.23054815], + [144.62356863], + [173.54828235], + [144.62356863], + [172.60933358], + [145.70868872], + [114.77201952], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [113.67319266], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.17201603], + [115.83391131], + [144.62356863], + [172.45951691], + [144.62356863], + [171.24629520], + [144.62356863], + [114.49757752], + [144.62356863], + [115.69885490], + [90.47869755], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [82.85480093], + [113.04248281], + [87.16786365], + [57.84942745], + [87.11687774], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [114.77757736], + [146.73781308], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [114.34501090], + [144.62356863], + [173.54828235], + [144.62356863], + [171.86984731], + [144.62356863], + [115.69885490], + [146.57465888], + [173.54828235], + [144.25225068], + [173.54828235], + [144.62356863], + [117.32390655], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.47663028], + [144.62356863], + [168.30879215], + [144.62356863], + [115.69885490], + [144.02555393], + [173.54828235], + [144.62356863], + [173.10893858], + [144.62356863], + [115.69885490], + [143.58702819], + [115.69885490], + [85.77062709], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.06521115], + [86.77414118], + [116.29109546], + [87.29625172], + [115.70908182], + [144.62356863], + [115.69885490], + [144.62356863], + [115.01342587], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [111.86131247], + [86.72111343], + [57.84942745], + [91.70062540], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [54.74810059], + [86.91126713], + [115.69885490], + [87.72132604], + [113.86000643], + [147.72343744], + [114.13234832], + [143.97944560], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [112.48388843], + [144.62356863], + [115.69885490], + [88.33778692], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [87.46703760], + [115.69885490], + [145.08807602], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [113.31624791], + [145.93667585], + [113.74949156], + [146.19773784], + [173.54828235], + [144.62356863], + [175.47503461], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [143.11609630], + [173.54828235], + [144.62356863], + [115.69885490], + [145.30587258], + [115.69885490], + [88.42850768], + [115.72485869], + [144.62356863], + [115.69885490], + [144.62356863], + [174.79961705], + [144.62356863], + [171.40649736], + [145.58851346], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [114.80582500], + [144.62356863], + [115.69885490], + [84.28266362], + [115.69885490], + [144.62356863], + [113.93114003], + [144.93101884], + [115.69885490], + [84.48820058], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [116.72895028], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [120.32817204], + [144.62356863], + [173.54828235], + [141.39813689], + [173.54828235], + [146.80146982], + [115.69885490], + [144.62356863], + [114.26824748], + [86.77414118], + [115.69885490], + [144.62356863], + [115.78999858], + [143.32036793], + [173.54828235], + [144.62356863], + [173.54828235], + [144.99647726], + [115.69885490], + [144.62356863], + [173.54828235], + [144.39409575], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [119.22976338], + [144.62356863], + [115.69885490], + [146.45929252], + [115.69885490], + [86.77414118], + [112.66011497], + [86.77414118], + [57.84942745], + [86.77414118], + [116.58649376], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [142.57479335], + [115.69885490], + [84.27857481], + [118.96367751], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [118.02518241], + [86.77414118], + [57.84942745], + [86.77414118], + [116.09697429], + [86.77414118], + [115.69885490], + [86.00351398], + [58.07646214], + [86.77414118], + [57.84942745], + [26.44908273], + [57.84942745], + [82.86996558], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [85.78813931], + [57.84942745], + [86.77414118], + [115.69885490], + [85.38832199], + [117.49805465], + [145.23816767], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [145.84430916], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.41406505], + [88.97169488], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [117.06276085], + [144.00303512], + [115.69885490], + [86.77414118], + [115.89284683], + [144.62356863], + [114.06241354], + [144.62356863], + [113.68682014], + [86.77414118], + [115.69885490], + [86.77414118], + [59.09766709], + [88.03083220], + [115.69885490], + [86.77414118], + [115.69885490], + [85.41981775], + [57.84942745], + [86.77414118], + [57.84942745], + [28.28194204], + [57.84942745], + [85.64669207], + [56.20498666], + [86.77414118], + [116.18878805], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [83.95921363], + [115.69885490], + [86.77414118], + [116.32067003], + [86.77414118], + [59.56474670], + [86.45426412], + [57.84942745], + [26.91965500], + [57.84942745], + [86.77414118], + [57.84942745], + [85.11967929], + [58.88812048], + [31.99019155], + [57.84942745], + [28.92471373], + [1.38028798], + [28.92471373], + [58.29761242], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [57.84942745], + [28.92471373], + [62.15579237], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [53.60163600], + [85.72263113], + [114.18058958], + [87.07492875], + [115.69885490], + [90.52648286], + [57.84942745], + [86.77414118], + [56.05259811], + [28.92471373], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [112.27258584], + [86.77414118], + [115.69885490], + [86.77414118], + [54.66057213], + [86.77414118], + [115.70934230], + [86.86810236], + [114.79872396], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [147.17892227], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [115.69885490], + [86.77414118], + [115.20092661], + [144.62356863], + [115.69885490], + [147.36083174], + [115.69885490], + [86.77414118], + [115.69885490], + [141.10608966], + [115.69885490], + [144.62356863], + [115.16004123], + [88.20922569], + [115.69885490], + [86.92233074], + [57.84942745], + [86.77414118], + [112.29209002], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [55.24048845], + [28.92471373], + [57.84942745], + [84.89438160], + [57.84942745], + [86.77414118], + [115.69885490], + [88.68442582], + [115.69885490], + [86.77414118], + [56.78891221], + [85.18839551], + [115.48479418], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.69409573], + [115.69885490], + [86.77414118], + [115.47419880], + [144.18162943], + [116.92718830], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [118.98879033], + [86.27606910], + [116.85196883], + [145.24606894], + [115.69885490], + [144.62356863], + [115.44301972], + [84.86306030], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [172.25513659], + [142.46047262], + [173.54828235], + [144.62356863], + [115.68290962], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [113.94761840], + [84.00854172], + [115.69885490], + [144.62356863], + [112.90171976], + [144.62356863], + [173.54828235], + [143.64931786], + [173.54828235], + [144.62356863], + [115.69885490], + [142.96166840], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.89751951], + [144.62356863], + [115.69885490], + [144.62356863], + [114.37360739], + [86.77414118], + [115.69885490], + [86.77414118], + [54.59434258], + [86.77414118], + [115.69885490], + [84.96550793], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [143.02977812], + [173.54828235], + [144.21747786], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [116.37406023], + [144.62356863], + [114.72364245], + [143.75845225], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [169.47203328], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [88.31587157], + [112.74168241], + [89.06164926], + [57.84942745], + [86.77414118], + [116.96441864], + [86.77414118], + [116.06258741], + [144.62356863], + [115.69885490], + [142.92387989], + [115.69885490], + [85.06197353], + [115.84198738], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [84.81661375], + [57.84942745], + [87.52874216], + [117.21283214], + [86.77414118], + [117.43806674], + [86.77414118], + [57.84942745], + [90.52773280], + [57.84942745], + [26.43540432], + [57.84942745], + [86.77414118], + [57.84942745], + [86.77414118], + [116.25879216], + [86.77414118], + [115.69885490], + [86.77414118], + [57.84942745], + [86.77414118], + [116.66087337], + [87.22190923], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [85.75170982], + [115.69885490], + [144.37199479], + [115.69885490], + [144.62356863], + [115.69885490], + [89.83324182], + [115.69885490], + [86.77414118], + [57.84942745], + [83.46442783], + [115.69885490], + [86.77414118], + [113.11893310], + [142.03341108], + [115.02728550], + [144.62356863], + [115.69885490], + [86.77414118], + [115.20736877], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [146.01598136], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.57614094], + [144.57531845], + [115.69885490], + [144.62356863], + [114.55153089], + [85.68042329], + [115.63334836], + [144.62356863], + [114.27316334], + [144.62356863], + [173.03832792], + [144.62356863], + [168.24634274], + [144.62356863], + [118.19102529], + [144.62356863], + [172.86290717], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [88.20013804], + [115.69885490], + [86.77414118], + [59.27134739], + [86.77414118], + [114.97692257], + [86.77414118], + [113.53672825], + [144.62356863], + [115.69885490], + [144.62356863], + [115.69885490], + [86.77414118], + [115.69885490], + [144.25376436], + [115.69885490], + [146.72158708], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [169.38442354], + [144.62356863], + [173.97031729], + [144.62356863], + [115.69885490], + [144.62356863], + [115.62358550], + [86.77414118], + [115.92731020], + [144.62356863], + [114.97163048], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + [144.62356863], + [115.69885490], + [144.62356863], + [173.54828235], + [144.62356863], + [173.54828235], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(1, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [30.07394833], + [-2.16338047], + [31.56283076], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(2, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [58.99866205], + [26.76133325], + [57.84942745], + [28.92471373], + [0.0], + [28.92471373], + [53.92113501], + [28.92471373], + [57.84942745], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_rosenbrock.py b/tests/test_inf_dim_rosenbrock.py index 647f1a2..6fe5447 100644 --- a/tests/test_inf_dim_rosenbrock.py +++ b/tests/test_inf_dim_rosenbrock.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.inf_dim_rosenbrock import * class_fun = Rosenbrock +str_name = 'rosenbrock' TEST_EPSILON = 1e-5 @@ -70,3 +71,16 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_sphere.py b/tests/test_inf_dim_sphere.py index bca9569..a84d203 100644 --- a/tests/test_inf_dim_sphere.py +++ b/tests/test_inf_dim_sphere.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.inf_dim_sphere import * class_fun = Sphere +str_name = 'sphere' TEST_EPSILON = 1e-5 @@ -70,3 +71,16 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_inf_dim_zakharov.py b/tests/test_inf_dim_zakharov.py new file mode 100644 index 0000000..0a1aeb4 --- /dev/null +++ b/tests/test_inf_dim_zakharov.py @@ -0,0 +1,416 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 4, 2023 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.inf_dim_zakharov import * + +class_fun = Zakharov +str_name = 'zakharov' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun(16) + + with pytest.raises(AssertionError) as error: + class_fun(1.0) + with pytest.raises(AssertionError) as error: + class_fun('abc') + with pytest.raises(AssertionError) as error: + class_fun(4, seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(4, seed='abc') + +def test_validate_properties(): + obj_fun = class_fun(8) + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun(4) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [391350.], + [10181.25], + [825.], + [36014.94140625], + [66.50390625], + [70149.31640625], + [220.3125], + [24726.5625], + [572920.3125], + [204441.50390625], + [1627.44140625], + [6094.62890625], + [10162.5], + [693.75], + [160537.5], + [160.25390625], + [70130.56640625], + [954882.12890625], + [94270.3125], + [201.5625], + [24820.3125], + [1721.19140625], + [6075.87890625], + [318961.81640625], + [900.], + [160631.25], + [1502175.], + [94176.5625], + [107.8125], + [24726.5625], + [1627.44140625], + [5982.12890625], + [318868.06640625], + [806.25], + [160537.5], + [1502081.25], + [35996.19140625], + [47.75390625], + [70130.56640625], + [89.0625], + [24595.3125], + [572789.0625], + [6075.87890625], + [318849.31640625], + [2256404.00390625], + [10256.25], + [787.5], + [160631.25], + [141.50390625], + [70111.81640625], + [954863.37890625], + [24801.5625], + [572882.8125], + [3264651.5625], + [10275.], + [806.25], + [160650.], + [160.25390625], + [70130.56640625], + [954882.12890625], + [24820.3125], + [572901.5625], + [3264670.3125], + [1721.19140625], + [6075.87890625], + [318961.81640625], + [787.5], + [160518.75], + [1502062.5], + [70224.31640625], + [954863.37890625], + [4578033.69140625], + [295.3125], + [24801.5625], + [572995.3125], + [6169.62890625], + [318943.06640625], + [2256497.75390625], + [160725.], + [1502156.25], + [6252900.], + ]) + outputs = obj_fun.output(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun(2) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [3270.3125], + [243.06640625], + [125.], + [31.25], + [224.31640625], + [3326.5625], + [3345.3125], + [16250.87890625], + [51050.], + ]) + outputs = obj_fun(grids) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun(2) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [3.27231250e+03], + [2.45066406e+02], + [1.27000000e+02], + [3.32500000e+01], + [2.26316406e+02], + [3.32856250e+03], + [3.34731250e+03], + [1.62528789e+04], + [5.10520000e+04], + ]) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(4, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [391350.99342831], + [10180.9734714], + [826.29537708], + [36017.98746596], + [66.0355995], + [70148.84813234], + [223.47092563], + [24728.09736946], + [572919.37355123], + [204442.58902634], + [1626.51457086], + [6093.69744674], + [10162.98392454], + [689.92343951], + [160534.05016433], + [159.12933119], + [70128.54074401], + [954882.75740092], + [94268.49645185], + [198.7378926], + [24823.24379754], + [1720.73985365], + [6076.01396266], + [318958.96690988], + [898.91123455], + [160631.47184518], + [1502172.69801285], + [94177.31389604], + [106.61122262], + [24725.9791125], + [1626.23799303], + [5985.83346262], + [318868.0394118], + [804.13457814], + [160539.14508982], + [1502078.8083127], + [35996.60913344], + [43.834566], + [70127.91003415], + [89.45622247], + [24596.78943316], + [572789.40523656], + [6075.64760969], + [318848.71419886], + [2256401.04686227], + [10254.81031158], + [786.57872246], + [160633.36424445], + [142.19114283], + [70108.29032594], + [954864.02707419], + [24800.79233544], + [572881.458656], + [3264652.78585258], + [10277.06199904], + [808.11256024], + [160648.32156495], + [159.6354815], + [70131.22893311], + [954884.0799965], + [24819.35415152], + [572901.19118205], + [3264668.09983005], + [1718.798993], + [6077.50395789], + [318964.52888631], + [787.35597976], + [160520.7570658], + [1502063.22327205], + [70223.02616674], + [954864.10169746], + [4578036.76747938], + [295.24084792], + [24804.69178731], + [572990.07300979], + [6171.27271126], + [318943.24050039], + [2256497.15589155], + [160725.18352155], + [1502152.27486217], + [6252899.56065622], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(4, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [391350.], + [10181.25], + [826.29537708], + [36017.98746596], + [66.0355995], + [70148.84813234], + [220.3125], + [24726.5625], + [572920.3125], + [204441.50390625], + [1627.44140625], + [6093.69744674], + [10162.5], + [693.75], + [160537.5], + [160.25390625], + [70130.56640625], + [954882.75740092], + [94268.49645185], + [201.5625], + [24820.3125], + [1721.19140625], + [6076.01396266], + [318961.81640625], + [900.], + [160631.47184518], + [1502172.69801285], + [94176.5625], + [107.8125], + [24726.5625], + [1627.44140625], + [5982.12890625], + [318868.06640625], + [806.25], + [160537.5], + [1502078.8083127], + [35996.19140625], + [47.75390625], + [70127.91003415], + [89.45622247], + [24595.3125], + [572789.0625], + [6075.64760969], + [318848.71419886], + [2256404.00390625], + [10254.81031158], + [786.57872246], + [160631.25], + [141.50390625], + [70108.29032594], + [954863.37890625], + [24801.5625], + [572881.458656], + [3264651.5625], + [10275.], + [806.25], + [160650.], + [160.25390625], + [70131.22893311], + [954882.12890625], + [24820.3125], + [572901.19118205], + [3264668.09983005], + [1721.19140625], + [6075.87890625], + [318964.52888631], + [787.5], + [160520.7570658], + [1502062.5], + [70223.02616674], + [954863.37890625], + [4578033.69140625], + [295.3125], + [24804.69178731], + [572995.3125], + [6171.27271126], + [318943.06640625], + [2256497.75390625], + [160725.18352155], + [1502156.25], + [6252900.], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(1, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [71.4617346], + [8.09052578], + [752.63811703], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(2, seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [3271.4617346], + [240.90302578], + [125.], + [31.25], + [224.31640625], + [3326.5625], + [3341.38420756], + [16250.87890625], + [51050.], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun(2) + assert obj_fun.name == str_name + '_2' + + obj_fun = class_fun(4) + assert obj_fun.name == str_name + '_4' + + obj_fun = class_fun(16) + assert obj_fun.name == str_name + '_16' + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_one_dim_constant.py b/tests/test_one_dim_constant.py index c53d313..67e76f6 100644 --- a/tests/test_one_dim_constant.py +++ b/tests/test_one_dim_constant.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.one_dim_constant import * class_fun = Constant +str_name = 'constant' TEST_EPSILON = 1e-5 @@ -54,3 +55,26 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [0.0], + [0.0], + [0.0], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_one_dim_gramacyandlee2012.py b/tests/test_one_dim_gramacyandlee2012.py index 13237ab..e24cf34 100644 --- a/tests/test_one_dim_gramacyandlee2012.py +++ b/tests/test_one_dim_gramacyandlee2012.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.one_dim_gramacyandlee2012 import * class_fun = GramacyAndLee2012 +str_name = 'gramacyandlee2012' TEST_EPSILON = 1e-5 @@ -40,3 +41,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_one_dim_linear.py b/tests/test_one_dim_linear.py index 8457528..3b7eee5 100644 --- a/tests/test_one_dim_linear.py +++ b/tests/test_one_dim_linear.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.one_dim_linear import * class_fun = Linear +str_name = 'linear' TEST_EPSILON = 1e-5 @@ -66,3 +67,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_one_dim_step.py b/tests/test_one_dim_step.py index 0fe08cb..7dc9ba2 100644 --- a/tests/test_one_dim_step.py +++ b/tests/test_one_dim_step.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.one_dim_step import * class_fun = Step +str_name = 'step' TEST_EPSILON = 1e-5 @@ -55,3 +56,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_six_dim_hartmann6d.py b/tests/test_six_dim_hartmann6d.py index ef86d2d..361ad2f 100644 --- a/tests/test_six_dim_hartmann6d.py +++ b/tests/test_six_dim_hartmann6d.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.six_dim_hartmann6d import * class_fun = Hartmann6D +str_name = 'hartmann6d' TEST_EPSILON = 1e-5 @@ -766,3 +767,752 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [-5.08911288e-03], + [-1.39417909e-01], + [-7.03642418e-02], + [-1.28869208e-02], + [-3.53479936e-01], + [-1.78361572e-01], + [-2.54689221e-04], + [-3.71921487e-03], + [-1.06424677e-03], + [-7.71014520e-03], + [-2.03302912e-01], + [-1.02872411e-01], + [-1.90092977e-02], + [-5.15263796e-01], + [-2.60720627e-01], + [-4.31653377e-04], + [-1.82166544e-03], + [-5.57722931e-04], + [-1.34601938e-04], + [-2.04523802e-03], + [-1.02727639e-03], + [-2.49175535e-04], + [-5.18358536e-03], + [-2.60138785e-03], + [-6.29850385e-05], + [-1.21979697e-04], + [-3.33663146e-05], + [-2.01973752e-02], + [-3.79140190e-01], + [-1.72776742e-01], + [-5.31354735e-02], + [-9.88341220e-01], + [-3.77506742e-01], + [-4.34890158e-02], + [-6.52731890e-01], + [-1.79563032e-01], + [-1.52764672e-02], + [-3.35264377e-01], + [-1.78871699e-01], + [-3.90210622e-02], + [-8.60382551e-01], + [-3.87506085e-01], + [-1.92650287e-02], + [-2.84407512e-01], + [-7.83150773e-02], + [-6.16609104e-04], + [-1.03409268e-02], + [-3.30619590e-02], + [-1.53231605e-03], + [-2.51342950e-02], + [-1.72736777e-02], + [-1.48864416e-03], + [-2.14985611e-02], + [-5.96035595e-03], + [-3.57243075e-03], + [-9.53672207e-02], + [-1.65567290e-01], + [-9.10553914e-03], + [-2.34536318e-01], + [-1.49844278e-01], + [-1.64812933e-03], + [-2.46029476e-02], + [-6.99010494e-03], + [-5.02661669e-03], + [-1.29938794e-01], + [-1.85603313e-01], + [-1.22155389e-02], + [-3.21392180e-01], + [-1.97089704e-01], + [-1.04757111e-03], + [-1.08440287e-02], + [-3.21702233e-03], + [-1.23405921e-04], + [-5.08713433e-03], + [-1.18652035e-01], + [-2.19152932e-04], + [-4.87166863e-03], + [-3.73950140e-02], + [-1.11007245e-04], + [-8.17050467e-04], + [-4.19803489e-04], + [-4.98627198e-03], + [-1.32458341e-01], + [-6.70204937e-02], + [-1.23500430e-02], + [-3.35717210e-01], + [-1.69856989e-01], + [-2.51130043e-04], + [-1.25998552e-03], + [-3.83966561e-04], + [-1.18067119e-02], + [-1.94142004e-01], + [-9.81966234e-02], + [-2.25031920e-02], + [-4.91644737e-01], + [-2.48857619e-01], + [-4.47221414e-03], + [-9.50824094e-04], + [-2.57363332e-04], + [-8.96938712e-04], + [-1.96888061e-03], + [-9.74727532e-04], + [-9.92865242e-04], + [-4.92524484e-03], + [-2.46720543e-03], + [-7.67213164e-04], + [-7.73899702e-05], + [-1.10377943e-05], + [-1.02145839e-02], + [-2.23252421e-01], + [-1.28189573e-01], + [-2.61884889e-02], + [-5.72693200e-01], + [-2.58912791e-01], + [-1.34364265e-02], + [-1.99122393e-01], + [-5.48427318e-02], + [-1.51665230e-02], + [-2.60067875e-01], + [-1.55614367e-01], + [-3.10431745e-02], + [-6.60493738e-01], + [-3.26162430e-01], + [-1.03515667e-02], + [-8.71324338e-02], + [-2.40128029e-02], + [-1.07842858e-03], + [-5.38157507e-03], + [-3.16372526e-02], + [-1.43191616e-03], + [-1.18269962e-02], + [-1.35338549e-02], + [-1.22548209e-03], + [-6.59622416e-03], + [-1.85266330e-03], + [-3.24646485e-03], + [-8.60695727e-02], + [-1.62042071e-01], + [-7.94897734e-03], + [-2.10194240e-01], + [-1.40928970e-01], + [-6.80649908e-04], + [-7.58417793e-03], + [-2.30729429e-03], + [-9.28302411e-03], + [-1.22277348e-01], + [-1.82060775e-01], + [-1.58335639e-02], + [-3.01279219e-01], + [-1.88253232e-01], + [-4.82231893e-03], + [-3.64585053e-03], + [-1.17571514e-03], + [-9.05731357e-04], + [-4.88738991e-03], + [-1.18473356e-01], + [-9.66875140e-04], + [-4.28343285e-03], + [-3.71602329e-02], + [-8.10268545e-04], + [-2.94248069e-04], + [-2.65456530e-04], + [-1.01866285e-03], + [-2.81614256e-02], + [-1.42683928e-02], + [-2.58074116e-03], + [-7.13682077e-02], + [-3.61563426e-02], + [-1.96640000e-06], + [-3.90396482e-05], + [-1.92547684e-05], + [-1.50675227e-03], + [-4.13036311e-02], + [-2.09262322e-02], + [-3.79755641e-03], + [-1.04672823e-01], + [-5.30289519e-02], + [-1.45246242e-05], + [-5.55811549e-05], + [-2.76113094e-05], + [-1.70921654e-05], + [-4.08358502e-04], + [-2.08294922e-04], + [-3.97023325e-05], + [-1.03459954e-03], + [-5.24518085e-04], + [-2.18273812e-06], + [-7.17532844e-07], + [-2.92797021e-07], + [-1.22074825e-03], + [-3.45514485e-02], + [-4.68866044e-02], + [-3.09402230e-03], + [-8.55414071e-02], + [-5.21413638e-02], + [-2.93023413e-05], + [-4.53875241e-04], + [-1.84464412e-04], + [-1.79439560e-03], + [-5.01235291e-02], + [-5.51586428e-02], + [-4.52633232e-03], + [-1.24968147e-01], + [-7.22725892e-02], + [-2.70749465e-05], + [-2.44283645e-04], + [-1.32013401e-04], + [-2.02828415e-05], + [-1.38096103e-03], + [-2.93775538e-02], + [-4.76589378e-05], + [-1.51174593e-03], + [-9.42872578e-03], + [-3.14626116e-06], + [-1.56943790e-05], + [-5.27334259e-05], + [-6.16929640e-04], + [-2.06445976e-02], + [-1.26429383e-01], + [-1.56243078e-03], + [-4.42787658e-02], + [-5.74711985e-02], + [-2.33338971e-06], + [-4.36448190e-05], + [-2.12476855e-04], + [-9.17683116e-04], + [-2.86381883e-02], + [-1.31921681e-01], + [-2.30369846e-03], + [-6.44351026e-02], + [-6.81199561e-02], + [-1.46101013e-05], + [-4.60953511e-05], + [-2.17810367e-04], + [-1.14595526e-05], + [-3.75956349e-03], + [-1.14981197e-01], + [-2.50731250e-05], + [-1.68766734e-03], + [-3.50220260e-02], + [-2.28614353e-06], + [-6.81639226e-06], + [-1.92367509e-04], + [-5.65385855e-03], + [-9.67927426e-02], + [-4.87783652e-02], + [-1.10377689e-02], + [-2.45253274e-01], + [-1.23633381e-01], + [-2.16022665e-03], + [-3.00626559e-03], + [-8.27667950e-04], + [-5.96745804e-02], + [-1.43673045e-01], + [-7.12804483e-02], + [-6.67466444e-02], + [-3.59809313e-01], + [-1.80639418e-01], + [-5.05533708e-02], + [-3.99159225e-03], + [-4.25845136e-04], + [-9.46885958e-03], + [-1.90313229e-03], + [-7.19448618e-04], + [-9.41744789e-03], + [-4.07612031e-03], + [-1.80669595e-03], + [-8.71468740e-03], + [-5.41662418e-04], + [-2.61241964e-05], + [-1.75032197e-02], + [-2.86778842e-01], + [-2.61287764e-01], + [-4.25031506e-02], + [-7.39107298e-01], + [-3.17239160e-01], + [-3.61907088e-02], + [-5.12932271e-01], + [-1.41292654e-01], + [-6.72086761e-02], + [-2.47990525e-01], + [-2.64118285e-01], + [-8.38363686e-02], + [-6.23231468e-01], + [-3.16432662e-01], + [-6.69396289e-02], + [-2.26098945e-01], + [-6.17418747e-02], + [-1.01429584e-02], + [-1.23748708e-02], + [-1.55824804e-01], + [-1.07147972e-02], + [-2.08773304e-02], + [-5.25559751e-02], + [-1.01090629e-02], + [-1.73576281e-02], + [-4.90015774e-03], + [-4.72686643e-03], + [-8.33353958e-02], + [-6.51676513e-01], + [-8.61164570e-03], + [-1.69529355e-01], + [-2.66539798e-01], + [-3.32982852e-03], + [-1.94516375e-02], + [-6.36568260e-03], + [-5.99005776e-02], + [-1.09856252e-01], + [-6.72115749e-01], + [-6.41271814e-02], + [-2.31382042e-01], + [-3.00974859e-01], + [-5.29470770e-02], + [-1.12155571e-02], + [-3.40987785e-03], + [-9.81945025e-03], + [-2.00546011e-02], + [-6.05580038e-01], + [-9.75203927e-03], + [-8.77035978e-03], + [-1.84066791e-01], + [-9.08191769e-03], + [-1.13102974e-03], + [-1.18665197e-03], + [-3.28854104e-02], + [-9.33026658e-02], + [-4.64416001e-02], + [-3.75782465e-02], + [-2.34134839e-01], + [-1.17687234e-01], + [-2.73967061e-02], + [-2.37410310e-03], + [-2.93622690e-04], + [-7.61874317e-01], + [-1.73296523e-01], + [-6.80342229e-02], + [-7.58740328e-01], + [-3.78859295e-01], + [-1.72399548e-01], + [-7.00116229e-01], + [-3.65832813e-02], + [-1.91975636e-04], + [-1.30680296e-01], + [-8.06032335e-03], + [-6.82655295e-04], + [-1.28927185e-01], + [-1.00162035e-02], + [-1.71222014e-03], + [-1.20809885e-01], + [-6.24859784e-03], + [-8.85605209e-06], + [-3.78399741e-02], + [-1.66427904e-01], + [-2.26487863e-01], + [-4.91552890e-02], + [-4.15694906e-01], + [-2.24902689e-01], + [-3.86169732e-02], + [-1.57879606e-01], + [-4.33021740e-02], + [-7.88231366e-01], + [-2.27025613e-01], + [-2.46238350e-01], + [-7.88644125e-01], + [-5.05314992e-01], + [-2.69486569e-01], + [-7.26783266e-01], + [-1.05432244e-01], + [-1.90795014e-02], + [-1.34935782e-01], + [-1.48902631e-02], + [-1.54599672e-01], + [-1.33325522e-01], + [-1.67617823e-02], + [-4.95970773e-02], + [-1.24974560e-01], + [-1.15727948e-02], + [-1.67290629e-03], + [-3.28126972e-02], + [-7.78216699e-02], + [-6.48633370e-01], + [-3.56677578e-02], + [-1.52716537e-01], + [-2.59844642e-01], + [-2.87686859e-02], + [-7.42935626e-03], + [-2.68601275e-03], + [-7.88791593e-01], + [-1.41680122e-01], + [-6.69137063e-01], + [-7.82393820e-01], + [-2.53690230e-01], + [-2.94549338e-01], + [-7.26880074e-01], + [-4.01007774e-02], + [-1.80725208e-03], + [-1.35632767e-01], + [-2.63342699e-02], + [-6.05004574e-01], + [-1.33786771e-01], + [-1.46716790e-02], + [-1.83756753e-01], + [-1.25414609e-01], + [-6.68055294e-03], + [-1.06493476e-03], + [-7.88704703e-04], + [-1.95121337e-02], + [-9.89065653e-03], + [-1.86961061e-03], + [-4.94416263e-02], + [-2.50478224e-02], + [-7.81956838e-05], + [-3.12038273e-05], + [-1.34061382e-05], + [-3.17111006e-03], + [-2.87210161e-02], + [-1.45026596e-02], + [-4.72820200e-03], + [-7.26155878e-02], + [-3.67355781e-02], + [-1.97745668e-03], + [-1.39868750e-04], + [-1.91674993e-05], + [-3.78943109e-04], + [-3.01976202e-04], + [-1.50958168e-04], + [-3.89469331e-04], + [-7.35373946e-04], + [-3.65354470e-04], + [-3.41008654e-04], + [-1.79807622e-05], + [-2.16660605e-07], + [-9.32256819e-04], + [-2.80043448e-02], + [-1.65034993e-01], + [-2.22999296e-03], + [-6.05174297e-02], + [-7.61799080e-02], + [-1.02079775e-04], + [-3.63245556e-04], + [-3.59881912e-04], + [-3.43816804e-03], + [-3.89431695e-02], + [-1.72411676e-01], + [-5.30041339e-03], + [-8.79320643e-02], + [-9.06178826e-02], + [-2.04951519e-03], + [-2.97099260e-04], + [-3.20413163e-04], + [-3.92909681e-04], + [-4.92882310e-03], + [-1.49594128e-01], + [-4.06543231e-04], + [-2.26174402e-03], + [-4.55839513e-02], + [-3.52504410e-04], + [-3.67615719e-05], + [-2.52998682e-04], + [-5.14052700e-04], + [-3.02878422e-02], + [-6.10212903e-01], + [-1.16754138e-03], + [-3.55069860e-02], + [-1.97729966e-01], + [-8.14529696e-05], + [-6.24894125e-05], + [-1.02153856e-03], + [-2.84441490e-03], + [-3.61327903e-02], + [-6.20517230e-01], + [-3.77332715e-03], + [-4.96364609e-02], + [-2.07070224e-01], + [-2.05236226e-03], + [-1.64737930e-04], + [-1.03588577e-03], + [-3.89435933e-04], + [-1.82072400e-02], + [-5.89235961e-01], + [-3.93233080e-04], + [-5.89709436e-03], + [-1.78236811e-01], + [-3.53993075e-04], + [-4.89687028e-05], + [-9.85413505e-04], + [-6.59238442e-03], + [-1.20054976e-02], + [-5.88472482e-03], + [-7.16337480e-03], + [-2.99557347e-02], + [-1.49188254e-02], + [-5.73435279e-03], + [-7.95863576e-04], + [-1.41626265e-04], + [-1.58503337e-01], + [-2.51058655e-02], + [-8.58597372e-03], + [-1.57239929e-01], + [-5.10505477e-02], + [-2.17604739e-02], + [-1.46028887e-01], + [-7.75075671e-03], + [-6.98757292e-05], + [-2.72517233e-02], + [-1.57489907e-03], + [-8.64394364e-05], + [-2.68803827e-02], + [-1.82043389e-03], + [-2.18546903e-04], + [-2.51975042e-02], + [-1.31333070e-03], + [-4.58467785e-06], + [-8.81688553e-03], + [-4.36456441e-02], + [-2.04818492e-02], + [-1.27688328e-02], + [-1.13807862e-01], + [-4.08846274e-02], + [-1.18697031e-02], + [-9.01972308e-02], + [-2.47288254e-02], + [-1.64465619e-01], + [-4.14853618e-02], + [-1.92229612e-02], + [-1.64730523e-01], + [-9.35514262e-02], + [-3.69097743e-02], + [-1.53242895e-01], + [-4.69088018e-02], + [-1.07807200e-02], + [-2.81794379e-02], + [-2.77742264e-03], + [-5.67148756e-03], + [-2.79052355e-02], + [-4.57072125e-03], + [-2.57043884e-03], + [-2.61911117e-02], + [-4.29877788e-03], + [-8.22924646e-04], + [-6.72515139e-03], + [-9.06477998e-03], + [-2.52860989e-02], + [-7.14557312e-03], + [-2.11513705e-02], + [-1.62476551e-02], + [-6.14315216e-03], + [-3.68763318e-03], + [-9.67810048e-04], + [-1.64292995e-01], + [-1.98115625e-02], + [-2.70307765e-02], + [-1.62620961e-01], + [-3.57296690e-02], + [-2.00493568e-02], + [-1.51664456e-01], + [-9.28514856e-03], + [-4.47158849e-04], + [-2.82874358e-02], + [-2.23288187e-03], + [-2.09746765e-02], + [-2.79013952e-02], + [-1.98218096e-03], + [-6.47577875e-03], + [-2.61619296e-02], + [-1.45866944e-03], + [-6.56436061e-05], + [-8.59241826e-02], + [-1.54658359e-02], + [-5.59406400e-03], + [-8.53439946e-02], + [-3.23848795e-02], + [-1.41776954e-02], + [-7.91016625e-02], + [-4.23440094e-03], + [-4.83247082e-05], + [-2.19086006e+00], + [-1.28927151e-01], + [-8.19575789e-03], + [-2.16111393e+00], + [-1.52170833e-01], + [-2.07621247e-02], + [-2.02556653e+00], + [-1.04357711e-01], + [-3.33704982e-05], + [-3.77963549e-01], + [-1.96177796e-02], + [-8.25084491e-05], + [-3.72684501e-01], + [-1.95931770e-02], + [-2.07134029e-04], + [-3.49534811e-01], + [-1.79984504e-02], + [-2.29591959e-06], + [-8.93010949e-02], + [-2.67856599e-02], + [-1.45415617e-02], + [-8.97934230e-02], + [-6.17215001e-02], + [-2.50612786e-02], + [-8.34202455e-02], + [-3.16147332e-02], + [-7.55051221e-03], + [-2.26055311e+00], + [-1.39614600e-01], + [-1.63196907e-02], + [-2.23044003e+00], + [-1.73892940e-01], + [-2.92155744e-02], + [-2.09046707e+00], + [-1.19524938e-01], + [-3.30628821e-03], + [-3.89946799e-01], + [-2.07198647e-02], + [-5.47804038e-03], + [-3.84534811e-01], + [-2.11117028e-02], + [-2.06329506e-03], + [-3.60657558e-01], + [-1.94657058e-02], + [-2.57948625e-04], + [-8.90381136e-02], + [-1.22259248e-02], + [-2.48993264e-02], + [-8.82031892e-02], + [-2.24920412e-02], + [-1.52788414e-02], + [-8.21675069e-02], + [-5.26420602e-03], + [-3.23119186e-04], + [-2.27392323e+00], + [-1.27622303e-01], + [-2.66943813e-02], + [-2.24267185e+00], + [-1.40762494e-01], + [-1.92176473e-02], + [-2.10261399e+00], + [-1.08698362e-01], + [-1.70895763e-04], + [-3.92333810e-01], + [-2.09430258e-02], + [-2.09484462e-02], + [-3.86851230e-01], + [-2.03812838e-02], + [-6.44687435e-03], + [-3.62827834e-01], + [-1.87126054e-02], + [-4.51927134e-05], + [-3.26294369e-04], + [-2.36067775e-03], + [-1.18991047e-03], + [-4.53174149e-04], + [-5.96331690e-03], + [-3.01493025e-03], + [-2.23373504e-04], + [-1.48656613e-05], + [-1.63942185e-06], + [-6.30676167e-03], + [-3.76227163e-03], + [-1.74507714e-03], + [-6.41129847e-03], + [-9.04181589e-03], + [-4.42183260e-03], + [-5.71750323e-03], + [-2.98950322e-04], + [-2.33080844e-06], + [-1.06805061e-03], + [-8.89639198e-05], + [-1.75125348e-05], + [-1.05501271e-03], + [-1.40413277e-04], + [-4.37825127e-05], + [-9.86595170e-04], + [-5.08424046e-05], + [-2.81245054e-08], + [-3.51268205e-04], + [-2.98691434e-03], + [-6.71697126e-03], + [-5.04794192e-04], + [-7.19077504e-03], + [-5.20076875e-03], + [-2.34188602e-04], + [-7.20489018e-05], + [-2.61784599e-05], + [-6.52659463e-03], + [-4.59778100e-03], + [-7.44050157e-03], + [-6.66552681e-03], + [-1.07787090e-02], + [-6.88692805e-03], + [-5.90011395e-03], + [-3.33758882e-04], + [-1.84295783e-05], + [-1.10209415e-03], + [-2.55682914e-04], + [-5.18503546e-03], + [-1.08900624e-03], + [-2.07823581e-04], + [-1.61289536e-03], + [-1.01794449e-03], + [-5.45656746e-05], + [-9.17478486e-06], + [-3.01998702e-04], + [-2.07285020e-03], + [-2.16034133e-02], + [-3.77356905e-04], + [-3.80778858e-03], + [-8.13461009e-03], + [-2.31938881e-04], + [-1.69651123e-05], + [-3.64435778e-05], + [-6.49269710e-03], + [-3.06083421e-03], + [-2.21989194e-02], + [-6.51850527e-03], + [-5.80231567e-03], + [-9.06401290e-03], + [-5.93489370e-03], + [-3.10231795e-04], + [-3.70027561e-05], + [-1.10814922e-03], + [-7.00301267e-04], + [-2.03726271e-02], + [-1.09378813e-03], + [-2.96601645e-04], + [-6.17908587e-03], + [-1.02411386e-03], + [-5.38568035e-05], + [-3.40853927e-05], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_three_dim_hartmann3d.py b/tests/test_three_dim_hartmann3d.py index c364257..62417f9 100644 --- a/tests/test_three_dim_hartmann3d.py +++ b/tests/test_three_dim_hartmann3d.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.three_dim_hartmann3d import * class_fun = Hartmann3D +str_name = 'hartmann3d' TEST_EPSILON = 1e-5 @@ -64,3 +65,50 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [-6.79741166e-02], + [-1.36461045e-01], + [-9.13324430e-02], + [-9.71082067e-02], + [-1.85406663e-01], + [-9.02038776e-02], + [-3.09547170e-02], + [-7.29043824e-02], + [-8.47693855e-02], + [-1.80480228e-02], + [-8.39060933e-01], + [-1.99426284e+00], + [-2.57290548e-02], + [-6.28022015e-01], + [-1.95703928e+00], + [-8.19356834e-03], + [-2.25915245e-01], + [-1.82665019e+00], + [-2.73536768e-04], + [-2.26230774e+00], + [-3.34829168e-01], + [-2.04016877e-04], + [-1.48565839e+00], + [-3.25957854e-01], + [-3.77271851e-05], + [-2.24631259e-01], + [-3.00476074e-01], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_beale.py b/tests/test_two_dim_beale.py index a3f8f2e..f4aba0d 100644 --- a/tests/test_two_dim_beale.py +++ b/tests/test_two_dim_beale.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_beale import * class_fun = Beale +str_name = 'beale' TEST_EPSILON = 1e-3 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_bohachevsky.py b/tests/test_two_dim_bohachevsky.py index a0b9918..007e942 100644 --- a/tests/test_two_dim_bohachevsky.py +++ b/tests/test_two_dim_bohachevsky.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_bohachevsky import * class_fun = Bohachevsky +str_name = 'bohachevsky' TEST_EPSILON = 1e-5 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_branin.py b/tests/test_two_dim_branin.py index 5017ccd..3c7509c 100644 --- a/tests/test_two_dim_branin.py +++ b/tests/test_two_dim_branin.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_branin import * class_fun = Branin +str_name = 'branin' TEST_EPSILON = 1e-5 SCALE_NOISE = 2.0 @@ -61,6 +62,28 @@ def test_output(): print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [308.12909601], + [10.30790849], + [10.96088904], + [106.56869776], + [24.12996441], + [22.16653996], + [17.50829952], + [150.45202034], + [145.87219088], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + def test_output_constant_noise(): obj_fun = class_fun() bounds = obj_fun.get_bounds() @@ -174,3 +197,10 @@ def test_output_sparse_student_t_noise(): print(outputs) print(np.abs(outputs - truths_grids) < TEST_EPSILON) assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_bukin6.py b/tests/test_two_dim_bukin6.py new file mode 100644 index 0000000..6f3175c --- /dev/null +++ b/tests/test_two_dim_bukin6.py @@ -0,0 +1,194 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 6, 2023 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_bukin6 import * + +class_fun = Bukin6 +str_name = 'bukin6' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [229.17878475], + [200.0], + [180.32756377], + [150.05], + [100.0], + [50.05], + [86.65254038], + [141.42135624], + [165.88123952], + ]) + + print(grids) + print(obj_fun.output(grids)) + print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [229.17878475], + [200.0], + [180.32756377], + [150.05], + [100.0], + [50.05], + [86.65254038], + [141.42135624], + [165.88123952], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [231.17878475], + [202.0], + [182.32756377], + [152.05], + [102.0], + [52.05], + [88.65254038], + [143.42135624], + [167.88123952], + ]) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [230.17221305], + [199.7234714], + [181.62294085], + [153.09605971], + [99.53169325], + [49.58172609], + [89.81096601], + [142.9562257], + [164.94229075], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [230.17221305], + [199.7234714], + [180.32756377], + [150.05], + [100.0], + [49.58172609], + [86.65254038], + [142.9562257 ], + [164.94229075], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [230.32801935], + [197.83661953], + [182.96568081], + [148.46644847], + [101.4728255], + [53.83670737], + [82.72424794], + [140.30935909], + [164.7380196], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [230.32801935], + [197.83661953], + [180.32756377], + [150.05], + [100.0], + [50.05], + [82.72424794], + [141.42135624], + [165.88123952], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_dejong5.py b/tests/test_two_dim_dejong5.py index 17483ac..6c3e137 100644 --- a/tests/test_two_dim_dejong5.py +++ b/tests/test_two_dim_dejong5.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_dejong5 import * class_fun = DeJong5 +str_name = 'dejong5' TEST_EPSILON = 1e-3 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_dropwave.py b/tests/test_two_dim_dropwave.py index 529378f..2fbc3ed 100644 --- a/tests/test_two_dim_dropwave.py +++ b/tests/test_two_dim_dropwave.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_dropwave import * class_fun = DropWave +str_name = 'dropwave' TEST_EPSILON = 1e-3 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_easom.py b/tests/test_two_dim_easom.py new file mode 100644 index 0000000..f7d6cc7 --- /dev/null +++ b/tests/test_two_dim_easom.py @@ -0,0 +1,194 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 3, 2023 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_easom import * + +class_fun = Easom +str_name = 'easom' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [0.0], + [0.0], + [0.0], + [0.0], + [-2.67528799e-09], + [0.0], + [0.0], + [0.0], + [0.0], + ]) + + print(grids) + print(obj_fun.output(grids)) + print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [0.0], + [0.0], + [0.0], + [0.0], + [-2.67528799e-09], + [0.0], + [0.0], + [0.0], + [0.0], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [2.0], + [2.0], + [2.0], + [2.0], + [2.0], + [2.0], + [2.0], + [2.0], + [2.0], + ]) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [0.99342831], + [-0.2765286], + [1.29537708], + [3.04605971], + [-0.46830675], + [-0.46827391], + [3.15842563], + [1.53486946], + [-0.93894877], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [9.93428306e-01], + [-2.76528602e-01], + [0.0], + [0.0], + [-2.67528799e-09], + [-4.68273914e-01], + [0.0], + [1.53486946], + [-9.38948772e-01], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [1.1492346], + [-2.16338047], + [2.63811703], + [-1.58355153], + [1.4728255], + [3.78670737], + [-3.92829244], + [-1.11199715], + [-1.14321992], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [1.14923460], + [-2.16338047], + [0.0], + [0.0], + [-2.67528799e-09], + [0.0], + [-3.92829244], + [0.0], + [0.0], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_eggholder.py b/tests/test_two_dim_eggholder.py index eb71991..4cfbebb 100644 --- a/tests/test_two_dim_eggholder.py +++ b/tests/test_two_dim_eggholder.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: January 13, 2023 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_eggholder import * class_fun = Eggholder +str_name = 'eggholder' TEST_EPSILON = 1e-5 @@ -16,10 +17,6 @@ def test_init(): obj_fun = class_fun() - with pytest.raises(AssertionError) as error: - class_fun(bounds='abc') - with pytest.raises(AssertionError) as error: - class_fun(bounds=2.1) with pytest.raises(AssertionError) as error: class_fun(seed='abc') with pytest.raises(AssertionError) as error: @@ -50,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_goldsteinprice.py b/tests/test_two_dim_goldsteinprice.py index c0b4793..913ae0b 100644 --- a/tests/test_two_dim_goldsteinprice.py +++ b/tests/test_two_dim_goldsteinprice.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_goldsteinprice import * class_fun = GoldsteinPrice +str_name = 'goldsteinprice' TEST_EPSILON = 1e-5 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_holdertable.py b/tests/test_two_dim_holdertable.py index 3f6ccb9..bd11d85 100644 --- a/tests/test_two_dim_holdertable.py +++ b/tests/test_two_dim_holdertable.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_holdertable import * class_fun = HolderTable +str_name = 'holdertable' TEST_EPSILON = 1e-5 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_kim1.py b/tests/test_two_dim_kim1.py index 45ff5d9..fbc74d1 100644 --- a/tests/test_two_dim_kim1.py +++ b/tests/test_two_dim_kim1.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: October 27, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_kim1 import * class_fun = Kim1 +str_name = 'kim1' TEST_EPSILON = 1e-5 SCALE_NOISE = 2.0 @@ -102,3 +103,10 @@ def test_output_gaussian_noise(): print(outputs) print(np.abs(outputs - truths_grids) < TEST_EPSILON) assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_kim2.py b/tests/test_two_dim_kim2.py index b4a821d..7c0a54b 100644 --- a/tests/test_two_dim_kim2.py +++ b/tests/test_two_dim_kim2.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: October 27, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_kim2 import * class_fun = Kim2 +str_name = 'kim2' TEST_EPSILON = 1e-5 SCALE_NOISE = 2.0 @@ -102,3 +103,10 @@ def test_output_gaussian_noise(): print(outputs) print(np.abs(outputs - truths_grids) < TEST_EPSILON) assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_kim3.py b/tests/test_two_dim_kim3.py index ef6423f..44bdec8 100644 --- a/tests/test_two_dim_kim3.py +++ b/tests/test_two_dim_kim3.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: October 27, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_kim3 import * class_fun = Kim3 +str_name = 'kim3' TEST_EPSILON = 1e-5 SCALE_NOISE = 2.0 @@ -102,3 +103,10 @@ def test_output_gaussian_noise(): print(outputs) print(np.abs(outputs - truths_grids) < TEST_EPSILON) assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_michalewicz.py b/tests/test_two_dim_michalewicz.py index c06e496..e61ada4 100644 --- a/tests/test_two_dim_michalewicz.py +++ b/tests/test_two_dim_michalewicz.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_michalewicz import * class_fun = Michalewicz +str_name = 'michalewicz' TEST_EPSILON = 1e-3 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_shubert.py b/tests/test_two_dim_shubert.py new file mode 100644 index 0000000..f9bbfdb --- /dev/null +++ b/tests/test_two_dim_shubert.py @@ -0,0 +1,194 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 3, 2023 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_shubert import * + +class_fun = Shubert +str_name = 'shubert' + +TEST_EPSILON = 1e-5 +SCALE_NOISE = 2.0 +SEED = 42 + + +def test_init(): + obj_fun = class_fun() + + with pytest.raises(AssertionError) as error: + class_fun(seed=1.0) + with pytest.raises(AssertionError) as error: + class_fun(seed='abc') + +def test_validate_properties(): + obj_fun = class_fun() + obj_fun.validate_properties() + +def test_output(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [0.06674108], + [1.15175294], + [0.86375707], + [1.15175294], + [19.87583625], + [14.90588261], + [0.86375707], + [14.90588261], + [11.17866608], + ]) + + print(grids) + print(obj_fun.output(grids)) + print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_call(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [0.06674108], + [1.15175294], + [0.86375707], + [1.15175294], + [19.87583625], + [14.90588261], + [0.86375707], + [14.90588261], + [11.17866608], + ]) + + print(grids) + print(obj_fun(grids)) + print(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(obj_fun(grids) - truths_grids) < TEST_EPSILON) + +def test_output_constant_noise(): + obj_fun = class_fun() + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [2.06674108], + [3.15175294], + [2.86375707], + [3.15175294], + [21.87583625], + [16.90588261], + [2.86375707], + [16.90588261], + [13.17866608], + ]) + + print(grids) + print(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE)) + print(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + assert np.all(np.abs(obj_fun.output_constant_noise(grids, scale_noise=SCALE_NOISE) - truths_grids) < TEST_EPSILON + SCALE_NOISE) + +def test_output_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [1.06016939], + [0.87522434], + [2.15913415], + [4.19781266], + [19.4075295], + [14.4376087], + [4.02218271], + [16.44075207], + [10.2397173], + ]) + outputs = obj_fun.output_gaussian_noise(grids, scale_noise=SCALE_NOISE) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_gaussian_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [1.06016939], + [0.87522434], + [0.86375707], + [1.15175294], + [19.87583625], + [14.4376087], + [0.86375707], + [16.44075207], + [10.2397173], + ]) + outputs = obj_fun.output_sparse_gaussian_noise(grids, scale_noise=SCALE_NOISE, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_student_t_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [1.21597568], + [-1.01162753], + [3.50187411], + [-0.43179858], + [21.34866175], + [18.69258998], + [-3.06453537], + [13.79388546], + [10.03544615], + ]) + outputs = obj_fun.output_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_output_sparse_student_t_noise(): + obj_fun = class_fun(seed=SEED) + bounds = obj_fun.get_bounds() + + grids = obj_fun.sample_grids(3) + truths_grids = np.array([ + [1.21597568], + [-1.01162753], + [0.86375707], + [1.15175294], + [19.87583625], + [14.90588261], + [-3.06453537], + [14.90588261], + [11.17866608], + ]) + outputs = obj_fun.output_sparse_student_t_noise(grids, scale_noise=SCALE_NOISE, dof=4.0, sparsity=0.3) + + print(grids) + print(outputs) + print(np.abs(outputs - truths_grids) < TEST_EPSILON) + assert np.all(np.abs(outputs - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_sixhumpcamel.py b/tests/test_two_dim_sixhumpcamel.py index 1303007..d3e5044 100644 --- a/tests/test_two_dim_sixhumpcamel.py +++ b/tests/test_two_dim_sixhumpcamel.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_sixhumpcamel import * class_fun = SixHumpCamel +str_name = 'sixhumpcamel' TEST_EPSILON = 1e-5 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_two_dim_threehumpcamel.py b/tests/test_two_dim_threehumpcamel.py index 6dc72c6..29f4a08 100644 --- a/tests/test_two_dim_threehumpcamel.py +++ b/tests/test_two_dim_threehumpcamel.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: February 8, 2021 +# last updated: December 4, 2022 # import numpy as np @@ -9,6 +9,7 @@ from bayeso_benchmarks.two_dim_threehumpcamel import * class_fun = ThreeHumpCamel +str_name = 'threehumpcamel' TEST_EPSILON = 1e-5 @@ -46,3 +47,10 @@ def test_output(): print(obj_fun.output(grids)) print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON) + +def test_name(): + obj_fun = class_fun() + assert obj_fun.name == str_name + + assert obj_fun.__class__.__name__.lower() == str_name + assert obj_fun.__class__.__qualname__.lower() == str_name diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..09f9aec --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,131 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: January 6, 2023 +# + +import numpy as np +import pytest + +from bayeso_benchmarks import utils + +TEST_EPSILON = 1e-5 + + +def test_get_benchmark(): + with pytest.raises(TypeError) as error: + benchmark = utils.get_benchmark() + with pytest.raises(ValueError) as error: + benchmark = utils.get_benchmark('abc', seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('ackley') + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('ackley', seed='abc') + + benchmark = utils.get_benchmark('ackley', dim=4, seed=42) + print(benchmark.output(np.array([0.0, 0.0, 0.0, 0.0]))) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('cosines') + + benchmark = utils.get_benchmark('cosines', dim=4, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('griewank') + + benchmark = utils.get_benchmark('griewank', dim=4, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('levy') + + benchmark = utils.get_benchmark('levy', dim=2, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('rastrigin') + + benchmark = utils.get_benchmark('rastrigin', dim=8, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('rosenbrock') + + benchmark = utils.get_benchmark('rosenbrock', dim=8, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('sphere') + + benchmark = utils.get_benchmark('sphere', dim=16, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('zakharov') + + benchmark = utils.get_benchmark('zakharov', dim=16, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('constant') + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('constant', constant=None) + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('constant', bounds=None) + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('constant', bounds=np.array([0.0, 10.0]), constant=10.0, seed=None) + + benchmark = utils.get_benchmark('constant', bounds=np.array([[0.0, 10.0]]), constant=10.0, seed=None) + + benchmark = utils.get_benchmark('gramacyandlee2012') + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('linear') + + benchmark = utils.get_benchmark('linear', bounds=np.array([[0.0, 10.0]]), slope=-1.2, seed=None) + + with pytest.raises(AssertionError) as error: + benchmark = utils.get_benchmark('step') + + benchmark = utils.get_benchmark('step', steps=[0.0, 3.0, 7.0, 10.0], step_values=[-2.1, 4.0, 10.0], seed=None) + + benchmark = utils.get_benchmark('beale') + benchmark = utils.get_benchmark('bohachevsky') + + benchmark = utils.get_benchmark('branin') + print(benchmark.output(np.array([1.0, 1.0]))) + + benchmark = utils.get_benchmark('bukin6') + benchmark = utils.get_benchmark('dejong5') + benchmark = utils.get_benchmark('dropwave') + benchmark = utils.get_benchmark('easom') + benchmark = utils.get_benchmark('eggholder') + benchmark = utils.get_benchmark('goldsteinprice') + benchmark = utils.get_benchmark('holdertable') + benchmark = utils.get_benchmark('kim1') + benchmark = utils.get_benchmark('kim2') + benchmark = utils.get_benchmark('kim3') + benchmark = utils.get_benchmark('michalewicz') + benchmark = utils.get_benchmark('shubert') + benchmark = utils.get_benchmark('sixhumpcamel') + benchmark = utils.get_benchmark('threehumpcamel') + + benchmark = utils.get_benchmark('colville') + benchmark = utils.get_benchmark('hartmann3d') + benchmark = utils.get_benchmark('hartmann6d') + +def test_pdf_two_dim_normal(): + bx = np.array([0.0, 1.0]) + mu = np.array([1.0, 1.0]) + Cov = np.array([ + [2.0, 1.0], + [1.0, 2.0], + ]) + + with pytest.raises(AssertionError) as error: + value = utils.pdf_two_dim_normal(np.array([1.0, 1.0, 1.0]), mu, Cov) + with pytest.raises(AssertionError) as error: + value = utils.pdf_two_dim_normal(np.array([2.0]), mu, Cov) + with pytest.raises(AssertionError) as error: + value = utils.pdf_two_dim_normal(bx, np.array([1.0, 1.0, 1.0]), Cov) + with pytest.raises(AssertionError) as error: + value = utils.pdf_two_dim_normal(bx, np.array([3.0]), Cov) + + value = utils.pdf_two_dim_normal(bx, mu, Cov) + print(value) + + assert np.abs(0.06584073599896273 - value) < TEST_EPSILON diff --git a/tests/test_version.py b/tests/test_version.py index f0bb691..d967e4c 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,10 +1,10 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: October 23, 2021 +# last updated: October 19, 2022 # -STR_VERSION = '0.1.6' +STR_VERSION = '0.1.7' def test_version_bayeso():