コード例 #1
0
def operator_difference_and_compound_experiment():
    """Take the 6 permutation operators in pairs, and for each calculate
    the GINI/stddev/etc of the compound operator, and also the
    difference between the pair.

    """
    
    opss = ("two_opt", "twoh_opt", "three_opt", "three_opt_broad", "swap_two", "swap_adj")
    for n in range(6, 11):
        diff = np.zeros((len(opss), len(opss)))
        Gini = np.zeros((len(opss), len(opss)))
        SD = np.zeros((len(opss), len(opss)))
        CV = np.zeros((len(opss), len(opss)))
        for i, opi in enumerate(opss):
            for j, opj in enumerate(opss):
                basedir = sys.argv[1] + "/tsp_length_%d_" % n
                ops = [opi, opj]
                ps = [np.genfromtxt(basedir + op + "/TP_row0.dat") for op in ops]
                names = "+".join(ops)
                delta = random_walks.operator_difference_RMSE(*ps)
                print "delta", names, delta
                diff[i][j] = delta

                wts = [1.0 / len(ops) for _ in ops]
                compound_tp = random_walks.compound_operator(wts, ps)
                gini = random_walks.gini_coeff(compound_tp)
                sd = np.std(compound_tp)
                cv = np.std(compound_tp) / np.mean(compound_tp)
                print "compound gini", names, gini
                Gini[i][j] = gini
                print "compound stddev", names, sd
                SD[i][j] = sd
                print "compound coefvar", names, cv
                CV[i][j] = cv
                
        basedir = sys.argv[1] + "/permutation_size_%d_compound_diff/" % n
        
        filename = os.path.join(basedir + "diff")
        np.savetxt(filename+".dat", diff)
        plot_grid(filename, ("Operator difference %d" % n), opss, diff)
        
        filename = os.path.join(basedir + "diff_mds")
        op_diff_mds(filename, ("Operator difference %d" % n), opss, diff)

        filename = os.path.join(basedir + "compound_gini")
        np.savetxt(filename+".dat", Gini)
        plot_grid(filename, ("Compound operator Gini %d" % n), opss, Gini)

        filename = os.path.join(basedir + "compound_sd")
        np.savetxt(filename+".dat", SD)
        plot_grid(filename, ("Compound operator SD %d" % n), opss, SD)

        filename = os.path.join(basedir + "compound_cv")
        np.savetxt(filename+".dat", CV)
        plot_grid(filename, ("Compound operator CV %d" % n), opss, CV)
コード例 #2
0
def operator_difference_and_compound_experiment():
    """Take the 6 operators in pairs, and for each calculate the
    GINI/stddev of the compound operator, and also the difference
    between the pair.

    """
    
    opss = ("two_opt", "twoh_opt", "three_opt", "three_opt_broad", "swap", "swap_adj")
    for n in range(6, 11):
        diff_result = np.zeros((len(opss), len(opss)))
        comp_result = np.zeros((len(opss), len(opss)))
        comp_result_stddev = np.zeros((len(opss), len(opss)))
        for i, opi in enumerate(opss):
            for j, opj in enumerate(opss):
                basedir = "/Users/jmmcd/Dropbox/GPDistance/results/tsp_length_%d_" % n
                ops = [opi, opj]
                ps = [np.genfromtxt(basedir + op + "/TP_row0.dat") for op in ops]
                names = "+".join(ops)
                delta = random_walks.operator_difference_RMSE(*ps)
                print "delta", names, delta
                diff_result[i][j] = delta

                wts = [1.0 / len(ops) for _ in ops]
                compound_tp = random_walks.compound_operator(wts, ps)
                gini = random_walks.gini_coeff(compound_tp)
                stddev = np.std(compound_tp)
                print "compound gini", names, gini
                comp_result[i][j] = gini
                print "compound stddev", names, stddev
                comp_result_stddev[i][j] = stddev
                
        op_diff_filename = "/Users/jmmcd/Dropbox/GPDistance/results/EURO2015/tsp_length_%d_op_diff" % n
        np.savetxt(op_diff_filename+".dat", diff_result)
        plot_grid(op_diff_filename, ("Operator difference %d" % n), opss, diff_result)
        
        comp_op_filename = "/Users/jmmcd/Dropbox/GPDistance/results/EURO2015/tsp_length_%d_comp_op" % n
        np.savetxt(comp_op_filename+".dat", comp_result)
        plot_grid(comp_op_filename, ("Compound operator Gini %d" % n), opss, comp_result)

        comp_op_stddev_filename = "/Users/jmmcd/Dropbox/GPDistance/results/EURO2015/tsp_length_%d_comp_op_stddev" % n
        np.savetxt(comp_op_stddev_filename+".dat", comp_result_stddev)
        plot_grid(comp_op_stddev_filename, ("Compound operator stddev %d" % n), opss, comp_result_stddev)

        mds_filename = "/Users/jmmcd/Dropbox/GPDistance/results/EURO2015/tsp_length_%d_mds" % n
        op_diff_mds(mds_filename, ("Operator difference %d" % n), opss, diff_result)