Ejemplo n.º 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();
Ejemplo n.º 2
0
def training_round_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    SNRval = 2.

    #overfitting_e_list=[];
    overfitting_e_list = [0.1 * x for x in range(0, 5)]
    training_acc = []
    testing_acc = []
    list_till_now = []

    for overfitting_e in overfitting_e_list:
        glob_const.overfitting_e = overfitting_e
        glob_const.savefile()
        traintest = train_and_test.TrainAndTest(SNRval)
        traintest.train_tree()
        traintest.test_tree()
        list_till_now.append(overfitting_e)
        training_acc.append(traintest.training_accuracy)
        testing_acc.append(traintest.testing_accuracy)
        vid_utils.savefile(list_till_now, training_acc,
                           'data/overfittng_e_training_acc.txt')
        vid_utils.savefile(list_till_now, testing_acc,
                           'data/overfitting_e_testing_acc.txt')
        print "Processed e: " + str(overfitting_e) + "...."

    plt.plot(overfitting_e_list,
             training_acc,
             'bo-',
             label='Training Accuracy')
    plt.plot(overfitting_e_list, testing_acc, 'ro-', label='Testing Accuracy')
    plt.legend()
    plt.show()

    pass
def training_round_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    SNRval = 0.5

    #training_round_list=[];
    training_round_list = range(2, 11)
    training_acc = []
    testing_acc = []

    for training_round in training_round_list:
        glob_const.training_rounds = training_round
        glob_const.savefile()
        traintest = train_and_test.TrainAndTest(SNRval)
        traintest.train_tree()
        traintest.test_tree()
        training_acc.append(traintest.training_accuracy)
        testing_acc.append(traintest.testing_accuracy)

    vid_utils.savefile(training_round_list, training_acc,
                       'data/training_acc.txt')
    vid_utils.savefile(training_round_list, testing_acc,
                       'data/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()

    pass
Ejemplo n.º 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();
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
def roc_script(SNRval,particle_shape,image_type):
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    
    glob_const.image_type=image_type;
    glob_const.particle_shape=particle_shape;
    glob_const.savefile();
    
 
    
    traintest=train_and_test.TrainAndTest(SNRval);
    traintest.train_tree();
    traintest.test_tree();
    [precision,recall]=traintest.get_precision_recall_curve();
    precision_filename="data/precision_"+str(SNRval)+"_"+str(image_type)+\
                        "_"+str(particle_shape)+".txt";
    vid_utils.savefile(precision,recall,precision_filename)
    [tpr,fpr]=traintest.get_roc_curve();
    roc_filename="data/roc_"+str(SNRval)+"_"+str(image_type)+\
                        "_"+str(particle_shape)+".txt";
    
    vid_utils.savefile(tpr,fpr,roc_filename)
Ejemplo n.º 7
0
def training_round_script():
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    SNRval=2.;

    #overfitting_e_list=[];
    overfitting_e_list=[0.1*x for x in range(0,5)];
    training_acc=[];
    testing_acc=[];
    list_till_now=[]
    
    for overfitting_e in overfitting_e_list:
        glob_const.overfitting_e=overfitting_e;
        glob_const.savefile();
        traintest=train_and_test.TrainAndTest(SNRval);
        traintest.train_tree();
        traintest.test_tree();
        list_till_now.append(overfitting_e)
        training_acc.append(traintest.training_accuracy);
        testing_acc.append(traintest.testing_accuracy);
        vid_utils.savefile(list_till_now,training_acc,'data/overfittng_e_training_acc.txt')
        vid_utils.savefile(list_till_now,testing_acc,'data/overfitting_e_testing_acc.txt')
        print "Processed e: "+str(overfitting_e)+"...."
        
    plt.plot(overfitting_e_list,training_acc,'bo-',label='Training Accuracy');
    plt.plot(overfitting_e_list,testing_acc,'ro-',label='Testing Accuracy');
    plt.legend();
    plt.show();






    
    
    
    
    pass
def training_round_script():
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    SNRval=0.5;

    #training_round_list=[];
    training_round_list=range(2,11);
    training_acc=[];
    testing_acc=[];
    
    for training_round in training_round_list:
        glob_const.training_rounds=training_round;
        glob_const.savefile();
        traintest=train_and_test.TrainAndTest(SNRval);
        traintest.train_tree();
        traintest.test_tree();
        training_acc.append(traintest.training_accuracy);
        testing_acc.append(traintest.testing_accuracy);

    vid_utils.savefile(training_round_list,training_acc,'data/training_acc.txt')
    vid_utils.savefile(training_round_list,testing_acc,'data/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();






    
    
    
    
    pass
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
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();
Ejemplo n.º 11
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();
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
def depth_script():
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    SNRval=2.;

    #maxdepth_list=[];
    maxdepth_list=range(2,7);
    training_acc=[];
    testing_acc=[];
    list_tillnow=[];
    time_list=[];
    for depth in maxdepth_list:
        starttime=time.time();
        
        glob_const.maxdepth_tree=depth;
        glob_const.savefile();
        traintest=train_and_test.TrainAndTest(SNRval);
        traintest.train_tree();
        traintest.test_tree();
        traintest.post_prune_tree();
        traintest.test_tree();
        elapsed=time.time()-starttime;
        
        #append values
        training_acc.append(traintest.training_accuracy);
        testing_acc.append(traintest.testing_accuracy);
        list_tillnow.append(depth);
        time_list.append(elapsed)
        vid_utils.savefile(list_tillnow,training_acc,\
                           'data/training_acc_depth.txt')
        vid_utils.savefile(list_tillnow,testing_acc,\
                'data/testing_acc_depth.txt')
        vid_utils.savefile(list_tillnow,time_list,\
                'data/time_vals_depth.txt')

    plt.plot(maxdepth_list,training_acc,'bo-',label='Training');
    plt.plot(maxdepth_list,testing_acc,'ro-',label='Testing');
    plt.legend(loc=2);
    plt.show();
Ejemplo n.º 14
0
def exampleno_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    SNRval = 0.5

    #exampleno_list=[];
    exampleno_list = range(50, 250, 50)
    training_acc = []
    testing_acc = []
    list_tillnow = []
    time_list = []
    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()
        traintest = train_and_test.TrainAndTest(SNRval)
        traintest.train_tree()
        traintest.test_tree()
        elapsed = time.time() - starttime

        #append values
        training_acc.append(traintest.training_accuracy)
        testing_acc.append(traintest.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()
Ejemplo n.º 15
0
def gamma_script():
    glob_const = globalconstants.GlobalConstants()
    init_set(glob_const)
    SNRval = 2.

    #maxdepth_list=[];
    #gamma_list=range(1,7);
    gamma_list = [0]
    training_acc = []
    testing_acc = []
    list_tillnow = []
    time_list = []
    for gamma in gamma_list:
        starttime = time.time()

        glob_const.gamma = gamma
        glob_const.savefile()
        traintest = train_and_test.TrainAndTest(SNRval)
        traintest.train_tree()
        traintest.test_tree()
        elapsed = time.time() - starttime

        #append values
        training_acc.append(traintest.training_accuracy)
        testing_acc.append(traintest.testing_accuracy)
        list_tillnow.append(gamma)
        time_list.append(elapsed)
        vid_utils.savefile(list_tillnow,training_acc,\
                           'data/training_acc_gamma.txt')
        vid_utils.savefile(list_tillnow,testing_acc,\
                'data/testing_acc_gamma.txt')
        vid_utils.savefile(list_tillnow,time_list,\
                'data/time_vals_depth.txt')

    plt.plot(gamma_list, training_acc, 'bo-', label='Training Accuracy')
    plt.plot(gamma_list, testing_acc, 'ro-', label='Testing Accuracy')
    plt.legend()
    plt.show()
Ejemplo n.º 16
0
def exampleno_script():
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    SNRval=0.5;

    #exampleno_list=[];
    exampleno_list=range(50,250,50);
    training_acc=[];
    testing_acc=[];
    list_tillnow=[];
    time_list=[];
    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();
        traintest=train_and_test.TrainAndTest(SNRval);
        traintest.train_tree();
        traintest.test_tree();
        elapsed=time.time()-starttime;
        
        #append values
        training_acc.append(traintest.training_accuracy);
        testing_acc.append(traintest.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();
Ejemplo n.º 17
0
def gamma_script():
    glob_const=globalconstants.GlobalConstants();
    init_set(glob_const);
    SNRval=2.;

    #maxdepth_list=[];
    #gamma_list=range(1,7);
    gamma_list=[0];
    training_acc=[];
    testing_acc=[];
    list_tillnow=[];
    time_list=[];
    for gamma in gamma_list:
        starttime=time.time();
        
        glob_const.gamma=gamma;
        glob_const.savefile();
        traintest=train_and_test.TrainAndTest(SNRval);
        traintest.train_tree();
        traintest.test_tree();
        elapsed=time.time()-starttime;
        
        #append values
        training_acc.append(traintest.training_accuracy);
        testing_acc.append(traintest.testing_accuracy);
        list_tillnow.append(gamma);
        time_list.append(elapsed)
        vid_utils.savefile(list_tillnow,training_acc,\
                           'data/training_acc_gamma.txt')
        vid_utils.savefile(list_tillnow,testing_acc,\
                'data/testing_acc_gamma.txt')
        vid_utils.savefile(list_tillnow,time_list,\
                'data/time_vals_depth.txt')

    plt.plot(gamma_list,training_acc,'bo-',label='Training Accuracy');
    plt.plot(gamma_list,testing_acc,'ro-',label='Testing Accuracy');
    plt.legend();
    plt.show();