示例#1
0
 def test_simple(self):
     """
     line of numbers. Here the pca should return values that are double or close to double of the last value
     """
     m1 = np.array([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]])
     [res, model] = pca(Matrix(self.sds, m1), K=1,
               scale=False, center=False).compute()
     for x in range(len(m1) - 1):
         self.assertTrue(abs(res[x + 1] - res[0] * (x + 2)) < 0.001)
示例#2
0
 def test_500x2(self):
     """
     This test constructs a line of values in 2d space. 
     That if fit correctly maps perfectly to 1d space.
     The check is simply if the input value was positive
     then the output value should be similar.
     """
     m1 = self.generate_matrices_for_pca(30, seed=1304)
     X = Matrix(self.sds, m1)
     # print(features)
     [res, model] = pca(X, K=1, scale="FALSE", center="FALSE").compute()
     for (x, y) in zip(m1, res):
         self.assertTrue((x[0] > 0 and y > 0) or (x[0] < 0 and y < 0))
示例#3
0
 def test_invalid_input_2(self):
     features = Matrix(self.sds, np.array([1]))
     with self.assertRaises(ValueError) as context:
         pca(features, K=-1)