Exemplo n.º 1
0
    pop.max_mini_y_dist_sampling,
    pop.hv_improvement_sampling,
]
sample_sizes = [1] * 6
sample_rates = [0.1, 0.8, 0.6, 0.6, 0.6, 1.]
sample_candidates = ['decision_space', 'pop'] + ['pm_hat'] * 3 + ['gap']

# ===============================Initialization================================

pop.config_surrogate(typ='rbf', params=params_surrogate, n_process=2)
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=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')
Exemplo n.º 2
0
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