コード例 #1
0
def run_param_search(problem, output_dir):
    rhc = mlrose.RHCRunner(problem=problem,
                           experiment_name="RHC",
                           output_directory=output_dir,
                           seed=42,
                           iteration_list=2**np.arange(15),
                           max_attempts=1000,
                           restart_list=[10])
    rhc_run_stats, rhc_run_curves = rhc.run()
    sa = mlrose.SARunner(problem=problem,
                         experiment_name="SA",
                         output_directory=output_dir,
                         seed=42,
                         iteration_list=2**np.arange(20),
                         max_attempts=1000,
                         temperature_list=[100, 250, 500],
                         decay_list=[mlrose.ExpDecay, mlrose.GeomDecay])
    sa_run_stats, sa_run_curves = sa.run()
    ga = mlrose.GARunner(problem=problem,
                         experiment_name="GA",
                         output_directory=output_dir,
                         seed=42,
                         iteration_list=2**np.arange(13),
                         max_attempts=1000,
                         population_sizes=[100, 200, 300],
                         mutation_rates=[0.1, 0.2, 0.3])
    ga_run_stats, ga_run_curves = ga.run()
    mimic = mlrose.MIMICRunner(problem=problem,
                               experiment_name="MIMIC",
                               output_directory=output_dir,
                               seed=42,
                               iteration_list=2**np.arange(13),
                               population_sizes=[100, 200, 300],
                               max_attempts=500,
                               keep_percent_list=[0.1, 0.2, 0.3],
                               use_fast_mimic=True)
    mimic_run_stats, mimic_run_curves = mimic.run()
コード例 #2
0
                          experiment_name=expName,
                          output_directory=OUTPUT_DIRECTORY,
                          seed=RANDOM_STATE,
                          iteration_list=iList,
                          population_sizes=[100, 200, 300, 400, 500],
                          mutation_rates=[0.3, 0.4, 0.5, 0.6, 0.7],
                          verbose=False)
        experiments.append(ga)
    # s,c = ga.run()
    # results.append([s,c])
    # MIMIC
    if not os.path.isfile(os.path.join(sys.path[0],'Output', expName, f'mimic__{expName}__curves_df.csv')):
        mc = mlr.MIMICRunner(problem=problem,
                            experiment_name=expName,
                            output_directory=OUTPUT_DIRECTORY,
                            seed=RANDOM_STATE,
                            iteration_list=iList,
                            population_sizes=[50, 125, 200, 275, 350],
                            keep_percent_list=[0.25, 0.5, 0.75],
                            verbose=False)
        experiments.append(mc)
    # s,c = mc.run()
    # results.append([s,c])

# experiments is 6 * 3 * 4 = 72 experiments long....
print(len(experiments))
print(np.array([[exp.dynamic_runner_name() + exp._experiment_name for exp in experiments]]).T)
if input('Continue... >') == 'y':
    pass
else:
    quit()
print('Running all experiments...')
コード例 #3
0
ファイル: queens.py プロジェクト: abagde93/CS7641
                                                   max_attempts=max_attempts,
                                                   max_iters=max_iters,
                                                   random_state=random_state,
                                                   pop_size=pop_size,
                                                   mutation_prob=mutation_prob,
                                                   curve=True)
print("Genetic Alg - Total Function Evaluations:", eval_count)
plot_fitness_iteration('fitness_iteration_ga_queens.png',gen_curve,
                       "Queens - Genetic Alg: mutation_prob: {}, pop_size: {}".format(mutation_prob, pop_size))


# MIMIC
mim = mlrh.MIMICRunner(problem=prob,
                       experiment_name=experiment_name,
                       output_directory=output_directory,
                       seed=random_state,
                       population_sizes=[50, 100, 200],
                       keep_percent_list=[0.1, 0.25, 0.5, 0.75],
                       iteration_list=[50],
                       use_fast_mimic=True)
mim_stats, mim_curve = mim.run()

columns = ['Time', 'Fitness', 'Population Size', 'Keep Percent']
df=pd.read_csv("./queen/queen_prob/mimic__queen_prob__run_stats_df.csv")
print(df[columns].sort_values(by=['Fitness'], ascending=False))

max_attempts = 10
max_iters = 25
keep_pct=0.25
pop_size = 200
eval_count = 0
best_state, best_fitness, mimic_curve = mlrh.mimic(prob,
コード例 #4
0
lengths_experiment = [2**x for x in range(10)]

for length in lengths_experiment:
    problem = mlrose.DiscreteOpt(length=length,
                                 fitness_fn=fitness,
                                 maximize=True,
                                 max_val=2)
    output_dir2 = os.path.join(
        this_dir, problem_name + '_MIMIC_length', str(length)
    )  #r"C:\Users\AREHAN2\Documents\omscs\CS7641\randomized_optimization\4peaks_GA_length\\" + str(length)
    mimic = mlrose.MIMICRunner(problem=problem,
                               experiment_name="MIMIC",
                               output_directory=output_dir2,
                               seed=42,
                               iteration_list=2**np.arange(13),
                               population_sizes=[300],
                               max_attempts=500,
                               keep_percent_list=[0.2],
                               use_fast_mimic=True)
    mimic_run_stats, mimic_run_curves = mimic.run()

#===================================================================================================
# STEP6: PLOT PERFORMANCE FROM STEP#4 AND STEP#5
#===================================================================================================
fig, ax = plt.subplots(1, 3, figsize=(17, 4))
param_search.plot_best_models(ga_best, sa_best, rhc_best, mimic_best, ax,
                              problem_name)
#plt.show()

max_iteartions_needed = []