Skip to content

Commit

Permalink
ADD: sixhumpcamel
Browse files Browse the repository at this point in the history
  • Loading branch information
jungtaekkim committed Oct 3, 2018
1 parent 7992b32 commit 6646026
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bayeso/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
'global_minimum_y': -959.6407,
}

INFO_SIXHUMPCAMEL = {
'dim_fun': 2,
'bounds': np.array([
[-3.0, 3.0],
[-2.0, 2.0],
]),
'global_minimum_X': np.array([
[0.0898, -0.7126],
[-0.0898, 0.7126],
]),
'global_minimum_y': -1.0316,
}

def branin(X,
a=1.0,
b=5.1 / (4.0 * np.pi**2),
Expand Down Expand Up @@ -95,3 +108,15 @@ def eggholder(X):
Y = -1.0 * (X[:, 1] + 47.0) * np.sin(np.sqrt(np.abs(X[:, 1] + X[:, 0] / 2.0 + 47.0))) - X[:, 0] * np.sin(np.sqrt(np.abs(X[:, 0] - (X[:, 1] + 47.0))))
return Y

def sixhumpcamel(X):
assert isinstance(X, np.ndarray)
assert len(X.shape) == 1 or len(X.shape) == 2
if len(X.shape) == 1:
assert X.shape[0] == 2
X = np.expand_dims(X, axis=0)
elif len(X.shape) == 2:
assert X.shape[1] == 2

Y = (4.0 - 2.1 * X[:, 0]**2 + X[:, 0]**4 / 3.0) * X[:, 0]**2 + X[:, 0] * X[:, 1] + (-4.0 + 4.0 * X[:, 1]**2) * X[:, 1]**2
return Y

53 changes: 53 additions & 0 deletions examples/benchmarks/example_benchmarks_sixhumpcamel_bo_ei.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# example_benchmarks_sixhumpcamel_ei
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: October 04, 2018

import numpy as np
import os

from bayeso import bo
from bayeso import benchmarks
from bayeso.utils import utils_bo
from bayeso.utils import utils_plotting
from bayeso.utils import utils_benchmarks

INFO_TARGET = benchmarks.INFO_SIXHUMPCAMEL
STR_FUN_TARGET = 'sixhumpcamel'
PATH_SAVE = '../figures/benchmarks/'


def fun_target(X):
return benchmarks.sixhumpcamel(X)

def main():
int_bo = 5
int_iter = 50
int_init = 3

int_dim = 2

bounds = utils_benchmarks.get_bounds(INFO_TARGET, int_dim)
model_bo = bo.BO(bounds, debug=True)
list_Y = []
list_time = []
for ind_bo in range(0, int_bo):
print('BO Iteration', ind_bo)
X_final, Y_final, time_final = utils_bo.optimize_many_with_random_init(model_bo, fun_target, int_init, int_iter, str_initial_method_bo='uniform', str_initial_method_ao='uniform', int_samples_ao=100)
print(X_final)
print(Y_final)
print(time_final)
list_Y.append(Y_final)
list_time.append(time_final)

arr_Y = np.array(list_Y)
arr_Y = np.expand_dims(np.squeeze(arr_Y), axis=0)
arr_time = np.array(list_time)
arr_time = np.expand_dims(arr_time, axis=0)
utils_plotting.plot_minimum(arr_Y, [STR_FUN_TARGET], int_init, True, path_save=PATH_SAVE, str_postfix=STR_FUN_TARGET)
utils_plotting.plot_minimum_time(arr_time, arr_Y, [STR_FUN_TARGET], int_init, True, path_save=PATH_SAVE, str_postfix=STR_FUN_TARGET)

if __name__ == '__main__':
if not os.path.isdir(PATH_SAVE):
os.makedirs(PATH_SAVE)
main()

0 comments on commit 6646026

Please sign in to comment.