def testSimpleMargin1(self): "Test against two 1-dimensional support points (SIGN), 1 kernel (linear)" Sigma = np.double([1.]); # 1 kernel, weight 1.0 alpha = np.double([1.,1.])/2; # 2 support points of equal weight 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 Xte = Xtr/2; # test points ytr = np.int32([-1,1]); # labels results = test_mkl(Sigma, alpha, kerns, params, features, Xtr, Xte, ytr) self.assertTrue((np.sign(results) == ytr).all(), msg='results={0}, ytr={1}'.format(results, ytr))
def testSimpleMargin2(self): "Test against four 2-dimensional support points (XOR), 1 kernel (quad)" Sigma = np.double([1.]); # 1 kernel, weight 1.0 alpha = np.double([1.,1.,1.,1.])/4; # 4 support points of equal weight kerns = np.int32([1]); # 1 polynomial kernel params = np.double([2.]); # quadratic features = np.int32([-1]); # use all features Xtr = np.double([[-2.,2.,-2.,2.], [-2.,-2.,2.,2.]]); # support points Xte = Xtr/2; # test points ytr = np.int32([-1,1,1,-1]); # labels results = test_mkl(Sigma, alpha, kerns, params, features, Xtr, Xte, ytr) self.assertTrue((np.sign(results) == ytr).all(), msg='results={0}, ytr={1}'.format(results, ytr))