Ejemplo n.º 1
0
 def train(self,A_pos_set, A_neg_set, online=False):
     assert(online==False)
     filename="%s-training"%(self.filename,)
     labelfilename="%s-traininglabels"%(self.filename,)        
     svmformat.output_matrix_svmformat(numpy.vstack([A_pos_set,A_neg_set]) ,filename)
     f=open(labelfilename,"w")
     f.write("\n".join(["1",] * len(A_pos_set) + ["-1",] * len(A_neg_set)))
     f.close()
     os.system("svmlin %s %s "%(filename,labelfilename))
Ejemplo n.º 2
0
 def test(self,data,log=True): ## return likelihood of samples
     filename="%s-training.weights"%(self.filename,)
     filename2="%s-testing"%(self.filename,)
     svmformat.output_matrix_svmformat(data,filename2)
     print "running test"
     os.system("svmlin -f %s %s"%(filename, filename2) )
     A=numpy.array(map(lambda x:float(x),open("%s.testing.outputs"%(self.filename,)).readlines()))
     if log:
       return numpy.log(A)
     else:
       return A