Exemple #1
0
def training_round_script():
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    SNRval=0.5;

    #training_round_list=[];
    training_round_list=range(2,15);
    training_acc=[];
    testing_acc=[];
    rounds_tillnow=[];
    pos_tr_eg=glob_const.no_pos_training_eg;
    neg_tr_eg=glob_const.no_neg_training_eg;
    pos_te_eg=glob_const.no_pos_testing_eg;
    neg_te_eg=glob_const.no_neg_testing_eg;


    for training_round in training_round_list:
        boost=adaboost_train_test.AdaBoostTrainTest(SNRval,training_round,\
              pos_tr_eg,neg_tr_eg,pos_te_eg,neg_te_eg);
     
        boost.train_adaboost();
        boost.test_adaboost();
        training_acc.append(boost.training_accuracy);
        testing_acc.append(boost.testing_accuracy);
        rounds_tillnow.append(training_round);
        #this now saves the file at every iteration
        #if you want to quit the program before it finishes
        vid_utils.savefile(rounds_tillnow,training_acc,'data/adaboost_training_acc.txt')
        vid_utils.savefile(rounds_tillnow,testing_acc,'data/adaboost_testing_acc.txt')


    plt.plot(training_round_list,training_acc,'bo-',label='Training Accuracy');
    plt.plot(training_round_list,testing_acc,'ro-',label='Testing Accuracy');
    plt.legend();
    plt.show();
Exemple #2
0
def exampleno_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    SNRval = 0.5

    #exampleno_list=[];
    exampleno_list = range(50, 1000, 50)
    training_acc = []
    testing_acc = []
    list_tillnow = []
    time_list = []

    training_rounds = 15
    pos_te_eg = glob_const.no_pos_testing_eg
    neg_te_eg = glob_const.no_neg_testing_eg

    for exampleno in exampleno_list:
        starttime = time.time()

        glob_const.no_pos_training_eg = exampleno
        glob_const.no_neg_training_eg = exampleno
        glob_const.savefile()

        boost=adaboost_train_test.AdaBoostTrainTest(SNRval,training_rounds,\
              exampleno,exampleno,pos_te_eg,neg_te_eg)
        boost.train_adaboost()
        boost.test_adaboost()
        elapsed = time.time() - starttime

        #append values
        training_acc.append(boost.training_accuracy)
        testing_acc.append(boost.testing_accuracy)
        list_tillnow.append(exampleno)
        time_list.append(elapsed)
        vid_utils.savefile(list_tillnow,training_acc,\
                           'data/training_acc_eg.txt')
        vid_utils.savefile(list_tillnow,testing_acc,\
                'data/testing_acc_eg.txt')
        vid_utils.savefile(list_tillnow,time_list,\
                'data/time_vals.txt')

    plt.plot(exampleno_list, training_acc, 'bo-', label='Training Accuracy')
    plt.plot(exampleno_list, testing_acc, 'ro-', label='Testing Accuracy')
    plt.legend()
    plt.show()
def training_round_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    SNRval = 2.

    #exampleno_list=[];
    round_list = range(5, 30, 5)
    training_acc = []
    testing_acc = []
    list_tillnow = []
    time_list = []

    pos_te_eg = glob_const.no_pos_testing_eg
    neg_te_eg = glob_const.no_neg_testing_eg

    for training_rounds in round_list:
        starttime = time.time()

        pos_training_eg = glob_const.no_pos_training_eg
        neg_training_eg = glob_const.no_neg_training_eg
        glob_const.savefile()

        boost=adaboost_train_test.AdaBoostTrainTest(SNRval,training_rounds,\
              pos_training_eg,neg_training_eg,pos_te_eg,neg_te_eg)
        boost.train_adaboost()
        boost.test_adaboost()
        elapsed = time.time() - starttime

        #append values
        training_acc.append(boost.training_accuracy)
        testing_acc.append(boost.testing_accuracy)
        list_tillnow.append(training_rounds)
        time_list.append(elapsed)
        vid_utils.savefile(list_tillnow,training_acc,\
                           'data/training_acc_trainingrounds.txt')
        vid_utils.savefile(list_tillnow,testing_acc,\
                'data/testing_acc_trainingrounds.txt')
        vid_utils.savefile(list_tillnow,time_list,\
                'data/time_vals.txt')

    plt.plot(round_list, training_acc, 'bo-', label='Training Accuracy')
    plt.plot(round_list, testing_acc, 'ro-', label='Testing Accuracy')
    plt.legend(loc=2)
    plt.show()
Exemple #4
0
def compare_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    #SNRlist=[];
    SNRlist = [0.25 * x for x in range(8, 9)]
    tree_acc = []
    boost_acc = []

    training_rounds = 7
    pos_tr_eg = glob_const.no_pos_training_eg
    neg_tr_eg = glob_const.no_neg_training_eg
    pos_te_eg = glob_const.no_pos_testing_eg
    neg_te_eg = glob_const.no_neg_testing_eg
    list_till_now = []

    for SNRval in SNRlist:
        boost=adaboost_train_test.AdaBoostTrainTest(SNRval,training_rounds,\
              pos_tr_eg,neg_tr_eg,pos_te_eg,neg_te_eg)
        traintest = train_and_test.TrainAndTest(SNRval)

        #Train
        boost.train_adaboost()
        traintest.train_tree()

        #Test
        boost.test_adaboost()
        traintest.test_tree()
        #traintest.post_prune_tree();
        #traintest.test_tree();

        #get accuracies
        boost_acc.append(boost.testing_accuracy)
        tree_acc.append(traintest.testing_accuracy)
        list_till_now.append(SNRval)
        vid_utils.savefile(list_till_now, tree_acc, "data/Tree_accuracies.txt")
        vid_utils.savefile(list_till_now, boost_acc,
                           "data/Boost_accuracies.txt")
        print "Processed SNR: " + str(SNRval) + "..."

    plt.plot(SNRlist, tree_acc, 'ro', label="Tree")
    plt.plot(SNRlist, boost_acc, 'bo', label="Adaboost")
    plt.xlim(0, 2.5)
    plt.legend(loc=2)
    plt.show()