Exemple #1
0
    def setUp(self):
        for i in range(len(test_cases)):
            results.append(
                bootstrap(test_cases[i]['sample'], test_cases[i]['predstot'],
                          test_cases[i]['predsdim']))

            resultsInt64.append(
                bootstrap(test_cases[i]['sample'], test_cases[i]['predstot'],
                          test_cases[i]['predsdim'], True))
Exemple #2
0
def main(args):
    trees = args.trees
    depth = args.depth
    train = args.train
    test = args.test
    test = test.replace('\r','') #Removes the carriage return cuz I use windows

    #Load the data in and convert to numpy
    with open(train,"r") as read_file:
        train = json.load(read_file)
        train = json2numpy(train)
    with open(test,"r") as read_file:
        test = json.load(read_file)
        test = json2numpy(test)

    bootstrap(trees, depth, train, test, display = True)
def main(args):
    method = args.method
    trees = args.trees
    depth = args.depth
    train = args.train
    test = args.test
    test = test.replace('\r','') #Removes the carriage return cuz I use windows

    #Load the data in and convert to numpy
    with open(train,"r") as read_file:
        train = json.load(read_file)
        train = json2numpy(train)
    with open(test,"r") as read_file:
        test = json.load(read_file)
        test = json2numpy(test)

    #Pull the true labels
    truth = test.labels
    #Generate the predictions from the ensemble
    if method == 'bag':
        predictions = bootstrap(trees, depth, train, test, display = False)
    elif method == 'boost':
        predictions = adaboost(trees, depth, train, test, display = False)
    else:
        print('Invalid ensemble method.')

    build_confusion_matrix(test, predictions, verbose = True)
Exemple #4
0
msusc = np.zeros(len(sizes))
mbeta = np.zeros(len(sizes))
merr = np.zeros(len(sizes))

start = time.time()
mag = np.zeros((len(sizes), risol))

for L in sizes:
    print "Lattice dimension:", L
    for j in range(len(beta)):
        conf = 2 * np.random.randint(2, size=(L, L, L)) - 1
        magn, cc = fx.clusteralg(conf, beta[j], beta[j], T)
        print(j)
        susc[j] = fx.suscet(magn[cut:], conf)
        stsusc[j] = fx.bootstrap(magn[cut:], 500, fx.suscet, conf)
        binder[j] = fx.bindercum(magn[cut:], conf)
        stbinder[j] = fx.bootstrap(magn[cut:], 500, fx.bindercum, conf)
        if (L == 40):
            plt.figure(j + 4)
            plt.title('beta=' + str(beta[j]))
            plt.hist(magn, normed="True")
            plt.savefig('histBeta=' + str(beta[j]) + '.pdf')
    mag[sizes.index(L), :] = np.mean(magn[cut:])
    msusc[sizes.index(L)] = susc.max()
    mbeta[sizes.index(L)] = beta[list(susc).index(susc.max())]
    merr[sizes.index(L)] = stsusc[list(susc).index(susc.max())]
    plt.figure(2)
    plt.grid(True)
    plt.title("Cumulante di binder")
    plt.xlabel("Beta")
Exemple #5
0
def main(args):
    method = args.method
    trees = args.trees
    depth = args.depth
    train = args.train
    test = args.test
    test = test.replace('\r','') #Removes the carriage return cuz I use windows
    data_origin = test.replace('_test.json','')
    data_origin = data_origin.replace('data/','')

    #Load the data in and convert to numpy
    with open(train,"r") as read_file:
        train = json.load(read_file)
        train = json2numpy(train)
    with open(test,"r") as read_file:
        test = json.load(read_file)
        test = json2numpy(test)


    #Pull the true labels
    truth = test.labels
    #Generate the predictions from the ensemble, create list of coordinates
    xlist = []
    ylist = []
    if method == 'bag':
        title = 'Decision Tree Bagging: Accuracy vs. Number of trees'
        filename = 'bagged_tree_plot.pdf'
        caption = ('Dataset: ' + data_origin)
        depth1 = depth - 2
        depth2 = depth 
        depth3 = depth + 2
        for j in [depth1,depth2,depth3]:
            for i in range(1,trees+1):
                predictions = bootstrap(i, j, train, test, display = False)
                accuracy = sum((truth == predictions).astype(float)) / test.length 
                xlist.append(i)
                ylist.append(accuracy)
            plt.plot(xlist,ylist)
            xlist = []
            ylist = []
    elif method == 'boost':
        title = 'Decision Tree AdaBoost: Accuracy vs. Number of trees'
        filename = 'boosted_tree_plot.pdf'
        caption = ('Dataset: ' + data_origin)
        depth1 = depth - 1
        depth2 = depth 
        depth3 = depth + 1
        for j in [depth1,depth2,depth3]:
            for i in range(1,trees+1):
                predictions = adaboost(i, j, train, test, display = False)
                accuracy = sum((truth == predictions).astype(float)) / test.length 
                xlist.append(i)
                ylist.append(accuracy)
            plt.plot(xlist,ylist)
            xlist = []
            ylist = []
    else:
        print('Invalid ensemble method.')
    
    #Plot the data
    plt.legend([depth1,depth2,depth3], loc = "lower right", title = "Maximum tree depth", fancybox = True)
    plt.xlabel('Ensemble size')
    plt.ylabel('Accuracy')
    plt.ylim([0.0, 1.05])
    plt.xlim([1, trees])
    plt.title(caption, fontsize = 9, wrap = True)
    plt.suptitle(title)
    plt.savefig(filename)