#lib="linearblock" #pc=0.008 #single resolution pc = cfg.svmc #high res #util.trainSvmRaw(ftrpos,ftrneg,svmname,dir="",pc=pc,lib=lib) #util.trainSvmRaw(ftrneg,ftrpos,svmname,dir="",pc=pc,lib=lib) #w,r=util.loadSvm(svmname,dir="",lib=lib) #w,r=util.trainSvmRawPeg(ftrpos,ftrneg,testname+".rpt.txt",dir="",pc=pc) import pegasos if w == None: w = numpy.zeros(cumsize[-1]) w, r, prloss = pegasos.trainComp( trpos, trneg, testname + "loss.rpt.txt", trposcl, trnegcl, oldw=w, dir="", pc=pc, k=10, numthr=numcore) #pylab.figure(300) #pylab.clf() #pylab.plot(w) pylab.figure(500) pylab.clf() oldprloss = numpy.concatenate((oldprloss, prloss), 0) pylab.plot(oldprloss) pylab.semilogy() pylab.legend(["loss+", "loss-", "reg", "obj", "hard+", "hard-"], loc='upper left')
print "SVM learning" svmname="%s.svm"%cfg.testname #lib="libsvm" lib="linear" #pc=0.008 #single resolution pc=cfg.svmc #high res #util.trainSvmRaw(trpos,trneg,svmname,dir="",pc=pc,lib=lib) #w,r=util.loadSvm(svmname,dir="",lib=lib) import time tt1=time.time() #w,r=pegasos.train(trpos,trneg,svmname,dir="",pc=pc) if w==None: w=numpy.zeros(len(trpos[0]),numpy.float32) r=0 w,r,prloss=pegasos.trainComp(trpos,trneg,svmname,oldw=numpy.concatenate((w,[-r/100])),pc=pc,k=10,numthr=numcore) #w,r,prloss=pegasos.trainComp(trpos,trneg,svmname,dir="",pc=pc) r=-w[-1]*100;w=w[:-1] #print "Results" #raw_input() #w,r=pegasos.trainkeep(trpos,trneg,svmname,dir="",pc=pc) pylab.figure(500) pylab.clf() oldprloss=numpy.concatenate((oldprloss,prloss),0) pylab.plot(oldprloss) pylab.semilogy() pylab.legend(["loss+","loss-","reg","obj","hard+","hard-"],loc='upper left') pylab.savefig("%s_loss%d.pdf"%(cfg.testname,it)) pylab.draw() pylab.show()
lib = "linear" #lib="linearblock" #pc=0.008 #single resolution pc = cfg.svmc #high res #util.trainSvmRaw(ftrpos,ftrneg,svmname,dir="",pc=pc,lib=lib) #util.trainSvmRaw(ftrneg,ftrpos,svmname,dir="",pc=pc,lib=lib) #w,r=util.loadSvm(svmname,dir="",lib=lib) #w,r=util.trainSvmRawPeg(ftrpos,ftrneg,testname+".rpt.txt",dir="",pc=pc) import pegasos if w == None: w = numpy.zeros(cumsize[-1]) w, r, prloss = pegasos.trainComp(trpos, trneg, testname + "loss.rpt.txt", trposcl, trnegcl, oldw=w, dir="", pc=pc, k=10, numthr=numcore) #pylab.figure(300) #pylab.clf() #pylab.plot(w) pylab.figure(500) pylab.clf() oldprloss = numpy.concatenate((oldprloss, prloss), 0) pylab.plot(oldprloss) pylab.semilogy() pylab.legend(["loss+", "loss-", "reg", "obj", "hard+", "hard-"], loc='upper left') pylab.savefig("%s_loss%d.pdf" % (cfg.testname, it))
#lib="libsvm" lib = "linear" #pc=0.008 #single resolution pc = cfg.svmc #high res #util.trainSvmRaw(trpos,trneg,svmname,dir="",pc=pc,lib=lib) #w,r=util.loadSvm(svmname,dir="",lib=lib) import time tt1 = time.time() #w,r=pegasos.train(trpos,trneg,svmname,dir="",pc=pc) if w == None: w = numpy.zeros(len(trpos[0]), numpy.float32) r = 0 w, r, prloss = pegasos.trainComp(trpos, trneg, svmname, oldw=numpy.concatenate( (w, [-r / 100])), pc=pc, k=10, numthr=numcore) #w,r,prloss=pegasos.trainComp(trpos,trneg,svmname,dir="",pc=pc) r = -w[-1] * 100 w = w[:-1] #print "Results" #raw_input() #w,r=pegasos.trainkeep(trpos,trneg,svmname,dir="",pc=pc) pylab.figure(500) pylab.clf() oldprloss = numpy.concatenate((oldprloss, prloss), 0) pylab.plot(oldprloss) pylab.semilogy() pylab.legend(["loss+", "loss-", "reg", "obj", "hard+", "hard-"],