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)
def main(str_optimizer_method_gp, str_mlm_method, str_ms_method, int_bo, int_iter, int_init): int_dim = 2 bounds = utils_benchmarks.get_bounds(INFO_TARGET, int_dim) list_Y = [] list_time = [] for ind_bo in range(0, int_bo): print('BO Iteration', ind_bo) model_bo = bo.BO(bounds, str_optimizer_method_gp=str_optimizer_method_gp, debug=False) 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, str_mlm_method=str_mlm_method, str_modelselection_method=str_ms_method, int_seed=77*(ind_bo+1)) list_Y.append(Y_final) list_time.append(time_final) arr_Y = np.array(list_Y) if int_bo == 1: arr_Y = np.expand_dims(np.squeeze(arr_Y), axis=0) else: arr_Y = np.squeeze(arr_Y) arr_Y = np.expand_dims(arr_Y, axis=0) arr_time = np.array(list_time) arr_time = np.expand_dims(arr_time, axis=0) print(np.array2string(arr_Y, separator=',')) print(np.array2string(arr_time, separator=',')) utils_plotting.plot_minimum(arr_Y, [STR_FUN_TARGET], int_init, True, path_save=None, str_postfix=None) utils_plotting.plot_minimum_time(arr_time, arr_Y, [STR_FUN_TARGET], int_init, True, path_save=None, str_postfix=None) return arr_Y, arr_time
def test_get_bounds(): info_branin = copy.deepcopy(benchmarks.INFO_BRANIN) info_ackley = copy.deepcopy(benchmarks.INFO_ACKLEY) with pytest.raises(AssertionError) as error: utils_benchmarks.get_bounds(1, 2) with pytest.raises(AssertionError) as error: utils_benchmarks.get_bounds(info_branin, 1.2) with pytest.raises(ValueError) as error: utils_benchmarks.get_bounds(info_branin, 3) with pytest.raises(AssertionError) as error: utils_benchmarks.get_bounds(info_branin, np.inf) with pytest.raises(AssertionError) as error: utils_benchmarks.get_bounds(info_branin, -2) with pytest.raises(AssertionError) as error: utils_benchmarks.get_bounds(info_ackley, np.inf) with pytest.raises(AssertionError) as error: utils_benchmarks.get_bounds(info_ackley, -2) bounds = utils_benchmarks.get_bounds(info_branin, 2) assert (bounds == info_branin['bounds']).all() bounds = utils_benchmarks.get_bounds(info_ackley, 4) assert (bounds == np.repeat(info_ackley['bounds'], 4, axis=0)).all()