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.concatenate([A[np.newaxis], B[np.newaxis]], axis=0) W, V = csp(X, [1, 2]) C1a = np.cov(np.dot(W.T, X[0, :, :])) C2a = np.cov(np.dot(W.T, X[1, :, :])) Y = np.concatenate([B[np.newaxis], A[np.newaxis]], axis=0) W, V = csp(Y, [1, 2]) C1b = np.cov(np.dot(W.T, Y[0, :, :])) C2b = np.cov(np.dot(W.T, Y[1, :, :])) # check symmetric case assert_allclose(C1a.diagonal(), C2a.diagonal()[::-1]) assert_allclose(C1b.diagonal(), C2b.diagonal()[::-1]) # swapping class labels (or in this case, trials) should not change the result assert_allclose(C1a, C1b, rtol=1e-9, atol=1e-9) assert_allclose(C2a, C2b, rtol=1e-9, atol=1e-9) # variance of first component should be greatest for class 1 self.assertGreater(C1a[0, 0], C2a[0, 0]) # variance of last component should be greatest for class 1 self.assertLess(C1a[2, 2], C2a[2, 2]) # variance of central component should be equal for both classes assert_allclose(C1a[1, 1], C2a[1, 1])
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]))
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 = list(self.C) self.N, self.M, self.T = self.X.shape self.W, self.V = csp(self.X, self.C, numcomp=5)
def setUp(self): self.X = np.random.randn(10, 5, 100) self.C = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] self.Y = self.X.copy() self.D = list(self.C) self.T, self.M, self.N = self.X.shape self.W, self.V = csp(self.X, self.C)
def setUp(self): self.n_comps = 5 self.X = np.random.rand(10, 6, 100) self.C = np.asarray([0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) self.X[self.C == 0, 0, :] *= 10 self.X[self.C == 0, 2, :] *= 5 self.X[self.C == 1, 1, :] *= 10 self.X[self.C == 1, 3, :] *= 2 self.Y = self.X.copy() self.D = list(self.C) self.T, self.M, self.N = self.X.shape self.W, self.V = csp(self.X, self.C, numcomp=self.n_comps)