예제 #1
0
 def testSimpleTrain1(self):
     "Two 1-dimensional input points (SIGN), 1 kernel (linear)"
     kerns = np.int32([0]); # 1 linear kernel
     params = np.double([0.]); # params not important
     features = np.int32([-1]); # use all features, but there's only 1
     Xtr = np.double([[-2.,2.]]); # support points
     ytr = np.int32([-1,1]); # labels
     (success, Sigma, alpha, bsvm, posw) = train_mwu_mkl(kerns, params, features, Xtr, ytr)
     self.assertTrue(success)
     self.assertTrue((posw == 1).all(), msg='posw={0}'.format(posw))
     self.assertTrue((Sigma > 0).all(), msg='Sigma={0}'.format(Sigma))
     self.assertTrue((alpha >= 0).all(), msg='alpha={0}'.format(alpha))
     self.assertAlmostEqual(bsvm, 0.0, msg='bsvm={0}'.format(bsvm))
예제 #2
0
 def testSimpleTrain2(self):
     "Four 2-dimensional input points (XOR), 1 kernel (quad)"
     kerns = np.int32([1]); # 1 polynomial kernel
     params = np.double([2.]); # quadratic
     features = np.int32([-1]); # use all features, but there's only 1
     Xtr = np.double([[-2.,2.,-2.,2.],
                      [-2.,-2.,2.,2.]]); # support points
     ytr = np.int32([-1,1,1,-1]); # labels
     (success, Sigma, alpha, bsvm, posw) = train_mwu_mkl(kerns, params, features, Xtr, ytr)
     self.assertTrue(success)
     self.assertTrue((posw == 1).all(), msg='posw={0}'.format(posw))
     self.assertTrue((Sigma > 0).all(), msg='Sigma={0}'.format(Sigma))
     self.assertTrue((alpha >= 0).all(), msg='alpha={0}'.format(alpha))
     self.assertAlmostEqual(bsvm, 0.0, msg='bsvm={0}'.format(bsvm))