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 depth_script(): #important: line 199 in function train_node.py #which is self._print_histogram in create_children() #function is uncommented for this script to run #comment it back and reinstall after the script runs #this also depends on information from self._print_loginfo #in tree_node.py glob_const=globalconstants.GlobalConstants(); init_set(glob_const); SNRval=0.5; traintest=train_and_test.TrainAndTest(SNRval); traintest.train_tree();
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()
def training_round_script(): glob_const = globalconstants.GlobalConstants() init_set(glob_const) examples = glob_const.no_pos_training_eg init_t = time.time() SNRval = 0.5 traintest = train_and_test.TrainAndTest(SNRval) traintest.train_tree() print "Trained: " + str(time.time() - init_t) init_t = time.time() traintest.test_tree() print "Tested: " + str(time.time() - init_t) init_t = time.time() traintest.post_prune_tree() print "Post Pruned: " + str(time.time() - init_t) return
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)
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()
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()
import pbtspot from pbtspot import set_default,train_and_test, globalconstants import matplotlib.pyplot as plt set_default.set_default_constants(); #set constants glob_const=globalconstants.GlobalConstants(); glob_const.no_pos_training_eg=50; glob_const.no_neg_training_eg=50; glob_const.no_pos_testing_eg=1000; glob_const.no_neg_testing_eg=1000; glob_const.savefile(); #main script SNR=0.5; train_test=train_and_test.TrainAndTest(SNR); train_test.load_saved_tree(); #train_test.train_tree(); #train_test.save_tree(); train_test.test_tree(); [tpr,fpr]=train_test.get_roc_curve(); plt.plot(fpr,tpr,'ro-'); plt.xlim(-0.05, 1.05) plt.ylim(-0.05,1.05) plt.xlabel("False Positive Rate") plt.ylabel("True Positive Rate") print "tpr: "+str(tpr) print "fpr: "+str(fpr) plt.show();