max_generation=MAX_GENERATION, selection_fun=None, mutation_fun=None, mutation_rate=None, crossover_fun=nsga_crossover, trial_method='lhs', trial_criterion='cm', u=0., st=0.2) #pop.config_sampling(methods=samplers, sizes=sample_sizes, # sample_rates=sample_rates, # candidates=sample_candidates) pop.config_sampling(methods='default', sizes='default', rate='default', candidates='default') pop.run(params_ea=params_ea, params_surrogate=params_surrogate, theo=theo) # ================================Visualization================================ fig, (ax, ax_metric) = plt.subplots(1, 2, figsize=(10, 4), dpi=100) # Test surrogate results final_arc = pop.true_front x = [] y = [] for f in final_arc: x.append(f.fitness[0]) y.append(f.fitness[1])
def run_sim(n, path, simtitle, REVOLUTION, PROBLEM, seed): POP_SIZE = 100 MAX_GENERATION = 50 MAX_EPISODE = 100 MAX_EVAL = 1000 STOPPING_RULE = 'max_eval' MUTATION_RATE = 0.1 MUTATION_U = 0. MUTATION_ST = 0.2 REF = [-14.3, 0.05] MINIMIZE = True VERBOSE = True X_SCALER = StandardScaler() # Set global numpy random_state np.random.seed(seed) theo = np.genfromtxt('pareto_Kursawe.txt', dtype='f8') # Instantiate a population pop = GOMORS(size=POP_SIZE, problem=PROBLEM, max_generation=MAX_GENERATION, max_episode=MAX_EPISODE, reference=REF, minimize=MINIMIZE, stopping_rule=STOPPING_RULE, max_eval=MAX_EVAL, mutation_rate=MUTATION_RATE, revolution=REVOLUTION, embedded_ea=MOEAD, verbose=VERBOSE, no_improvement_step_tol=4) pop.selection_fun = pop.compute_front pop.mutation_fun = gaussian_mutator pop.crossover_fun = random_crossover # Parametrization params_ea = { 'u': MUTATION_U, 'st': MUTATION_ST, 'trial_method': 'lhs', 'trial_criterion': 'cm' } kernel = CubicKernel tail = LinearTail params_surrogate = \ {'kernel': kernel, 'tail': tail, 'maxp': MAX_EVAL + POP_SIZE, 'eta': 1e-8, } # ===============================Initialization============================ pop.config_surrogate(typ='rbf', params=params_surrogate, n_process=1, X_scaler=X_SCALER, warm_start=True) pop.config_gap_opt(at='least_crowded', radius=0.1, size=POP_SIZE, max_generation=MAX_GENERATION, selection_fun=None, mutation_fun=None, mutation_rate=None, crossover_fun=random_crossover, trial_method='lhs', trial_criterion='cm', u=0., st=0.2) pop.config_sampling(methods='default', sizes='default', rate='default', candidates='default') pop.run(params_ea=params_ea, params_surrogate=params_surrogate, theo=theo) # ============================= Save Results ================================ # # path to save directory = path + simtitle + '/' + str(n) + '/' if not os.path.exists(directory): os.makedirs(directory) pop.render_features(pop.true_front).tofile(directory + 'xs.dat') pop.render_targets(pop.true_front).tofile(directory + 'fs.dat') np.array(pop.hypervol_diff).tofile(directory + 'hv_diff.dat') np.array(pop.hypervol_cov).tofile(directory + 'hv_cov.dat') np.array(pop.hypervol_index).tofile(directory + 'hv_ind.dat') # ================================Visualization============================== # # plot_res(pop=pop, ref=theo, directory=directory) return pop