Пример #1
0
 def testComponentSeparation(self):
     A = generate_covsig([[10,5,2],[5,10,2],[2,2,10]], 500)
     B = generate_covsig([[10,2,2],[2,10,5],[2,5,10]], 500)
         
     X = np.dstack([A,B])
     W, V = csp(X,[1,2])        
     C1a = np.cov(X[:,:,0].dot(W).T)
     C2a = np.cov(X[:,:,1].dot(W).T)
     
     Y = np.dstack([B,A])
     W, V = csp(Y,[1,2])
     C1b = np.cov(Y[:,:,0].dot(W).T)
     C2b = np.cov(Y[:,:,1].dot(W).T)
     
     # check symmetric case
     self.assertTrue(np.allclose(C1a.diagonal(), C2a.diagonal()[::-1]))
     self.assertTrue(np.allclose(C1b.diagonal(), C2b.diagonal()[::-1]))
     
     # swapping class labels (or in this case, trials) should not change the result
     self.assertTrue(np.allclose(C1a, C1b))
     self.assertTrue(np.allclose(C2a, C2b))
     
     # variance of first component should be greatest for class 1
     self.assertTrue(C1a[0,0] > C2a[0,0])
     
     # variance of last component should be greatest for class 1
     self.assertTrue(C1a[2,2] < C2a[2,2])
     
     # variance of central component should be equal for both classes
     self.assertTrue(np.allclose(C1a[1,1], C2a[1,1]))
Пример #2
0
 def setUp(self):
     self.X = np.random.rand(100,15,10)
     self.C = [0,0,0,0,0,1,1,1,1,1]
     self.Y = self.X.copy()
     self.D = self.C.copy()
     self.N, self.M, self.T = self.X.shape
     self.W, self.V = csp(self.X, self.C, numcomp=5)