def return_igd(target_problem, number_pf_points, nd_front): # extract pareto front nd_front = check_array(nd_front) n_obj = target_problem.n_obj # for test # nd_front = np.loadtxt('non_dominated_front.csv', delimiter=',') if n_obj == 2: if 'DTLZ' not in target_problem.name(): true_pf = target_problem.pareto_front( n_pareto_points=number_pf_points) else: ref_dir = get_uniform_weights(number_pf_points, 2) true_pf = target_problem.pareto_front(ref_dir) max_by_f = np.amax(true_pf, axis=0) min_by_f = np.amin(true_pf, axis=0) # normalized to 0-1 nd_front = (nd_front - min_by_f) / (max_by_f - min_by_f) true_pf = np.atleast_2d(true_pf).reshape(-1, n_obj) true_pf = (true_pf - min_by_f) / (max_by_f - min_by_f) eu_dist = pairwise_distances(true_pf, nd_front, 'euclidean') eu_dist = np.min(eu_dist, axis=1) igd = np.mean(eu_dist) return igd
def return_hv(nd_front, reference_point, target_problem): p_name = target_problem.name() if 'DTLZ' in p_name and int(p_name[-1]) < 5: ref_dir = get_uniform_weights(10000, 2) true_pf = target_problem.pareto_front(ref_dir) else: true_pf = target_problem.pareto_front(n_pareto_points=10000) max_by_f = np.amax(true_pf, axis=0) min_by_f = np.amin(true_pf, axis=0) # normalized to 0-1 nd_front = (nd_front - min_by_f) / (max_by_f - min_by_f) n_obj = nd_front.shape[1] n_nd = nd_front.shape[0] reference_point_norm = reference_point nd_list = [] for i in range(n_nd): if np.all(nd_front[i, :] < reference_point): nd_list = np.append(nd_list, nd_front[i, :]) nd_list = np.atleast_2d(nd_list).reshape(-1, n_obj) if len(nd_list) > 0: hv = pg.hypervolume(nd_list) hv_value = hv.compute(reference_point_norm) else: hv_value = 0 return hv_value
from pymop.factory import get_problem, get_uniform_weights # for some problems the pareto front does not need any parameters pf = get_problem("tnk").pareto_front() pf = get_problem("osy").pareto_front() # for other problems the number of non-dominated points can be defined pf = get_problem("zdt1").pareto_front(n_pareto_points=100) # for DTLZ for example the reference direction should be provided, because the pareto front for the # specific problem will depend on the factory for the reference lines ref_dirs = get_uniform_weights(100, 3) pf = get_problem("dtlz1", n_var=7, n_obj=3).pareto_front(ref_dirs)
def plot_pareto_vs_ouputs_compare(prob_str, seed1, seed2, method1, method2, run_signature1, run_signature2): from mpl_toolkits.mplot3d import Axes3D from pymop.factory import get_uniform_weights problem = eval(prob_str) prob = problem.name() # read ouput f values output_folder_name = 'outputs\\' + prob + '_' + run_signature1 if os.path.exists(output_folder_name): print(output_folder_name) else: print(output_folder_name) raise ValueError( "results folder for EGO does not exist" ) output_f_name = output_folder_name + '\\best_f_seed_' + str(seed1) + '_' + method1 + '.joblib' best_f_ego = load(output_f_name) ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(best_f_ego) ndf = list(ndf) f_pareto = best_f_ego[ndf[0], :] best_f_ego = f_pareto n1 = len(best_f_ego) # read compare value hvr output_folder_name_2 = 'outputs\\' + prob + '_' + method2 if os.path.exists(output_folder_name): print(output_folder_name) else: raise ValueError( "results folder for EGO does not exist" ) output_f_name_2 = output_folder_name_2+ '\\best_f_seed_' + str(seed2) + '_' + method2 + '.joblib' best_f_ego_2 = load(output_f_name_2) ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(best_f_ego_2) ndf = list(ndf) f_pareto_2 = best_f_ego_2[ndf[0], :] best_f_ego_2 = f_pareto_2 n2 = len(best_f_ego_2) n_obj = problem.n_obj if n_obj == 2: if 'DTLZ' not in prob: true_pf = problem.pareto_front(n_pareto_points=10000) else: ref_dir = get_uniform_weights(100, 2) true_pf = problem.pareto_front(ref_dir) max_by_truepf = np.amax(true_pf, axis=0) min_by_truepf = np.amin(true_pf, axis=0) # plot pareto front fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(8, 5)) ax1.scatter(true_pf[:, 0], true_pf[:, 1], s=0.2) ax1.scatter(best_f_ego[:, 0], best_f_ego[:, 1], c='r', marker='o') ax1.legend(['pareto front', method1]) ax1.set_title(prob + ' ' + method1) # for i in range(n1): # zuobiao = '[' + "{:4.2f}".format(f_pareto[i, 0]) + ', ' + "{:4.2f}".format(f_pareto[i, 1]) + ']' # ax1.text(f_pareto[i, 0], f_pareto[i, 1], zuobiao) ax2.scatter(true_pf[:, 0], true_pf[:, 1], s=0.2) ax2.scatter(best_f_ego_2[:, 0], best_f_ego_2[:, 1], c='r', marker='o') # for i in range(n2): # zuobiao = '[' + "{:4.2f}".format(f_pareto_r[i, 0]) + ', ' + "{:4.2f}".format(f_pareto_r[i, 1]) + ']' # ax2.text(f_pareto_r[i, 0], f_pareto_r[i, 1], zuobiao) # ax2.legend([ 'pareto front', method2]) ax2.set_title(prob + ' ' + method2) # p = ax2.get_ylim() # ax1.set_ylim(p) saveName = 'visualization_2\\' + prob + '_' + method1 + '_and_' + method2 + '.png' plt.savefig(saveName) else: ref_dir = get_uniform_weights(1000, 3) true_pf = problem.pareto_front(ref_dir) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(true_pf[:, 0], true_pf[:, 1], true_pf[:, 2], c='r', marker='x') ax.scatter(best_f_ego[:, 0], best_f_ego[:, 1], best_f_ego[:, 2], c='b', marker='o') ax.view_init(30, 60) ax.set_title(prob + run_signature) ax.legend(['true_pf', method]) saveName = 'visualization\\' + run_signature + prob + '_' + method + '_compare2pf.png' plt.savefig(saveName) plt.show() a = 1
def plot_pareto_vs_ouputs(prob, seed, method, run_signature, visualization_folder_name): from mpl_toolkits.mplot3d import Axes3D from pymop.factory import get_uniform_weights # read ouput f values problem = eval(prob) prob = problem.name() output_folder_name = 'outputs\\experiment_post_process_100_evaluation\\' + prob + '_' + run_signature if os.path.exists(output_folder_name): print(output_folder_name) else: raise ValueError( "results folder for EGO does not exist" ) output_f_name = output_folder_name + '\\best_f_seed_' + str(seed[0]) + '_' + method + '.joblib' best_f_ego = load(output_f_name) for s in seed[1:]: output_f_name = output_folder_name + '\\best_f_seed_' + str(s) + '_' + method+ '.joblib' best_f_ego1 = load(output_f_name) best_f_ego = np.vstack((best_f_ego, best_f_ego1)) ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(best_f_ego) ndf = list(ndf) f_pareto = best_f_ego[ndf[0], :] best_f_ego = f_pareto n = len(best_f_ego) n_obj = problem.n_obj if n_obj == 2: if 'DTLZ' not in prob: true_pf = problem.pareto_front(n_pareto_points=10000) else: ref_dir = get_uniform_weights(100, 2) true_pf = problem.pareto_front(ref_dir) max_by_truepf = np.amax(true_pf, axis=0) min_by_truepf = np.amin(true_pf, axis=0) # plot pareto front fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(8, 5)) ax1.scatter(best_f_ego[:, 0], best_f_ego[:, 1], marker='o') ax1.scatter(true_pf[:, 0], true_pf[:, 1], marker='x') ax1.legend([method, 'true_pf']) ax1.set_title(prob + ' ' + run_signature) for i in range(n): zuobiao = '[' + "{:4.2f}".format(f_pareto[i, 0]) + ', ' + "{:4.2f}".format(f_pareto[i, 1]) + ']' ax1.text(f_pareto[i, 0], f_pareto[i, 1], zuobiao) ax2.scatter(best_f_ego[:, 0], best_f_ego[:, 1], marker='o') ax2.scatter(true_pf[:, 0], true_pf[:, 1], marker='x',) ax2.set(xlim=(min_by_truepf[0], max_by_truepf[0]), ylim=(min_by_truepf[1], max_by_truepf[1])) ax2.legend([method, 'true_pf']) ax2.set_title(prob +' zoom in ' + run_signature) working_folder = os.getcwd() result_folder = working_folder + '\\' + visualization_folder_name if not os.path.isdir(result_folder): # shutil.rmtree(result_folder) # os.mkdir(result_folder) os.mkdir(result_folder) saveName = result_folder + '\\' + method + '_' + prob + '_seed_' + str(seed[0]) + '.png' plt.savefig(saveName) else: ref_dir = get_uniform_weights(1000, 3) true_pf = problem.pareto_front(ref_dir) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(true_pf[:, 0], true_pf[:, 1], true_pf[:, 2],c='r', marker='x') ax.scatter(best_f_ego[:, 0], best_f_ego[:, 1], best_f_ego[:, 2], c='b', marker='o') ax.view_init(30, 60) ax.set_title(prob + ' ' + run_signature) ax.legend(['true_pf', method]) saveName = 'visualization\\' + run_signature + prob + '_' + method + '_compare2pf.png' plt.savefig(saveName) # plt.show() a = 1
sum_min_dist = 0 for i in range(reference.shape[0]): min_dist = 100000000 for j in range(pop_fitness.shape[0]): dist = np.linalg.norm(reference[i] - pop_fitness[j]) if (dist < min_dist): min_dist = dist sum_min_dist += min_dist return sum_min_dist / reference.shape[0] # dt = DTLZ2(num_objectives, num_variables) problem = DTLZ2(n_var=num_variables, n_obj=num_objectives) eval_func = problem.evaluate p = initialize(n, num_variables) reference = problem.pareto_front(get_uniform_weights(150, num_objectives)) t = 0 igds = [] while (not termination(number_evaluations, t)): grid = grid_setting(p, div, eval_func, num_objectives) p_prime = mating_selection(p, grid, number_parents, num_variables, eval_func) p_double_prime = variation(p_prime, pc, pm, eta_c, eta_m) p = environmental_selection(p, p_double_prime, div, eval_func, num_objectives) igd_val = igd_fitness(p, eval_func, num_objectives, reference) print('# ', t, ' : ', "{0:.3f}".format(igd_val)) igds.append(igd_val) t += 1 print('best: ', "{0:.3f}".format(min(igds)))
def main(seed_index, target_problem, enable_crossvalidation, method_selection, run_signature): # this following one line is for work around 1d plot in multiple-processing settings mp.freeze_support() np.random.seed(seed_index) recordFlag = False target_problem = eval(target_problem) # test variable eim_compare = [] print('Problem %s, seed %d' % (target_problem.name(), seed_index)) hv_ref = [1.1, 1.1] # collect problem parameters: number of objs, number of constraints n_sur_objs = target_problem.n_obj n_sur_cons = target_problem.n_constr n_vals = target_problem.n_var if n_sur_objs > 2: stop = 200 else: stop = 100 number_of_initial_samples = 11 * n_vals - 1 n_iter = 300 # stopping criterion set if 'WFG' in target_problem.name(): stop = 250 number_of_initial_samples = 200 train_x, train_y, cons_y = init_xy(number_of_initial_samples, target_problem, seed_index) # test # stop = 400 # test # train_y = np.loadtxt('sample_y.csv', delimiter=',') # for evalparas compatibility across differenct algorithms # nadir/ideal initialization on nd front no 2d alignment fix nadir, ideal = initNormalization_by_nd(train_y) # kriging data preparison # initialization before infill interation if method_selection == 'eim': norm_train_y = normalization_with_self(train_y) krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) elif method_selection == 'eim_nd': norm_train_y = normalization_with_nd(train_y) krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) elif method_selection == 'eim_r': norm_train_y = normalization_with_nadir_ideal(train_y, nadir, ideal) krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) elif method_selection == 'eim_r3': norm_train_y = normalization_with_nadir_ideal(train_y, nadir, ideal) krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) else: norm_train_y = None krg, krg_g = cross_val_krg(train_x, train_y, cons_y, enable_crossvalidation) # always conduct reference search on a initialized samples if method_selection == 'hvr' or method_selection == 'hv_r3' or method_selection == 'eim_r' or method_selection == 'eim_r3': guide_x = return_current_extreme(train_x, train_y) x_out = check_krg_ideal_points(krg, n_vals, n_sur_cons, n_sur_objs, target_problem.xl, target_problem.xu, guide_x) next_y = np.atleast_2d([ideal[0] - 1, ideal[1] - 1]) # force to estimate train_x, train_y, norm_train_y, cons_y, krg, krg_g, nadir, ideal, est_flag = update_nadir( train_x, train_y, norm_train_y, cons_y, next_y, # flag for initialization target_problem, x_out, krg, krg_g, nadir, ideal, enable_crossvalidation, method_selection, ) # test ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(train_y) ndf = list(ndf) ndf_size = len(ndf) # extract nd for normalization if len(ndf[0]) > 1: ndf_extend = ndf[0] else: ndf_extend = np.append(ndf[0], ndf[1]) nd_front = train_y[ndf_extend, :] min_pf_by_feature = ideal max_pf_by_feature = nadir norm_nd = (nd_front - min_pf_by_feature) / (max_pf_by_feature - min_pf_by_feature) hv = pg.hypervolume(norm_nd) hv_value = hv.compute([1.1, 1.1]) # create EI problem evalparas = { 'train_x': train_x, 'train_y': train_y, 'norm_train_y': norm_train_y, 'krg': krg, 'krg_g': krg_g, 'nadir': nadir, 'ideal': ideal, 'feasible': np.array([]), 'ei_method': method_selection } # construct ei problems ei_problem = get_problem_from_func( acqusition_function, target_problem.xl, # row direction target_problem.xu, n_var=n_vals, func_args=evalparas) x_bounds = np.vstack( (target_problem.xl, target_problem.xu)).T.tolist() # for ea, column direction start_all = time.time() # start the searching process plot_flag = False plt.ion() for iteration in range(n_iter): print('iteration %d' % iteration) # check feasibility in main loop, update evalparas['feasible'] evalparas = feasible_check(train_x, target_problem, evalparas) ''' if train_x.shape[0] % 5 == 0: recordFlag = utilities.intermediate_save(target_problem, method_selection, seed_index, iteration, krg, train_y, nadir, ideal) ''' start = time.time() # main loop for finding next x candidate_x = np.zeros((1, n_vals)) candidate_y = [] num_pop = 50 num_gen = 50 if 'ZDT' in target_problem.name(): num_pop = 200 num_gen = 200 for restart in range(4): ''' NSGAII pop_x, pop_f, pop_g, archive_x, archive_f, archive_g, record = optimizer_EI.optimizer(ei_problem, ei_problem.n_obj, ei_problem.n_constr, x_bounds, recordFlag, # pop_test=pop_test, pop_test=None, mut=0.1, crossp=0.9, popsize=50, its=50, **evalparas) ''' # DE pop_x, pop_f = optimizer_EI.optimizer_DE( ei_problem, ei_problem.n_obj, ei_problem.n_constr, x_bounds, recordFlag, # pop_test=pop_test, pop_test=None, F=0.8, CR=0.8, NP=num_pop, itermax=num_gen, flag=plot_flag, **evalparas) candidate_x = np.vstack((candidate_x, pop_x[0, :])) candidate_y = np.append(candidate_y, pop_f[0, :]) ''' if recordFlag: saveName = 'intermediate\\' + target_problem.name() + '_' + method_selection+ '_seed_' + str(seed_index) + 'search_record_iteration_' + str(iteration) + '_restart_' + str(restart) + '.joblib' dump(record, saveName) ''' end = time.time() lasts = (end - start) # print('propose to next x in iteration %d uses %.2f sec' % (iteration, lasts)) w = np.argwhere(candidate_y == np.min(candidate_y)) metric_opt = np.min(candidate_y) # print('optimization of eim:') # eim_compare.append(np.min(candidate_y)) # print(np.min(candidate_y)) # propose next_x location next_x = candidate_x[w[0] + 1, :] # test # next_x = proposed_x[iteration, :] # print(next_x) # dimension re-check next_x = np.atleast_2d(next_x).reshape(-1, n_vals) # generate corresponding f and g out = {} target_problem._evaluate(next_x, out) next_y = out['F'] # print(next_y) ''' if train_x.shape[0] % 5 == 0: saveName = 'intermediate\\' + target_problem.name() + '_' + method_selection + '_seed_' + str(seed_index) + 'nextF_iteration_' + str(iteration) + '.joblib' dump(next_y, saveName) ''' recordFlag = False if 'G' in out.keys(): next_cons_y = out['G'] next_cons_y = np.atleast_2d(next_cons_y) else: next_cons_y = None # -----------plot ------------- # plot progress plt.clf() if 'DTLZ' in target_problem.name() and int( target_problem.name()[-1]) < 5: ref_dir = get_uniform_weights(100, 2) true_pf = target_problem.pareto_front(ref_dir) else: true_pf = target_problem.pareto_front(n_pareto_points=100) ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(train_y) ndf = list(ndf) nd_front = train_y[ndf[0], :] f1_pred, _ = krg[0].predict(next_x) f2_pred, _ = krg[1].predict(next_x) f_pred = np.hstack((f1_pred, f2_pred)) if method_selection == 'eim_r': f_pred = f_pred * (nadir - ideal) + ideal if method_selection == 'eim': f_min_by_feature = np.amin(train_y, axis=0) f_max_by_feature = np.max(train_y, axis=0) f_pred = f_pred * (f_max_by_feature - f_min_by_feature) + f_min_by_feature if method_selection == 'eim_nd': nd_front_index = return_nd_front(train_y) nd_front_plot = train_y[nd_front_index, :] f_min_by_feature = np.amin(nd_front_plot, axis=0) f_max_by_feature = np.max(nd_front_plot, axis=0) f_pred = f_pred * (f_max_by_feature - f_min_by_feature) + f_min_by_feature if method_selection == 'hv': nd_front_index = return_nd_front(train_y) nd_front_plot = train_y[nd_front_index, :] f_min_by_feature = np.amin(nd_front_plot, axis=0) f_max_by_feature = np.max(nd_front_plot, axis=0) reference_point = 1.1 * (f_max_by_feature - f_min_by_feature) + f_min_by_feature if method_selection == 'hvr' or method_selection == 'hv_r3': reference_point = 1.1 * (nadir - ideal) + ideal plt.grid(True) plt.scatter(true_pf[:, 0], true_pf[:, 1], s=0.2) plt.scatter(next_y[:, 0], next_y[:, 1], marker="D", c='red') text2 = 'real next y' plt.text(next_y[:, 0], next_y[:, 1], text2) plt.scatter(train_y[:, 0], train_y[:, 1], marker="o", s=1, c='k') plt.scatter(nd_front[:, 0], nd_front[:, 1], marker='o', c='c') plt.scatter(f_pred[:, 0], f_pred[:, 1], marker="P") text1 = ' predicted next y' + "{:4.2f}".format( metric_opt) + " [{:4.2f}".format( f_pred[0, 0]) + ' ' + "{:4.2f}]".format(f_pred[0, 1]) plt.text(f_pred[:, 0], f_pred[:, 1], text1) if method_selection == 'eim_r' or method_selection == 'eim_r3' or method_selection == 'hv_r3' or method_selection == 'hvr': plt.scatter(nadir[0], nadir[1], marker='+', c='g') plt.text(nadir[0], nadir[1], 'nadir') plt.scatter(ideal[0], ideal[1], marker='+', c='g') plt.text(ideal[0], ideal[1], 'ideal') tt = " [{:4.2f}".format( reference_point[0]) + ' ' + "{:4.2f}]".format( reference_point[1]) plt.scatter(reference_point[0], reference_point[1], marker='+', c='red') plt.text(reference_point[0], reference_point[1] + 0.2, tt) if iteration == 0: plt.scatter(train_y[-1, 0], train_y[-1, 1], marker='x', c='black') plt.scatter(train_y[-2, 0], train_y[-2, 1], marker='x', c='black') if method_selection == 'eim' or method_selection == 'eim_nd' or method_selection == 'hv': plt.scatter(f_min_by_feature[0], f_min_by_feature[1], marker='+', c='g') plt.text(f_min_by_feature[0], f_min_by_feature[1], 'ideal') plt.scatter(f_max_by_feature[0], f_max_by_feature[1], marker='+', c='g') tt = " [{:4.2f}".format( f_max_by_feature[0]) + ' ' + "{:4.2f}]".format( f_max_by_feature[1]) plt.text(f_max_by_feature[0] - 0.2, f_max_by_feature[1] - 0.2, tt) tt = " [{:4.2f}".format( reference_point[0]) + ' ' + "{:4.2f}]".format( reference_point[1]) plt.scatter(reference_point[0], reference_point[1], marker='+', c='red') plt.text(reference_point[0], reference_point[1], tt) # add new proposed data train_x = np.vstack((train_x, next_x)) train_y = np.vstack((train_y, next_y)) # print('train x size %d' % train_x.shape[0]) if n_sur_cons > 0: cons_y = np.vstack((cons_y, next_cons_y)) #--------- start = time.time() # use extended data to train krging model # output hv during the search n_x = train_x.shape[0] nd_front_index = return_nd_front(train_y) nd_front = train_y[nd_front_index, :] hv = return_hv(nd_front, hv_ref, target_problem) igd = return_igd(target_problem, 10000, nd_front) print( 'iteration: %d, number evaluation: %d, hv of current nd_front: %.4f, igd is: %.4f' % (iteration, n_x, hv, igd)) #---------plot-------------------------------- t = 'hv after adding new point {:6.4f}'.format(hv) plt.title(t) # kriging update with newly added x/f if method_selection == 'eim': norm_train_y = normalization_with_self(train_y) krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) elif method_selection == 'eim_nd': norm_train_y = normalization_with_nd(train_y) krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) # elif method_selection == 'eim_r': # norm_train_y = normalization_with_nadir_ideal(train_y, nadir, ideal) # krg, krg_g = cross_val_krg(train_x, norm_train_y, cons_y, enable_crossvalidation) elif method_selection == 'hv': norm_train_y = None krg, krg_g = cross_val_krg(train_x, train_y, cons_y, enable_crossvalidation) # new evaluation added depending on condition if method_selection == 'hvr' or method_selection == 'eim_r': if train_x.shape[0] == 70: a = 0 guide_x = return_current_extreme(train_x, train_y) x_out = check_krg_ideal_points(krg, n_vals, n_sur_cons, n_sur_objs, target_problem.xl, target_problem.xu, guide_x) train_x, train_y, norm_train_y, cons_y, krg, krg_g, nadir, ideal, est_flag = update_nadir( train_x, train_y, norm_train_y, cons_y, next_y, target_problem, x_out, krg, krg_g, nadir, ideal, enable_crossvalidation, method_selection) savename = 'visualization\\' + target_problem.name( ) + '_' + method_selection + '_guide_' + str( seed_index) + '_iteration_' + str(train_x.shape[0]) + '.png' if est_flag == True: plt.scatter(train_y[-1, 0], train_y[-1, 1], marker='x', c='red') plt.scatter(train_y[-2, 0], train_y[-2, 1], marker='x', c='red') plt.savefig(savename) # plt.pause(0.5) # -----------plot ends ------------- # r3 does not add if method_selection == 'eim_r3' or method_selection == 'hv_r3': guide_x = return_current_extreme(train_x, train_y) x_out = check_krg_ideal_points(krg, n_vals, n_sur_cons, n_sur_objs, target_problem.xl, target_problem.xu, guide_x) train_x, train_y, norm_train_y, cons_y, krg, krg_g, nadir, ideal = update_nadir_with_estimate( train_x, train_y, norm_train_y, cons_y, next_y, target_problem, x_out, krg, krg_g, nadir, ideal, enable_crossvalidation, method_selection) savename = 'visualization\\' + target_problem.name( ) + '_' + method_selection + '_guide_' + str( seed_index) + '_iteration_' + str(train_x.shape[0]) + '.png' plt.savefig(savename) # plt.pause(0.5) # -----------plot ends ------------- savename = 'visualization\\' + target_problem.name( ) + '_' + method_selection + '_guide_' + str( seed_index) + '_iteration_' + str(train_x.shape[0]) + '.png' plt.savefig(savename) # -----------plot ends ------------- lasts = (end - start) # print('cross-validation %d uses %.2f sec' % (iteration, lasts)) # update ea parameters evalparas['train_x'] = train_x evalparas['train_y'] = train_y evalparas['norm_train_y'] = norm_train_y evalparas['krg'] = krg evalparas['krg_g'] = krg_g evalparas['nadir'] = nadir evalparas['ideal'] = ideal # stopping criteria sample_n = train_x.shape[0] if sample_n == stop: break if sample_n > stop: vio_more = np.arange(stop, sample_n) train_y = np.delete(train_y, vio_more, 0) train_x = np.delete(train_x, vio_more, 0) break plt.ioff() end_all = time.time() print('overall time %.4f ' % (end_all - start_all)) save_hv_igd(train_x, train_y, hv_ref, seed_index, target_problem, method_selection) post_process(train_x, train_y, cons_y, target_problem, seed_index, method_selection, run_signature)