def lapeig_linear(X=None, W=None, L=None, num_vecs=None, k=None, eball=None): if L is None: if W is None: W = neighbor_graph(X, k=k, epsilon=eball) L = laplacian(W) u, s, _ = np.linalg.svd(np.dot(X.T, X)) Fplus = np.linalg.pinv(np.dot(u, np.diag(np.sqrt(s)))) T = reduce(np.dot, (Fplus, X.T, L, X, Fplus.T)) L = 0.5 * (T + T.T) return lapeig(L=L, num_vecs=num_vecs)
def lapeig(W=None, L=None, num_vecs=None, return_vals=False): tmp_L = (L is None) # we can overwrite L if it's a tmp variable if L is None: L = laplacian(W, normed=True) vals,vecs = sp.linalg.eigh(L, overwrite_a=tmp_L) # assumes L is symmetric! # not guaranteed to be in sorted order idx = np.argsort(vals) vecs = vecs.real[:,idx] vals = vals.real[idx] # discard any with really small eigenvalues for i in range(vals.shape[0]): if vals[i] >= 1e-8: break if num_vecs is None: # take all of them num_vecs = vals.shape[0] - i embedding = vecs[:,i:i+num_vecs] if return_vals: return embedding, vals[i:i+num_vecs] return embedding
def lapeig(W=None, L=None, num_vecs=None, return_vals=False): tmp_L = L is None # we can overwrite L if it's a tmp variable if L is None: L = laplacian(W, normed=True) vals, vecs = sp.linalg.eigh(L, overwrite_a=tmp_L) # assumes L is symmetric! # not guaranteed to be in sorted order idx = np.argsort(vals) vecs = vecs.real[:, idx] vals = vals.real[idx] # discard any with really small eigenvalues for i in xrange(vals.shape[0]): if vals[i] >= 1e-8: break if num_vecs is None: # take all of them num_vecs = vals.shape[0] - i embedding = vecs[:, i : i + num_vecs] if return_vals: return embedding, vals[i : i + num_vecs] return embedding
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 _manifold_setup(Wx, Wy, Wxy, mu): Wxy = mu * (Wx.sum() + Wy.sum()) / (2 * Wxy.sum()) * Wxy W = np.asarray(np.bmat(((Wx, Wxy), (Wxy.T, Wy)))) return laplacian(W)
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 _manifold_setup(Wx,Wy,Wxy,mu): Wxy = mu * (Wx.sum() + Wy.sum()) / (2 * Wxy.sum()) * Wxy W = np.asarray(np.bmat(((Wx,Wxy),(Wxy.T,Wy)))) return laplacian(W)