diff --git a/.gitignore b/.gitignore index 60d976a..bb50194 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,6 @@ dmypy.json .pyre/ # Jungtaek -*.swp .DS_Store __MACOSX/ +*.swp diff --git a/.travis.yml b/.travis.yml index 3b7b47e..86977f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ python: - "3.6" - "3.7" - "3.8" + - "3.9" install: - pip install . script: diff --git a/LICENSE b/LICENSE index 9148bb9..c48865d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Jungtaek Kim +Copyright (c) 2019-2021 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/MANIFEST.in b/MANIFEST.in index 096dd50..a7da3fc 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include LICENSE include requirements.txt +include LICENSE diff --git a/README.md b/README.md index 85da3a7..8945ca4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Benchmarks for Bayesian optimization. The details of benchmark functions can be found in [these notes](http://jungtaek.github.io/notes/benchmarks_bo.pdf). ## Installation -We recommend it should be installed in `virtualenv`. +We recommend installing it with `virtualenv`. You can choose one of three installation options. * Using PyPI repository (for user installation) @@ -51,7 +51,7 @@ The following `requirements` files include the package list, the purpose of whic * `requirements-dev.txt`: It is for developing the `bayeso-benchmarks` package. ## Author -* [Jungtaek Kim](http://mlg.postech.ac.kr/~jtkim/) (POSTECH) +* [Jungtaek Kim](http://jungtaek.github.io) (POSTECH) ## Contact * Jungtaek Kim: [jtkim@postech.ac.kr](mailto:jtkim@postech.ac.kr) diff --git a/benchmarks/__init__.py b/bayeso_benchmarks/__init__.py similarity index 79% rename from benchmarks/__init__.py rename to bayeso_benchmarks/__init__.py index 70d80e7..3bc19f7 100644 --- a/benchmarks/__init__.py +++ b/bayeso_benchmarks/__init__.py @@ -3,4 +3,4 @@ # last updated: November 5, 2020 # -__version__ = '0.1.3' +__version__ = '0.1.4' diff --git a/benchmarks/benchmark_base.py b/bayeso_benchmarks/benchmark_base.py similarity index 83% rename from benchmarks/benchmark_base.py rename to bayeso_benchmarks/benchmark_base.py index 4f4fcc4..7751c91 100644 --- a/benchmarks/benchmark_base.py +++ b/bayeso_benchmarks/benchmark_base.py @@ -1,6 +1,6 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np @@ -9,7 +9,7 @@ class Function(object): - def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, function, dim_problem=None): + 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) @@ -27,6 +27,7 @@ def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, fu self._function = function self.dim_problem = dim_problem + self.random_state = np.random.RandomState(seed) self.validate_properties() @@ -70,7 +71,7 @@ def function(self, bx): return self._function(bx) - def output(self, X): + def _output(self, X): assert isinstance(X, np.ndarray) if len(X.shape) == 2: @@ -79,6 +80,10 @@ def output(self, X): list_results = [self.function(X)] by = np.array(list_results) + return by + + def output(self, X): + by = self._output(X) Y = np.expand_dims(by, axis=1) assert len(Y.shape) == 2 @@ -86,15 +91,9 @@ def output(self, X): return Y def output_constant_noise(self, X, scale_noise=0.01): - assert isinstance(X, np.ndarray) assert isinstance(scale_noise, float) - if len(X.shape) == 2: - list_results = [self.function(bx) for bx in X] - else: - list_results = [self.function(X)] - - by = np.array(list_results) + by = self._output(X) by += scale_noise Y = np.expand_dims(by, axis=1) @@ -104,16 +103,10 @@ def output_constant_noise(self, X, scale_noise=0.01): return Y def output_gaussian_noise(self, X, scale_noise=0.01): - assert isinstance(X, np.ndarray) assert isinstance(scale_noise, float) - if len(X.shape) == 2: - list_results = [self.function(bx) for bx in X] - else: - list_results = [self.function(X)] - - by = np.array(list_results) - by += scale_noise * np.random.randn(by.shape[0]) + by = self._output(X) + by += scale_noise * self.random_state.randn(by.shape[0]) Y = np.expand_dims(by, axis=1) @@ -122,23 +115,20 @@ def output_gaussian_noise(self, X, scale_noise=0.01): return Y def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01): - assert isinstance(X, np.ndarray) assert isinstance(scale_noise, float) assert isinstance(sparsity, float) assert sparsity >= 0.0 and sparsity <= 1.0 assert sparsity < 0.5 + by = self._output(X) + if len(X.shape) == 2: num_X = X.shape[0] - list_results = [self.function(bx) for bx in X] else: num_X = 1 - list_results = [self.function(X)] - by = np.array(list_results) - - noise = np.random.randn(num_X) - mask = np.random.uniform(low=0.0, high=1.0, size=num_X) < sparsity + 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) by += scale_noise * noise diff --git a/benchmarks/inf_dim_ackley.py b/bayeso_benchmarks/inf_dim_ackley.py similarity index 91% rename from benchmarks/inf_dim_ackley.py rename to bayeso_benchmarks/inf_dim_ackley.py index 695c59e..ea15770 100644 --- a/benchmarks/inf_dim_ackley.py +++ b/bayeso_benchmarks/inf_dim_ackley.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx, diff --git a/benchmarks/inf_dim_cosines.py b/bayeso_benchmarks/inf_dim_cosines.py similarity index 90% rename from benchmarks/inf_dim_cosines.py rename to bayeso_benchmarks/inf_dim_cosines.py index e0e2747..50d9430 100644 --- a/benchmarks/inf_dim_cosines.py +++ b/bayeso_benchmarks/inf_dim_cosines.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/inf_dim_rosenbrock.py b/bayeso_benchmarks/inf_dim_rosenbrock.py similarity index 81% rename from benchmarks/inf_dim_rosenbrock.py rename to bayeso_benchmarks/inf_dim_rosenbrock.py index 558f8b5..242366e 100644 --- a/benchmarks/inf_dim_rosenbrock.py +++ b/bayeso_benchmarks/inf_dim_rosenbrock.py @@ -1,6 +1,11 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: February 8, 2021 +# + import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): @@ -17,6 +22,7 @@ def fun_target(bx, dim_bx): class Rosenbrock(Function): def __init__(self, dim_problem): assert isinstance(dim_problem, int) + assert dim_problem > 1 dim_bx = np.inf bounds = np.array([ diff --git a/benchmarks/inf_dim_sphere.py b/bayeso_benchmarks/inf_dim_sphere.py similarity index 89% rename from benchmarks/inf_dim_sphere.py rename to bayeso_benchmarks/inf_dim_sphere.py index bf12313..7d21361 100644 --- a/benchmarks/inf_dim_sphere.py +++ b/bayeso_benchmarks/inf_dim_sphere.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/one_dim_constant.py b/bayeso_benchmarks/one_dim_constant.py similarity index 92% rename from benchmarks/one_dim_constant.py rename to bayeso_benchmarks/one_dim_constant.py index efff339..3584e90 100644 --- a/benchmarks/one_dim_constant.py +++ b/bayeso_benchmarks/one_dim_constant.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx, constant): diff --git a/benchmarks/one_dim_gramacyandlee2012.py b/bayeso_benchmarks/one_dim_gramacyandlee2012.py similarity index 88% rename from benchmarks/one_dim_gramacyandlee2012.py rename to bayeso_benchmarks/one_dim_gramacyandlee2012.py index 8fe9e57..aca6936 100644 --- a/benchmarks/one_dim_gramacyandlee2012.py +++ b/bayeso_benchmarks/one_dim_gramacyandlee2012.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/one_dim_linear.py b/bayeso_benchmarks/one_dim_linear.py similarity index 92% rename from benchmarks/one_dim_linear.py rename to bayeso_benchmarks/one_dim_linear.py index 04d12e2..0dbe0b4 100644 --- a/benchmarks/one_dim_linear.py +++ b/bayeso_benchmarks/one_dim_linear.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx, slope): diff --git a/benchmarks/one_dim_step.py b/bayeso_benchmarks/one_dim_step.py similarity index 95% rename from benchmarks/one_dim_step.py rename to bayeso_benchmarks/one_dim_step.py index fd839ec..42c02da 100644 --- a/benchmarks/one_dim_step.py +++ b/bayeso_benchmarks/one_dim_step.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx, steps, step_values): diff --git a/bayeso_benchmarks/plot_benchmarks.py b/bayeso_benchmarks/plot_benchmarks.py new file mode 100644 index 0000000..17badd1 --- /dev/null +++ b/bayeso_benchmarks/plot_benchmarks.py @@ -0,0 +1,189 @@ +import numpy as np +import os +import matplotlib.pyplot as plt + + +def plot_1d(obj_fun, + str_fun, + str_x_axis=r'$x$', + str_y_axis=r'$f(x)$', + str_figures='../figures', +): + print(str_fun) + bounds = obj_fun.get_bounds() + print(bounds) + assert bounds.shape[0] == 1 + + X = np.linspace(bounds[0, 0], bounds[0, 1], 1000) + Y = obj_fun.output(X[..., np.newaxis]).flatten() + + assert len(X.shape) == 1 + assert len(Y.shape) == 1 + assert X.shape[0] == Y.shape[0] + + plt.rc('text', usetex=True) + + _ = plt.figure(figsize=(10, 6)) + ax = plt.gca() + + ax.plot(X, Y, + linewidth=4, + marker='None') + + ax.set_xlabel(str_x_axis, fontsize=36) + ax.set_ylabel(str_y_axis, fontsize=36) + ax.tick_params(labelsize=24) + + ax.set_xlim([np.min(X), np.max(X)]) + ax.grid() + + plt.tight_layout() + plt.savefig(os.path.join(str_figures, str_fun + '.pdf'), + format='pdf', + transparent=True, + bbox_inches='tight') + + plt.show() + +def plot_2d(obj_fun, + str_fun, + str_x1_axis=r'$x_1$', + str_x2_axis=r'$x_2$', + str_y_axis=r'$f(\mathbf{x})$', + str_figures='../figures', +): + print(str_fun) + 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) + 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])) + + Y = obj_fun.output(X).flatten() + + assert len(X.shape) == 2 + assert len(Y.shape) == 1 + assert X.shape[0] == Y.shape[0] + + Y = np.reshape(Y, (X1.shape[0], X2.shape[0])) + + plt.rc('text', usetex=True) + + _ = plt.figure(figsize=(8, 6)) + ax = plt.axes(projection='3d') + + surf = ax.plot_surface(X1, X2, Y, + cmap='coolwarm', + linewidth=0) + + ax.set_xlabel(str_x1_axis, fontsize=24, labelpad=10) + ax.set_ylabel(str_x2_axis, fontsize=24, labelpad=10) + ax.set_zlabel(str_y_axis, fontsize=24, labelpad=10) + ax.tick_params(labelsize=16) + + ax.set_xlim([np.min(X1), np.max(X1)]) + ax.set_ylim([np.min(X2), np.max(X2)]) + ax.grid() + + cbar = plt.colorbar(surf, + shrink=0.6, + aspect=12, + pad=0.15, + ) + cbar.ax.tick_params(labelsize=16) + + if np.max(Y) > 1000: + plt.ticklabel_format(axis='z', style='sci', scilimits=(0, 0), useMathText=True) + ax.zaxis.get_offset_text().set_fontsize(14) + + plt.tight_layout() + plt.savefig(os.path.join(str_figures, str_fun + '.pdf'), + format='pdf', + transparent=True, + bbox_inches='tight') + + plt.show() + + +if __name__ == '__main__': + # one dim. + from one_dim_gramacyandlee2012 import GramacyAndLee2012 as target_class + obj_fun = target_class() + plot_1d(obj_fun, 'gramacyandlee2012') + + from inf_dim_ackley import Ackley as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'ackley_1d') + + from inf_dim_cosines import Cosines as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'cosines_1d') + + from inf_dim_sphere import Sphere as target_class + obj_fun = target_class(1) + plot_1d(obj_fun, 'sphere_1d') + + # two dim. + from two_dim_beale import Beale as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'beale_2d') + + from two_dim_bohachevsky import Bohachevsky as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'bohachevsky_2d') + + from two_dim_branin import Branin as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'branin_2d') + + from two_dim_dejong5 import DeJong5 as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'dejong5_2d') + + from two_dim_dropwave import DropWave as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'dropwave_2d') + + from two_dim_eggholder import Eggholder as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'eggholder_2d') + + from two_dim_goldsteinprice import GoldsteinPrice as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'goldsteinprice_2d') + + from two_dim_holdertable import HolderTable as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'holdertable_2d') + + from two_dim_michalewicz import Michalewicz as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'michalewicz_2d') + + from two_dim_sixhumpcamel import SixHumpCamel as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'sixhumpcamel_2d') + + from two_dim_threehumpcamel import ThreeHumpCamel as target_class + obj_fun = target_class() + plot_2d(obj_fun, 'threehumpcamel_2d') + + from inf_dim_ackley import Ackley as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'ackley_2d') + + from inf_dim_cosines import Cosines as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'cosines_2d') + + from inf_dim_rosenbrock import Rosenbrock as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'rosenbrock_2d') + + from inf_dim_sphere import Sphere as target_class + obj_fun = target_class(2) + plot_2d(obj_fun, 'sphere_2d') diff --git a/benchmarks/six_dim_hartmann6d.py b/bayeso_benchmarks/six_dim_hartmann6d.py similarity index 94% rename from benchmarks/six_dim_hartmann6d.py rename to bayeso_benchmarks/six_dim_hartmann6d.py index 2e5b844..989f338 100644 --- a/benchmarks/six_dim_hartmann6d.py +++ b/bayeso_benchmarks/six_dim_hartmann6d.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/three_dim_hartmann3d.py b/bayeso_benchmarks/three_dim_hartmann3d.py similarity index 93% rename from benchmarks/three_dim_hartmann3d.py rename to bayeso_benchmarks/three_dim_hartmann3d.py index 78494b6..e3a56f2 100644 --- a/benchmarks/three_dim_hartmann3d.py +++ b/bayeso_benchmarks/three_dim_hartmann3d.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_beale.py b/bayeso_benchmarks/two_dim_beale.py similarity index 89% rename from benchmarks/two_dim_beale.py rename to bayeso_benchmarks/two_dim_beale.py index 2094b64..2e45e8f 100644 --- a/benchmarks/two_dim_beale.py +++ b/bayeso_benchmarks/two_dim_beale.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_bohachevsky.py b/bayeso_benchmarks/two_dim_bohachevsky.py similarity index 89% rename from benchmarks/two_dim_bohachevsky.py rename to bayeso_benchmarks/two_dim_bohachevsky.py index 936e58d..e3c5d22 100644 --- a/benchmarks/two_dim_bohachevsky.py +++ b/bayeso_benchmarks/two_dim_bohachevsky.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_branin.py b/bayeso_benchmarks/two_dim_branin.py similarity index 93% rename from benchmarks/two_dim_branin.py rename to bayeso_benchmarks/two_dim_branin.py index 538ee1f..edee15b 100644 --- a/benchmarks/two_dim_branin.py +++ b/bayeso_benchmarks/two_dim_branin.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx, a, b, c, r, s, t): diff --git a/bayeso_benchmarks/two_dim_dejong5.py b/bayeso_benchmarks/two_dim_dejong5.py new file mode 100644 index 0000000..f5a8c56 --- /dev/null +++ b/bayeso_benchmarks/two_dim_dejong5.py @@ -0,0 +1,57 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: February 8, 2021 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + A = np.array([ + [-32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0], + [-32.0, -32.0, -32.0, -32.0, -32.0, -16.0, -16.0, -16.0, -16.0, -16.0, 0.0, 0.0, 0.0, 0.0, 0.0, 16.0, 16.0, 16.0, 16.0, 16.0, 32.0, 32.0, 32.0, 32.0, 32.0], + ]) + y = 0.002 + + for ind in range(0, 25): + cur_y = 1.0 / (ind + 1.0 + (bx[0] - A[0, ind])**6 + (bx[1] - A[1, ind])**6) + y += cur_y + y = y**(-1) + + return y + + +class DeJong5(Function): + def __init__(self): + dim_bx = 2 + bounds = np.array([ + [-65.536, 65.536], + [-65.536, 65.536], + ]) + global_minimizers = np.array([ + [-32.10428207, -32.13705826], + [-32.07150588, -32.13705826], + [-32.03872968, -32.13705826], + [-32.00595349, -32.13705826], + [-31.97317729, -32.13705826], + [-31.9404011, -32.13705826], + [-31.90762491, -32.13705826], + [-32.13705826, -32.10428207], + [-32.10428207, -32.10428207], + [-32.07150588, -32.10428207], + [-32.03872968, -32.10428207], + [-32.00595349, -32.10428207], + [-31.97317729, -32.10428207], + [-31.9404011, -32.10428207], + [-31.90762491, -32.10428207], + [-31.87484871, -32.10428207], + ]) + global_minimum = 0.9980038753198021 + function = lambda bx: fun_target(bx, dim_bx) + + Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function) diff --git a/bayeso_benchmarks/two_dim_dropwave.py b/bayeso_benchmarks/two_dim_dropwave.py new file mode 100644 index 0000000..c8e325a --- /dev/null +++ b/bayeso_benchmarks/two_dim_dropwave.py @@ -0,0 +1,32 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: February 9, 2021 +# + +import numpy as np + +from bayeso_benchmarks.benchmark_base import Function + + +def fun_target(bx, dim_bx): + assert len(bx.shape) == 1 + assert bx.shape[0] == dim_bx + + y = -1.0 * (1 + np.cos(12.0 * np.sqrt(bx[0]**2 + bx[1]**2))) / (0.5 * (bx[0]**2 + bx[1]**2) + 2.0) + return y + + +class DropWave(Function): + def __init__(self): + dim_bx = 2 + bounds = np.array([ + [-5.12, 5.12], + [-5.12, 5.12], + ]) + global_minimizers = np.array([ + [0.0, 0.0], + ]) + global_minimum = -1.0 + function = lambda bx: fun_target(bx, dim_bx) + + Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function) diff --git a/benchmarks/two_dim_eggholder.py b/bayeso_benchmarks/two_dim_eggholder.py similarity index 91% rename from benchmarks/two_dim_eggholder.py rename to bayeso_benchmarks/two_dim_eggholder.py index 12b9676..43df2f2 100644 --- a/benchmarks/two_dim_eggholder.py +++ b/bayeso_benchmarks/two_dim_eggholder.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_goldsteinprice.py b/bayeso_benchmarks/two_dim_goldsteinprice.py similarity index 91% rename from benchmarks/two_dim_goldsteinprice.py rename to bayeso_benchmarks/two_dim_goldsteinprice.py index 25e0e3c..e5dbd0f 100644 --- a/benchmarks/two_dim_goldsteinprice.py +++ b/bayeso_benchmarks/two_dim_goldsteinprice.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_holdertable.py b/bayeso_benchmarks/two_dim_holdertable.py similarity index 90% rename from benchmarks/two_dim_holdertable.py rename to bayeso_benchmarks/two_dim_holdertable.py index 8b963a1..37309c3 100644 --- a/benchmarks/two_dim_holdertable.py +++ b/bayeso_benchmarks/two_dim_holdertable.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_michalewicz.py b/bayeso_benchmarks/two_dim_michalewicz.py similarity index 89% rename from benchmarks/two_dim_michalewicz.py rename to bayeso_benchmarks/two_dim_michalewicz.py index e9bd2c1..7555b2e 100644 --- a/benchmarks/two_dim_michalewicz.py +++ b/bayeso_benchmarks/two_dim_michalewicz.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_sixhumpcamel.py b/bayeso_benchmarks/two_dim_sixhumpcamel.py similarity index 89% rename from benchmarks/two_dim_sixhumpcamel.py rename to bayeso_benchmarks/two_dim_sixhumpcamel.py index 8f28f6c..64bdb81 100644 --- a/benchmarks/two_dim_sixhumpcamel.py +++ b/bayeso_benchmarks/two_dim_sixhumpcamel.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/benchmarks/two_dim_threehumpcamel.py b/bayeso_benchmarks/two_dim_threehumpcamel.py similarity index 88% rename from benchmarks/two_dim_threehumpcamel.py rename to bayeso_benchmarks/two_dim_threehumpcamel.py index bbd23ec..35ef4db 100644 --- a/benchmarks/two_dim_threehumpcamel.py +++ b/bayeso_benchmarks/two_dim_threehumpcamel.py @@ -1,11 +1,11 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np -from benchmarks.benchmark_base import Function +from bayeso_benchmarks.benchmark_base import Function def fun_target(bx, dim_bx): diff --git a/create_wheels_source.txt b/create_wheels_source.txt index 0c3fecd..e3e7cce 100644 --- a/create_wheels_source.txt +++ b/create_wheels_source.txt @@ -1,4 +1,4 @@ -# Install setuptools wheel first. +# Install setuptools wheel first, then command it. python2 setup.py sdist bdist_wheel python3 setup.py sdist bdist_wheel diff --git a/figures/ackley_1d.pdf b/figures/ackley_1d.pdf new file mode 100644 index 0000000..02c0db5 Binary files /dev/null and b/figures/ackley_1d.pdf differ diff --git a/figures/ackley_2d.pdf b/figures/ackley_2d.pdf new file mode 100644 index 0000000..0ec3594 Binary files /dev/null and b/figures/ackley_2d.pdf differ diff --git a/figures/beale_2d.pdf b/figures/beale_2d.pdf new file mode 100644 index 0000000..1682e8c Binary files /dev/null and b/figures/beale_2d.pdf differ diff --git a/figures/bohachevsky_2d.pdf b/figures/bohachevsky_2d.pdf new file mode 100644 index 0000000..281b8e9 Binary files /dev/null and b/figures/bohachevsky_2d.pdf differ diff --git a/figures/branin_2d.pdf b/figures/branin_2d.pdf new file mode 100644 index 0000000..3bf0d4b Binary files /dev/null and b/figures/branin_2d.pdf differ diff --git a/figures/cosines_1d.pdf b/figures/cosines_1d.pdf new file mode 100644 index 0000000..9ca615c Binary files /dev/null and b/figures/cosines_1d.pdf differ diff --git a/figures/cosines_2d.pdf b/figures/cosines_2d.pdf new file mode 100644 index 0000000..690616f Binary files /dev/null and b/figures/cosines_2d.pdf differ diff --git a/figures/dejong5_2d.pdf b/figures/dejong5_2d.pdf new file mode 100644 index 0000000..90a7e3c Binary files /dev/null and b/figures/dejong5_2d.pdf differ diff --git a/figures/dropwave_2d.pdf b/figures/dropwave_2d.pdf new file mode 100644 index 0000000..9a537bf Binary files /dev/null and b/figures/dropwave_2d.pdf differ diff --git a/figures/eggholder_2d.pdf b/figures/eggholder_2d.pdf new file mode 100644 index 0000000..a5b91cc Binary files /dev/null and b/figures/eggholder_2d.pdf differ diff --git a/figures/goldsteinprice_2d.pdf b/figures/goldsteinprice_2d.pdf new file mode 100644 index 0000000..c40742e Binary files /dev/null and b/figures/goldsteinprice_2d.pdf differ diff --git a/figures/gramacyandlee2012.pdf b/figures/gramacyandlee2012.pdf new file mode 100644 index 0000000..af7ff3c Binary files /dev/null and b/figures/gramacyandlee2012.pdf differ diff --git a/figures/holdertable_2d.pdf b/figures/holdertable_2d.pdf new file mode 100644 index 0000000..7800866 Binary files /dev/null and b/figures/holdertable_2d.pdf differ diff --git a/figures/michalewicz_2d.pdf b/figures/michalewicz_2d.pdf new file mode 100644 index 0000000..8cb1fce Binary files /dev/null and b/figures/michalewicz_2d.pdf differ diff --git a/figures/rosenbrock_2d.pdf b/figures/rosenbrock_2d.pdf new file mode 100644 index 0000000..83aa151 Binary files /dev/null and b/figures/rosenbrock_2d.pdf differ diff --git a/figures/sixhumpcamel_2d.pdf b/figures/sixhumpcamel_2d.pdf new file mode 100644 index 0000000..c7bbbf6 Binary files /dev/null and b/figures/sixhumpcamel_2d.pdf differ diff --git a/figures/sphere_1d.pdf b/figures/sphere_1d.pdf new file mode 100644 index 0000000..027f182 Binary files /dev/null and b/figures/sphere_1d.pdf differ diff --git a/figures/sphere_2d.pdf b/figures/sphere_2d.pdf new file mode 100644 index 0000000..aa6ef14 Binary files /dev/null and b/figures/sphere_2d.pdf differ diff --git a/figures/threehumpcamel_2d.pdf b/figures/threehumpcamel_2d.pdf new file mode 100644 index 0000000..91cb6ae Binary files /dev/null and b/figures/threehumpcamel_2d.pdf differ diff --git a/requirements-dev.txt b/requirements-dev.txt index e079f8a..d805a68 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1,2 @@ pytest +matplotlib diff --git a/setup.py b/setup.py index 0c821fe..9c49fe8 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,14 @@ from setuptools import setup path_requirements = 'requirements.txt' -list_packages = ['benchmarks'] +list_packages = ['bayeso_benchmarks'] with open(path_requirements) as f: required = f.read().splitlines() setup( name='bayeso-benchmarks', - version='0.1.3', + version='0.1.4', author='Jungtaek Kim', author_email='jtkim@postech.ac.kr', url='https://github.com/jungtaekkim/bayeso-benchmarks', diff --git a/tests/test_global_minimum.py b/tests/test_global_minimum.py index 2481762..94f87e2 100644 --- a/tests/test_global_minimum.py +++ b/tests/test_global_minimum.py @@ -1,14 +1,15 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_branin import * -from benchmarks.two_dim_eggholder import * -from benchmarks.two_dim_michalewicz import * +from bayeso_benchmarks.two_dim_branin import * +from bayeso_benchmarks.two_dim_eggholder import * +from bayeso_benchmarks.two_dim_michalewicz import * +from bayeso_benchmarks.two_dim_dejong5 import * TEST_EPSILON = 1e-5 @@ -54,3 +55,17 @@ def test_global_minimum_michalewicz(): print(grids[ind_minimum]) print(obj_fun.global_minimum - global_minimum_brute_force) assert (obj_fun.global_minimum - global_minimum_brute_force) < TEST_EPSILON + +def test_global_minimum_dejong5(): + class_fun = DeJong5 + + obj_fun = class_fun() + grids = obj_fun.get_grids(100) + vals_grids = obj_fun.output(grids) + ind_minimum = np.argmin(vals_grids) + global_minimum_brute_force = np.min(vals_grids) + + print(global_minimum_brute_force) + print(grids[((vals_grids - global_minimum_brute_force) < TEST_EPSILON)[:, 0]]) + print(obj_fun.global_minimum - global_minimum_brute_force) + assert (obj_fun.global_minimum - global_minimum_brute_force) < TEST_EPSILON diff --git a/tests/test_import.py b/tests/test_import.py index edb734c..6318a08 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,84 +1,88 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # def test_import_benchmarks(): - import benchmarks + import bayeso_benchmarks def test_import_benchmark_base(): - import benchmarks.benchmark_base - from benchmarks.benchmark_base import Function + import bayeso_benchmarks.benchmark_base + from bayeso_benchmarks.benchmark_base import Function def test_import_one_dim_constant(): - import benchmarks.one_dim_constant - from benchmarks.one_dim_constant import Constant + import bayeso_benchmarks.one_dim_constant + from bayeso_benchmarks.one_dim_constant import Constant def test_import_one_dim_gramacyandlee2012(): - import benchmarks.one_dim_gramacyandlee2012 - from benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 + import bayeso_benchmarks.one_dim_gramacyandlee2012 + from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012 def test_import_one_dim_linear(): - import benchmarks.one_dim_linear - from benchmarks.one_dim_linear import Linear + import bayeso_benchmarks.one_dim_linear + from bayeso_benchmarks.one_dim_linear import Linear def test_import_one_dim_step(): - import benchmarks.one_dim_step - from benchmarks.one_dim_step import Step + import bayeso_benchmarks.one_dim_step + from bayeso_benchmarks.one_dim_step import Step def test_import_two_dim_beale(): - import benchmarks.two_dim_beale - from benchmarks.two_dim_beale import Beale + import bayeso_benchmarks.two_dim_beale + from bayeso_benchmarks.two_dim_beale import Beale def test_import_two_dim_bohachevsky(): - import benchmarks.two_dim_bohachevsky - from benchmarks.two_dim_bohachevsky import Bohachevsky + import bayeso_benchmarks.two_dim_bohachevsky + from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky def test_import_two_dim_branin(): - import benchmarks.two_dim_branin - from benchmarks.two_dim_branin import Branin + import bayeso_benchmarks.two_dim_branin + from bayeso_benchmarks.two_dim_branin import Branin + +def test_import_two_dim_dropwave(): + import bayeso_benchmarks.two_dim_dropwave + from bayeso_benchmarks.two_dim_dropwave import DropWave def test_import_two_dim_eggholder(): - import benchmarks.two_dim_eggholder - from benchmarks.two_dim_eggholder import Eggholder + import bayeso_benchmarks.two_dim_eggholder + from bayeso_benchmarks.two_dim_eggholder import Eggholder def test_import_two_dim_goldsteinprice(): - import benchmarks.two_dim_goldsteinprice - from benchmarks.two_dim_goldsteinprice import GoldsteinPrice + import bayeso_benchmarks.two_dim_goldsteinprice + from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice def test_import_two_dim_holdertable(): - import benchmarks.two_dim_holdertable - from benchmarks.two_dim_holdertable import HolderTable + import bayeso_benchmarks.two_dim_holdertable + from bayeso_benchmarks.two_dim_holdertable import HolderTable def test_import_two_dim_michalewicz(): - import benchmarks.two_dim_michalewicz - from benchmarks.two_dim_michalewicz import Michalewicz + import bayeso_benchmarks.two_dim_michalewicz + from bayeso_benchmarks.two_dim_michalewicz import Michalewicz def test_import_two_dim_sixhumpcamel(): - import benchmarks.two_dim_sixhumpcamel - from benchmarks.two_dim_sixhumpcamel import SixHumpCamel + import bayeso_benchmarks.two_dim_sixhumpcamel + from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel def test_import_two_dim_threehumpcamel(): - import benchmarks.two_dim_threehumpcamel - from benchmarks.two_dim_threehumpcamel import ThreeHumpCamel + import bayeso_benchmarks.two_dim_threehumpcamel + from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel def test_import_three_dim_hartmann3d(): - import benchmarks.three_dim_hartmann3d - from benchmarks.three_dim_hartmann3d import Hartmann3D + import bayeso_benchmarks.three_dim_hartmann3d + from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D def test_import_six_dim_hartmann6d(): - import benchmarks.six_dim_hartmann6d - from benchmarks.six_dim_hartmann6d import Hartmann6D + import bayeso_benchmarks.six_dim_hartmann6d + from bayeso_benchmarks.six_dim_hartmann6d import Hartmann6D def test_import_inf_dim_ackley(): - import benchmarks.inf_dim_ackley - from benchmarks.inf_dim_ackley import Ackley + import bayeso_benchmarks.inf_dim_ackley + from bayeso_benchmarks.inf_dim_ackley import Ackley def test_import_inf_dim_rosenbrock(): - import benchmarks.inf_dim_rosenbrock - from benchmarks.inf_dim_rosenbrock import Rosenbrock + import bayeso_benchmarks.inf_dim_rosenbrock + from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock def test_import_inf_dim_sphere(): - import benchmarks.inf_dim_sphere - from benchmarks.inf_dim_sphere import Sphere + import bayeso_benchmarks.inf_dim_sphere + from bayeso_benchmarks.inf_dim_sphere import Sphere diff --git a/tests/test_inf_dim_ackley.py b/tests/test_inf_dim_ackley.py index 6dbd132..c064d33 100644 --- a/tests/test_inf_dim_ackley.py +++ b/tests/test_inf_dim_ackley.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.inf_dim_ackley import * +from bayeso_benchmarks.inf_dim_ackley import * class_fun = Ackley diff --git a/tests/test_inf_dim_cosines.py b/tests/test_inf_dim_cosines.py index 2d0eeec..09d9872 100644 --- a/tests/test_inf_dim_cosines.py +++ b/tests/test_inf_dim_cosines.py @@ -1,12 +1,13 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.inf_dim_cosines import * +from bayeso_benchmarks.inf_dim_cosines import * +# last updated: February 8, 2021 class_fun = Cosines diff --git a/tests/test_inf_dim_rosenbrock.py b/tests/test_inf_dim_rosenbrock.py index 0ace584..dacde66 100644 --- a/tests/test_inf_dim_rosenbrock.py +++ b/tests/test_inf_dim_rosenbrock.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.inf_dim_rosenbrock import * +from bayeso_benchmarks.inf_dim_rosenbrock import * class_fun = Rosenbrock diff --git a/tests/test_inf_dim_sphere.py b/tests/test_inf_dim_sphere.py index 9783bf5..8051831 100644 --- a/tests/test_inf_dim_sphere.py +++ b/tests/test_inf_dim_sphere.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.inf_dim_sphere import * +from bayeso_benchmarks.inf_dim_sphere import * class_fun = Sphere diff --git a/tests/test_one_dim_constant.py b/tests/test_one_dim_constant.py index 7c05674..215fec7 100644 --- a/tests/test_one_dim_constant.py +++ b/tests/test_one_dim_constant.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.one_dim_constant import * +from bayeso_benchmarks.one_dim_constant import * class_fun = Constant diff --git a/tests/test_one_dim_gramacyandlee2012.py b/tests/test_one_dim_gramacyandlee2012.py index e50ef96..5d3b921 100644 --- a/tests/test_one_dim_gramacyandlee2012.py +++ b/tests/test_one_dim_gramacyandlee2012.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.one_dim_gramacyandlee2012 import * +from bayeso_benchmarks.one_dim_gramacyandlee2012 import * class_fun = GramacyAndLee2012 diff --git a/tests/test_one_dim_linear.py b/tests/test_one_dim_linear.py index 528b168..b9720b7 100644 --- a/tests/test_one_dim_linear.py +++ b/tests/test_one_dim_linear.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.one_dim_linear import * +from bayeso_benchmarks.one_dim_linear import * class_fun = Linear diff --git a/tests/test_one_dim_step.py b/tests/test_one_dim_step.py index 0b24233..5dcfd2f 100644 --- a/tests/test_one_dim_step.py +++ b/tests/test_one_dim_step.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.one_dim_step import * +from bayeso_benchmarks.one_dim_step import * class_fun = Step diff --git a/tests/test_six_dim_hartmann6d.py b/tests/test_six_dim_hartmann6d.py index 00bf6d1..163b26a 100644 --- a/tests/test_six_dim_hartmann6d.py +++ b/tests/test_six_dim_hartmann6d.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.six_dim_hartmann6d import * +from bayeso_benchmarks.six_dim_hartmann6d import * class_fun = Hartmann6D diff --git a/tests/test_three_dim_hartmann3d.py b/tests/test_three_dim_hartmann3d.py index 3a4d59a..c81da66 100644 --- a/tests/test_three_dim_hartmann3d.py +++ b/tests/test_three_dim_hartmann3d.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.three_dim_hartmann3d import * +from bayeso_benchmarks.three_dim_hartmann3d import * class_fun = Hartmann3D diff --git a/tests/test_two_dim_beale.py b/tests/test_two_dim_beale.py index 5e65bef..818181c 100644 --- a/tests/test_two_dim_beale.py +++ b/tests/test_two_dim_beale.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_beale import * +from bayeso_benchmarks.two_dim_beale import * class_fun = Beale diff --git a/tests/test_two_dim_bohachevsky.py b/tests/test_two_dim_bohachevsky.py index e8f09f7..3cbc4a4 100644 --- a/tests/test_two_dim_bohachevsky.py +++ b/tests/test_two_dim_bohachevsky.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_bohachevsky import * +from bayeso_benchmarks.two_dim_bohachevsky import * class_fun = Bohachevsky diff --git a/tests/test_two_dim_branin.py b/tests/test_two_dim_branin.py index 292d33a..cb65aaa 100644 --- a/tests/test_two_dim_branin.py +++ b/tests/test_two_dim_branin.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_branin import * +from bayeso_benchmarks.two_dim_branin import * class_fun = Branin diff --git a/tests/test_two_dim_dejong5.py b/tests/test_two_dim_dejong5.py new file mode 100644 index 0000000..c13ab96 --- /dev/null +++ b/tests/test_two_dim_dejong5.py @@ -0,0 +1,43 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: February 8, 2021 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_dejong5 import * + +class_fun = DeJong5 + +TEST_EPSILON = 1e-3 + + +def test_init(): + obj_fun = class_fun() + +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.get_grids(3) + truths_grids = np.array([ + [499.99985236], + [499.99917292], + [499.99985236], + [499.99917292], + [12.67050581], + [499.99917292], + [499.99985236], + [499.99917292], + [499.99985236], + ]) + + 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) diff --git a/tests/test_two_dim_dropwave.py b/tests/test_two_dim_dropwave.py new file mode 100644 index 0000000..3b04f05 --- /dev/null +++ b/tests/test_two_dim_dropwave.py @@ -0,0 +1,43 @@ +# +# author: Jungtaek Kim (jtkim@postech.ac.kr) +# last updated: February 8, 2021 +# + +import numpy as np +import pytest + +from bayeso_benchmarks.two_dim_dropwave import * + +class_fun = DropWave + +TEST_EPSILON = 1e-3 + + +def test_init(): + obj_fun = class_fun() + +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.get_grids(3) + truths_grids = np.array([ + [-0.05229446], + [-0.07797539], + [-0.05229446], + [-0.07797539], + [-1.0], + [-0.07797539], + [-0.05229446], + [-0.07797539], + [-0.05229446], + ]) + + 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) diff --git a/tests/test_two_dim_eggholder.py b/tests/test_two_dim_eggholder.py index aa4ff94..58acb6c 100644 --- a/tests/test_two_dim_eggholder.py +++ b/tests/test_two_dim_eggholder.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_eggholder import * +from bayeso_benchmarks.two_dim_eggholder import * class_fun = Eggholder diff --git a/tests/test_two_dim_goldsteinprice.py b/tests/test_two_dim_goldsteinprice.py index cc9bce9..b6810c9 100644 --- a/tests/test_two_dim_goldsteinprice.py +++ b/tests/test_two_dim_goldsteinprice.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_goldsteinprice import * +from bayeso_benchmarks.two_dim_goldsteinprice import * class_fun = GoldsteinPrice diff --git a/tests/test_two_dim_holdertable.py b/tests/test_two_dim_holdertable.py index 34a1ea4..d1e61e4 100644 --- a/tests/test_two_dim_holdertable.py +++ b/tests/test_two_dim_holdertable.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_holdertable import * +from bayeso_benchmarks.two_dim_holdertable import * class_fun = HolderTable diff --git a/tests/test_two_dim_michalewicz.py b/tests/test_two_dim_michalewicz.py index f17f84a..7eb2eab 100644 --- a/tests/test_two_dim_michalewicz.py +++ b/tests/test_two_dim_michalewicz.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_michalewicz import * +from bayeso_benchmarks.two_dim_michalewicz import * class_fun = Michalewicz diff --git a/tests/test_two_dim_sixhumpcamel.py b/tests/test_two_dim_sixhumpcamel.py index 618e99f..1833dc3 100644 --- a/tests/test_two_dim_sixhumpcamel.py +++ b/tests/test_two_dim_sixhumpcamel.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_sixhumpcamel import * +from bayeso_benchmarks.two_dim_sixhumpcamel import * class_fun = SixHumpCamel diff --git a/tests/test_two_dim_threehumpcamel.py b/tests/test_two_dim_threehumpcamel.py index 6abe0f7..3486c58 100644 --- a/tests/test_two_dim_threehumpcamel.py +++ b/tests/test_two_dim_threehumpcamel.py @@ -1,12 +1,12 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # import numpy as np import pytest -from benchmarks.two_dim_threehumpcamel import * +from bayeso_benchmarks.two_dim_threehumpcamel import * class_fun = ThreeHumpCamel diff --git a/tests/test_version.py b/tests/test_version.py index fa68e0e..630bbe8 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,14 +1,14 @@ # # author: Jungtaek Kim (jtkim@postech.ac.kr) -# last updated: November 5, 2020 +# last updated: February 8, 2021 # -STR_VERSION = '0.1.3' +STR_VERSION = '0.1.4' def test_version_bayeso(): - import benchmarks - assert benchmarks.__version__ == STR_VERSION + import bayeso_benchmarks + assert bayeso_benchmarks.__version__ == STR_VERSION def test_version_setup(): import pkg_resources