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()
pN = [5, 10, 15, 30, 55, 100] for i in pN: problems_list.append((peaksGen.generate(RANDOM_STATE, i, t_pct), f'peaks_{i}')) print('Building experiments...') ## Algorithms experiments = [] for prob in problems_list: # Test if file already exists, if so skip problem, expName = prob iList = 2**np.arange(10) # Random Hill Climbing if not os.path.isfile(os.path.join(sys.path[0],'Output', expName, f'rhc__{expName}__curves_df.csv')): rhc = mlr.RHCRunner(problem=problem, experiment_name=expName, output_directory=OUTPUT_DIRECTORY, seed=RANDOM_STATE, iteration_list=iList, restart_list=[5,10,20,30], verbose=False) experiments.append(rhc) # s,c = rhc.run() # results.append([s,c]) # Simulated Annealing if not os.path.isfile(os.path.join(sys.path[0],'Output', expName, f'sa__{expName}__curves_df.csv')): sa = mlr.SARunner(problem=problem, experiment_name=expName, output_directory=OUTPUT_DIRECTORY, seed=RANDOM_STATE, iteration_list=iList, temperature_list=[1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000], decay_list=[mlr.ArithDecay, mlr.ExpDecay, mlr.GeomDecay],
max_attempts=max_attempts, max_iters=max_iters, random_state=random_state, pop_size=pop_size, keep_pct=keep_pct, curve=True) print("MIMIC - Total Function Evaluations:", eval_count) plot_fitness_iteration('fitness_iteration_mimic_queens.png',mimic_curve, "Queens - Mimic: Population Size: {}, Keep Percent: {}".format(pop_size, keep_pct)) # RHC rhc = mlrh.RHCRunner(problem=prob, experiment_name=experiment_name, output_directory=output_directory, seed=random_state, max_attempts=200, iteration_list=[2500], restart_list=[20]) rhc_stats, rhc_curve = rhc.run() columns = ['Time', 'Fitness', 'Restarts', 'current_restart'] df=pd.read_csv("./queen/queen_prob/rhc__queen_prob__run_stats_df.csv") print(df[columns].sort_values(by=['Fitness'], ascending=False)) max_attempts = 500 max_iters = 2500 restarts = 20 eval_count = 0 best_state, best_fitness, rhc_curve = mlrh.random_hill_climb(prob, max_attempts=max_attempts,