def __init__(self,X,Y,num_dims): mX = X - X.mean(0) mY = Y - Y.mean(0) Cxx = np.dot(mX.T,mX) Cyy = np.dot(mY.T,mY) Cxy = np.dot(mX.T,mY) d1,d2 = Cxy.shape if np.linalg.matrix_rank(Cxx) < d1 or np.linalg.matrix_rank(Cyy) < d2: lam = X.shape[0]/2.0 else: lam = 0 Cx = block_antidiag(Cxy,Cxy.T) Cy = sp.linalg.block_diag(Cxx + lam*np.eye(d1), Cyy + lam*np.eye(d2)) vals,vecs = sp.linalg.eig(Cx,Cy) vecs = vecs[np.argsort(vals)[::-1]] # descending order self.pX = vecs[:d1,:num_dims] self.pY = vecs[d1:d1+d2,:num_dims]
def test_block_antidiag(self): expected = np.array([[0, 0, 0, 1], [0, 0, 2, 3], [2, 3, 0, 0], [4, 5, 0, 0]]) assert_array_equal(util.block_antidiag(self.foo[:2], self.foo[1:]), expected)
def test_block_antidiag(self): expected = numpy.array([[0,0,0,1],[0,0,2,3],[2,3,0,0],[4,5,0,0]]) assert_array_equal(util.block_antidiag(self.foo[:2], self.foo[1:]), expected)
def __init__(self, X, Y, corr, num_dims, eps=1e-8): Wxy = corr.matrix() L = laplacian(block_antidiag(Wxy, Wxy.T)) self.pX, self.pY = _linear_decompose(X, Y, L, num_dims, eps)
def __init__(self,X,Y,corr,num_dims,eps=1e-8): Wxy = corr.matrix() L = laplacian(block_antidiag(Wxy,Wxy.T)) self.pX, self.pY = _linear_decompose(X,Y,L,num_dims,eps)