-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jungtaekkim/0.1.7
0.1.7
- Loading branch information
Showing
106 changed files
with
7,201 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
# | ||
# author: Jungtaek Kim ([email protected]) | ||
# 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,17 +24,58 @@ | |
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 | ||
from bayeso_benchmarks.two_dim_kim1 import Kim1 | ||
from bayeso_benchmarks.two_dim_kim2 import Kim2 | ||
from bayeso_benchmarks.two_dim_kim3 import Kim3 | ||
from bayeso_benchmarks.two_dim_michalewicz import Michalewicz | ||
from bayeso_benchmarks.two_dim_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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
# | ||
# author: Jungtaek Kim ([email protected]) | ||
# last updated: May 1, 2021 | ||
# last updated: December 13, 2022 | ||
# | ||
|
||
import numpy as np | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
# author: Jungtaek Kim ([email protected]) | ||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# author: Jungtaek Kim ([email protected]) | ||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# author: Jungtaek Kim ([email protected]) | ||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# author: Jungtaek Kim ([email protected]) | ||
# 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) |
Oops, something went wrong.