我正在尝试在Python中实现Nystrom近似方法。假设我已经计算了亲和度矩阵A(在所选样本之间)和B(在其余样本和所选样本之间),这是我的代码:
B_T = np.transpose(B)
d1 = np.sum(np.vstack((A, B_T)), 0)[np.newaxis]
d2 = np.sum(B, 0) + np.dot(np.sum(B_T, 0), np.dot(np.linalg.pinv(A), B))[np.newaxis]
dhat = np.sqrt(1./np.hstack((d1, d2))).T
A = np.dot(A, np.dot( dhat[0:subset_len], dhat[0:subset_len].T ) )
B1 = np.dot( dhat[0:subset_len], dhat[subset_len:].T)
B = B*B1
# here is the eigendecomposition
B_T = np.transpose(B)
Apseudo = np.sqrt(np.linalg.pinv(A))
BBT = np.dot(B,B_T)
W = np.vstack((A, B_T))
S = A + np.dot(Apseudo, np.dot(BBT, Apseudo) )
w,v = np.linalg.eigh(S)
ind = np.argsort(w)[::-1]
v = v[:, ind] # eigenvectors in decreasing order
w = w[ind] # eigenvalues in decreasing order
w = np.diag(w)
W = np.dot(W, Apseudo)
V1 = np.dot(W, np.dot(v, np.linalg.pinv(np.sqrt(w))))
m = 45 #embedding dimension
V = V1[:,:m]
# normalize eigenvectors to have unit length
for j in range(len(w)):
V[:,j] = V[:,j]/np.sqrt(np.sum(V,0))
V[:,j] = V[:,j]/np.linalg.norm(V[:,j])
当我执行文件时,我在计算V1时出现错误:**进入DLASCL参数编号4时出现非法值。可以请某人帮我解决实施和这个错误吗?
这是对完全没有意识到的人的方法的简要说明。Here is the Nystrom method