def main(): # (max_depth, n_estimators) int_init = 3 model_bo = bo.BO(np.array([[0.1, 2]]), debug=True) list_Y = [] list_time = [] for _ in range(0, 10): X_final, Y_final, time_final, _, _ = utils_bo.optimize_many_with_random_init( model_bo, fun_target, int_init, 10, str_initial_method_bo='uniform', str_initial_method_ao='uniform', int_samples_ao=100) 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, ['ridge'], int_init, True, path_save=PATH_SAVE, str_postfix='ridge') utils_plotting.plot_minimum_time(arr_time, arr_Y, ['ridge'], int_init, True, path_save=PATH_SAVE, str_postfix='ridge')
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 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 test_plot_minimum(): num_model = 2 num_bo = 3 num_iter = 10 arr_minima = np.ones((num_model, num_bo, num_iter)) list_str_label = ['abc', 'def'] int_init = 3 is_std = True with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, 1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, 'abc', is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, 1, int_init, is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(1, list_str_label, int_init, is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(np.ones((10, 2)), list_str_label, int_init, is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(np.ones(2), list_str_label, int_init, is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, ['abc', 'def', 'ghi'], int_init, is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, 12, is_std) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, is_marker=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, is_legend=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, is_tex=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, path_save=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, str_postfix=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, str_x_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, str_y_axis=1) with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, time_pause='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, range_shade='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, markers='abc') with pytest.raises(AssertionError) as error: utils_plotting.plot_minimum(arr_minima, list_str_label, int_init, is_std, colors='abc')