import scipy.io as sio from CurrentThingsNeededtoRun import NA_Classifier from CurrentThingsNeededtoRun.Transfer_Mat_From_Matlab import txmat <<<<<<< HEAD xtrain_BCDEFGHI = txmat('xtrain_BCDEFGHI_pow.mat','xtrain') ytrain_BCDEFGHI = txmat('ytrain_BCDEFGHI_pow.mat','ytrain') xtltrain_BCDEFGHI = txmat('xtltrain_BCDEFGHI_pow.mat','xtltrain') xtest_BCDEFGHI = txmat('xtest_BCDEFGHI_pow.mat','xtest') ytest_BCDEFGHI = txmat('ytest_BCDEFGHI_pow.mat','ytest') xtltest_BCDEFGHI = txmat('xtltest_BCDEFGHI_pow.mat','xtltest') xtrain_A = txmat('xtrain_A_pow.mat','xtrain') # we're gonna use this for testing' ytrain_A = txmat('ytrain_A_pow.mat','ytrain') xtltrain_A = txmat('xtltrain_A_pow.mat','xtltrain') ======= xtrain_pow = sio.loadmat('xtrain_all_pow.mat') xtrain_pow = xtrain_pow['xtrain'] >>>>>>> bd36724a187f99ba8e1e28e7167a1c6f578d48e7 print 'NA classifier pow training BCDEFGHI and A' nu = [0.05, 0.1,.2,.3,.4, 0.5, 0.8] for param in nu: ystring,ystring1 = NA_Classifier.myclassify_NA(2, xtrain_BCDEFGHI, xtest_BCDEFGHI, xtltest_BCDEFGHI, xtrain_A, xtltrain_A, nuparam=param) print 'for nu =' + str(param) print 'results on BCDEFGHI testing set'
def lookatme(): xtesting = txmat('xtesting.mat','xtesting') xtrunclength = txmat('xtrunclength.mat','xtrunclength') xtrainallpow = txmat('xtrain_all_pow.mat','xtrain') xtltrainallpow = txmat('xtltrain_all_pow.mat','xtltrain') ytrainallpow = txmat('ytrain_all_pow.mat','ytrain') # print "power results" y,x,power9Class = FinalClassifier.myclassify_practice_set(1, xtrainallpow, ytrainallpow, xtltrainallpow, xtrunclength, xtesting) # print y # print power9Class # print "" # print FinalClassifier.predVec2Str(power9Class) # print "" xtrainallaud = txmat('xtrain_all_aud.mat','xtrain') xtltrainallaud = txmat('xtltrain_all_aud.mat','xtltrain') ytrainallaud = txmat('ytrain_all_aud.mat','ytrain') # print 'audio results' # print "" y,x,audio9Class = FinalClassifier.myclassify_practice_set(1, xtrain = xtrainallaud, ytrain = ytrainallaud, xtltrain = xtltrainallaud, xtltest = xtrunclength, xtest = xtesting) # print y # print FinalClassifier.predVec2Str(audio9Class) # print "" ybintestallaud = txmat('ybintrain_all_aud.mat','ybintrain') ybintestallpow = txmat('ybintrain_all_pow.mat','ybintrain') y,audVpow = AudiovsPower.myclassify_AudPow(1, xtrainallaud, xtrainallpow, ybintestallaud, ybintestallpow, xtesting) # print 'results from binary audio power classifier ' # print "" # print y # print "" # print audVpow grids = ['A','B','C','D','E','F','G','H','I'] pow1ClassMat = np.empty([len(grids),len(audVpow)]) #POWER ONE-CLASS xtrain = [] xtltrain = [] for grid in grids: xtrain.append(txmat('xtrain_' + grid + '_pow.mat','xtrain')) xtltrain.append(txmat('xtltrain_' + grid + '_pow.mat','xtltrain')) for i in range(len(xtrain)): ystring,yvec = NA_Classifier.myclassify_oneclass(1, xtrain[i], xtesting, xtrunclength, nuparam = .05) pow1ClassMat[i,:] = yvec # print 'results on training set for training on ' + grids[i] + ' power ' # print ystring # print pow1ClassMat #AUDIO ONE-CLASS # grids = ['A_18class1','B_18class1','C_18class1','D_18class1','E_18class1','F_18class1','G_18class1','H_18class1','I_18class1', # 'A_18class2','B_18class2','C_18class2','D_18class2','E_18class2','F_18class2','G_18class2','H_18class2','I_18class2'] aud1ClassMat = np.empty([len(grids),len(audVpow)]) xtrain = [] xtltrain = [] for grid in grids: xtrain.append(txmat('xtrain_' + grid + '_aud.mat','xtrain')) xtltrain.append(txmat('xtltrain_' + grid + '_aud.mat','xtltrain')) for i in range(len(xtrain)): ystring,yvec = NA_Classifier.myclassify_oneclass(1, xtrain[i], xtesting, xtrunclength, nuparam = .1) aud1ClassMat[i,:] = yvec # print 'results on training set for training on ' + grids[i] + ' audio ' # print ystring # print aud1ClassMat.shape # we should run it for audio through 18 one class classifiers, one off each recording xtrain_BD_aud = txmat('xtrain_BD_aud.mat','xtrain') ytrain_BD_aud = txmat('ytrain_BD_aud.mat','ytrain') xtltrain_BD_aud = txmat('xtltrain_BD_aud.mat','xtltrain') y,x,BDsvm = FinalClassifier.myclassify_practice_set(1,xtrain_BD_aud,ytrain_BD_aud,xtltrain_BD_aud,xtrunclength,xtesting,grids='BD') print BDsvm xtrain_BE_aud = txmat('xtrain_BE_aud.mat','xtrain') ytrain_BE_aud = txmat('ytrain_BE_aud.mat','ytrain') xtltrain_BE_aud = txmat('xtltrain_BE_aud.mat','xtltrain') y,x,BEsvm = FinalClassifier.myclassify_practice_set(1,xtrain_BE_aud,ytrain_BE_aud,xtltrain_BE_aud,xtrunclength,xtesting,grids='BE') print BEsvm #math time finalclass = [] # print temp1classVec.shape for i in range(len(audVpow)): elem = audVpow[i] if elem: #power temp1classVec = pow1ClassMat[:,i] if np.any(temp1classVec == 1): finalclass.append(power9Class[i]) else: finalclass.append(10) #N/A else: #audio temp1classVec = aud1ClassMat[:,i] if np.any(temp1classVec == 1): if audio9Class[i] == 2: #if we guess class B, use the BD Classifier to make sure it isn't D if BDsvm[i] == 2: # BDsvm ==1 is B, 2 is D finalclass.append(4) # if we guessed class D but the BD svm says it's B, append B else: finalclass.append(audio9Class[i]) elif audio9Class[i] == 5: #if we guess E, make sure it isn't B if BEsvm[i] ==1: finalclass.append(2) else: finalclass.append(audio9Class[i]) else: finalclass.append(audio9Class[i]) # finalclass.append(audio9Class[i]) else: finalclass.append(10) #N/A # print finalclass print FinalClassifier.predVec2Str(finalclass)