def ga_gp_rw_experiment(path_results): uniformify_vals = [0.1, 0.5, .75, 0.9, 1.0, 1.0/0.9, 1.0/.75, 2.0, 10.0] results = OrderedDict() ga_length = 10 gp_depth = 2 tp_path = os.path.join(path_results, "ga_length_10", "TP.dat") ga_tp = np.genfromtxt(tp_path) tp_path = os.path.join(path_results, "depth_2", "TP.dat") gp_tp = np.genfromtxt(tp_path) print "doing probability of encounter experiment" # Do the "probability of encounter" experiment first reps = 100 steps = 50 fit_path = os.path.join(path_results, "ga_length_10", "fitness_vals.dat") ga_fit = np.genfromtxt(fit_path) gp_fit = [float(s) for s in open(os.path.join(path_results, "depth_2", "all_fitness_values.dat")).readlines()] inds = 0, len(gp_fit)-1 hc_encounters = [0.0, 0.0] rw_encounters = [0.0, 0.0] for rep_name, tp, fitvals in [["gp", gp_tp, gp_fit]]: for rep in range(reps): samples, fit_samples, best = random_walks.hillclimb(gp_tp, fitvals, steps, rw=False) for i in range(2): if inds[i] in samples: hc_encounters[i] += 1.0 / reps samples, fit_samples, best = random_walks.hillclimb(gp_tp, fitvals, steps, rw=True) for i in range(2): if inds[i] in samples: rw_encounters[i] += 1.0 / reps print "hc_encounters", hc_encounters print "rw_encounters", rw_encounters # now the GA v GP hillclimb experiments reps = 30 for rep_name, tp, fitvals in [["ga", ga_tp, ga_fit], ["gp", gp_tp, gp_fit]]: for uniformify_val in uniformify_vals: for rep in range(reps): tp_tmp = random_walks.uniformify(tp, uniformify_val) samples, fit_samples, best = random_walks.hillclimb(tp_tmp, fitvals, steps, rw=True) x = float(len(set(samples))) / len(samples) results[rep_name, uniformify_val, rep] = x return results, ga_fit, gp_fit
def rw_experiment_with_tp(tp): N = len(tp) walklen = int(math.ceil(math.sqrt(N))) results = [] fitvals = np.zeros_like(tp[0]) # don't need them for this reps = 30 for rep in range(reps): samples, fit_samples, best = random_walks.hillclimb(tp, fitvals, walklen, rw=True) prop_unique = float(len(set(samples))) / len(samples) results.append(prop_unique) return np.mean(results), np.std(results)
def ga_hc_experiment(path_results): """Run some hill-climbs on variations of a GA space. Report performance.""" uniformify_vals = [ 0.1, 0.5, .75, 0.9, 1.0, 1.0 / 0.9, 1.0 / .75, 2.0, 10.0 ] noise_vals = [0, 1, 10, 100, 1000] results = OrderedDict() ga_length = 10 tp_path = os.path.join(path_results, "ga_length_10", "TP.dat") try: ga_tp = np.genfromtxt(tp_path) except: ga_tp, _ = random_walks.generate_ga_tm(ga_length, pmut=1.0 / ga_length) np.savetxt(tp_path, ga_tp) fit_path = os.path.join(path_results, "ga_length_10", "fitness_vals.dat") try: ga_fit = np.genfromtxt(fit_path) except: ga_fit = random_walks.onemax_fitvals(ga_length) np.savetxt(fit_path, ga_fit) # just get mu(sigma()), don't bother with sigma(sigma()) mu_sigma_vals = [ random_walks.mu_sigma(random_walks.uniformify(ga_tp, uniformify_val))[0] for uniformify_val in uniformify_vals ] reps = 30 steps = 50 for rep_name, tp, fitvals in [["ga", ga_tp, ga_fit]]: for noise_val in noise_vals: tmp_fit = random_walks.permute_vals(fitvals, noise_val) for uniformify_val in uniformify_vals: for rep in range(reps): tp_tmp = random_walks.uniformify(tp, uniformify_val) samples, fit_samples, best = random_walks.hillclimb( tp_tmp, tmp_fit, steps, rw=False) x = best results[rep_name, uniformify_val, noise_val, rep] = x return results, mu_sigma_vals
def ga_hc_experiment(path_results): """Run some hill-climbs on variations of a GA space. Report performance.""" uniformify_vals = [0.1, 0.5, .75, 0.9, 1.0, 1.0/0.9, 1.0/.75, 2.0, 10.0] noise_vals = [0, 1, 10, 100, 1000] results = OrderedDict() ga_length = 10 tp_path = os.path.join(path_results, "ga_length_10", "TP.dat") try: ga_tp = np.genfromtxt(tp_path) except: ga_tp, _ = random_walks.generate_ga_tm(ga_length, pmut=1.0/ga_length) np.savetxt(tp_path, ga_tp) fit_path = os.path.join(path_results, "ga_length_10", "fitness_vals.dat") try: ga_fit = np.genfromtxt(fit_path) except: ga_fit = random_walks.onemax_fitvals(ga_length) np.savetxt(fit_path, ga_fit) # just get mu(sigma()), don't bother with sigma(sigma()) mu_sigma_vals = [random_walks.mu_sigma(random_walks.uniformify(ga_tp, uniformify_val))[0] for uniformify_val in uniformify_vals] reps = 30 steps = 50 for rep_name, tp, fitvals in [["ga", ga_tp, ga_fit]]: for noise_val in noise_vals: tmp_fit = random_walks.permute_vals(fitvals, noise_val) for uniformify_val in uniformify_vals: for rep in range(reps): tp_tmp = random_walks.uniformify(tp, uniformify_val) samples, fit_samples, best = random_walks.hillclimb(tp_tmp, tmp_fit, steps, rw=False) x = best results[rep_name, uniformify_val, noise_val, rep] = x return results, mu_sigma_vals
def ga_gp_rw_experiment(path_results): uniformify_vals = [ 0.1, 0.5, .75, 0.9, 1.0, 1.0 / 0.9, 1.0 / .75, 2.0, 10.0 ] results = OrderedDict() ga_length = 10 gp_depth = 2 tp_path = os.path.join(path_results, "ga_length_10", "TP.dat") ga_tp = np.genfromtxt(tp_path) tp_path = os.path.join(path_results, "depth_2", "TP.dat") gp_tp = np.genfromtxt(tp_path) print "doing probability of encounter experiment" # Do the "probability of encounter" experiment first reps = 100 steps = 50 fit_path = os.path.join(path_results, "ga_length_10", "fitness_vals.dat") ga_fit = np.genfromtxt(fit_path) gp_fit = [ float(s) for s in open( os.path.join(path_results, "depth_2", "all_fitness_values.dat")).readlines() ] inds = 0, len(gp_fit) - 1 hc_encounters = [0.0, 0.0] rw_encounters = [0.0, 0.0] for rep_name, tp, fitvals in [["gp", gp_tp, gp_fit]]: for rep in range(reps): samples, fit_samples, best = random_walks.hillclimb(gp_tp, fitvals, steps, rw=False) for i in range(2): if inds[i] in samples: hc_encounters[i] += 1.0 / reps samples, fit_samples, best = random_walks.hillclimb(gp_tp, fitvals, steps, rw=True) for i in range(2): if inds[i] in samples: rw_encounters[i] += 1.0 / reps print "hc_encounters", hc_encounters print "rw_encounters", rw_encounters # now the GA v GP hillclimb experiments reps = 30 for rep_name, tp, fitvals in [["ga", ga_tp, ga_fit], ["gp", gp_tp, gp_fit]]: for uniformify_val in uniformify_vals: for rep in range(reps): tp_tmp = random_walks.uniformify(tp, uniformify_val) samples, fit_samples, best = random_walks.hillclimb(tp_tmp, fitvals, steps, rw=True) x = float(len(set(samples))) / len(samples) results[rep_name, uniformify_val, rep] = x return results, ga_fit, gp_fit