Ejemplo n.º 1
0
def basic_stats_and_plots_tree():
    basename = sys.argv[1]
    filename = os.path.join(basename, "depth_2/TP.dat")
    tp = np.genfromtxt(filename)
    N = len(tp)

    sd = random_walks.mu_sigma(tp)[0]
    logN_sd = sd * np.log(len(tp))
    sqrtN_sd = sd * (N**0.5)
    cbrtN_sd = sd * (N**(1.0/3))
    g = random_walks.mean_gini_coeff(tp)
    cv = random_walks.mu_sigma_cv(tp)[0]
    mu, sigma = rw_experiment_with_tp(tp)
    
    prop_unique_v_expl = []
    space = "tree"
    op = "subtree"
    size = 2
    
    prop_unique_v_expl.append("%s %d %s %f %f %f %f %f %f %f %f" % (
        space, size, op, sd, cv, logN_sd, sqrtN_sd, cbrtN_sd, g, mu, sigma))
    filename = os.path.join(basename, "space_%s/size_%d_prop_unique_v_expl.dat" % (space, size))
    open(filename, "w").write("\n".join(prop_unique_v_expl))
    
    barchart(basename, space, size, "cbrt(N) SD", [cbrtN_sd], [op])
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
Ejemplo n.º 3
0
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