小特征值的Scipy稀疏eigsh() [英] Scipy's sparse eigsh() for small eigenvalues

查看:151
本文介绍了小特征值的Scipy稀疏eigsh()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SciPy的稀疏线性代数库,使用NumPy/SciPy针对较大(但仍易于处理)的系统编写光谱聚类算法.不幸的是,我遇到了

I'm trying to write a spectral clustering algorithm using NumPy/SciPy for larger (but still tractable) systems, making use of SciPy's sparse linear algebra library. Unfortunately, I'm running into stability issues with eigsh().

这是我的代码:

import numpy as np
import scipy.sparse
import scipy.sparse.linalg as SLA
import sklearn.utils.graph as graph

W = self._sparse_rbf_kernel(self.X_, self.datashape)
D = scipy.sparse.csc_matrix(np.diag(np.array(W.sum(axis = 0))[0]))
L = graph.graph_laplacian(W) # D - W
vals, vects = SLA.eigsh(L, k = self.k, M = D, which = 'SM', sigma = 0, maxiter = 1000)

sklearn库引用了scikit-learn包,特别是

The sklearn library refers to the scikit-learn package, specifically this method for calculating a graph laplacian from a sparse SciPy matrix.

_sparse_rbf_kernel是我编写的一种计算数据点的成对亲和力的方法.它通过从图像数据中创建稀疏的亲和度矩阵来进行操作,特别是仅通过计算每个像素周围的8个邻域的成对亲和力(而不是使用scikit-learn的rbf_kernel方法对所有像素进行成对亲和力,但记录无法解决此问题)要么.)

_sparse_rbf_kernel is a method I wrote to compute pairwise affinities of the data points. It operates by creating a sparse affinity matrix from image data, specifically by only computing pairwise affinities for the 8-neighborhoods around each pixel (instead of pairwise for all pixels with scikit-learn's rbf_kernel method, which for the record doesn't fix this either).

由于拉普拉斯算子未归一化,所以我正在寻找系统的最小特征值和相应的特征向量.我了解 ARPACK不适合查找较小的特征值,但是我试图使用shift-invert来找到这些值,但仍然没有太大的成功.

Since the laplacian is unnormalized, I'm looking for the smallest eigenvalues and corresponding eigenvectors of the system. I understand that ARPACK is ill-suited for finding small eigenvalues, but I'm trying to use shift-invert to find these values and am still not having much success.

使用上述参数(特别是sigma = 0),出现以下错误:

With the above arguments (specifically, sigma = 0), I get the following error:

RuntimeError:因子完全是单数

RuntimeError: Factor is exactly singular

使用sigma = 0.001时,出现另一个错误:

With sigma = 0.001, I get a different error:

scipy.sparse.linalg.eigen.arpack.arpack.ArpackNoConvergence:ARPACK错误-1:无收敛(1001次迭代,0/5特征向量收敛)

scipy.sparse.linalg.eigen.arpack.arpack.ArpackNoConvergence: ARPACK error -1: No convergence (1001 iterations, 0/5 eigenvectors converged)

我为mode尝试了所有三个不同的值,结果相同. 关于使用SciPy稀疏库查找大型系统的小特征值的任何建议吗?

I've tried all three different values for mode with the same result. Any suggestions for using the SciPy sparse library for finding small eigenvalues of a large system?

推荐答案

您应该使用which='LM':在平移-反转模式下,此参数引用转换后的特征值. (如文档中所述.)

You should use which='LM': in the shift-invert mode, this parameter refers to the transformed eigenvalues. (As explained in the documentation.)

这篇关于小特征值的Scipy稀疏eigsh()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆