Skip to main content
 首页 » 编程设计

python之TensorFlow 中的特征值问题

2024年08月20日29qq号

我想使用 TensorFlow 解决特征值问题。 特别是,我有

e, v = tf.self_adjoint_eig(laplacian, name="eigendata") 
eigenmap = v[:,1:4] 

所以我不想计算所有特征向量。

在 Matlab 中,我会使用 eigs(laplacian,4,'sm')

查看https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/linalg_ops.py , 我看到 tf.self_adjoint_eig 调用了 gen_linalg_ops._self_adjoint_eig_v2。 但是,我在 Github 或其他地方找不到 gen_linalg_ops。

关于在 TensorFlow 中进行此类线性代数的任何建议,还是最好与 Python 中的其他库一起使用?

请您参考如下方法:

MATLAB 函数 EIG 计算所有特征向量。 MATLAB 函数 EIGS 仅使用预编译的 https://en.wikipedia.org/wiki/ARPACK 计算选定数量的特征向量它实现了 https://en.wikipedia.org/wiki/Lanczos_algorithm MATLAB 中没有本地 MATLAB Lanczos 代码,很可能是因为 Lanczos 算法在舍入误差方面不可避免地不稳定,尤其是在单精度方面,这使得更稳定的实现变得棘手和/或昂贵。

EIGS 函数的替代方法是 https://www.mathworks.com/matlabcentral/fileexchange/48-lobpcg-m实现 https://en.wikipedia.org/wiki/LOBPCG原生在 MATLAB 中。

SciPy 有一个到 ARPACK 的接口(interface)以及 Python native 实现 https://docs.scipy.org/doc/scipy-1.1.0/reference/generated/scipy.sparse.linalg.lobpcg.html

Scikit 使用 ARPACK 或 LOBPCG 进行流形谱嵌入 http://scikit-learn.org/stable/modules/generated/sklearn.manifold.spectral_embedding.html和光谱聚类 http://scikit-learn.org/stable/modules/generated/sklearn.cluster.SpectralClustering.html

TensorFlow 现在有 Lanczos 的原生实现 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/solvers/python/ops/lanczos.py