- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图用 Scipy 解决一个大的特征值问题,其中矩阵 A
是密集的,但我可以计算它对向量的作用而无需组装 A
明确地。因此,为了避免矩阵 A 变大时出现内存问题,我想使用稀疏求解器 scipy.sparse.linalg.eigs
与 LinearOperator
实现此操作。
申请eigs
到一个显式的 numpy 数组 A
工作正常。但是,如果我申请 eigs
到 LinearOperator
相反,迭代求解器无法收敛。即使 matvec
也是如此LinearOperator
的方法只是矩阵向量与给定矩阵的乘法 A
.
下面附上了一个说明失败的最小示例(我使用移位反转模式,因为我对最小的几个特征值感兴趣)。这将计算随机矩阵的特征值 A
很好,但应用于 LinearOperator
时失败直接从 A
转换而来.我试图摆弄迭代求解器的参数( v0
、 ncv
、 maxiter
)但无济于事。
我错过了一些明显的东西吗?有没有办法使这项工作?任何建议将不胜感激。非常感谢!
编辑:我应该澄清我所说的“使这项工作”是什么意思(谢谢,迪特里希)。下面的示例使用随机矩阵进行说明。但是,在我的应用程序中,我知道特征值几乎是纯虚数(或者如果我将矩阵乘以 1j
则几乎是纯实数)。我对 10-20 个最小幅度的特征值感兴趣,但如果我指定 which='SM'
,该算法表现不佳(即,即使对于小矩阵尺寸也不会停止) .因此,我通过传递参数 sigma=0.0, which='LM'
来使用 shift-invert 模式.我很高兴尝试不同的方法,只要它允许我计算一堆最小幅度的特征值。
from scipy.sparse.linalg import eigs, LinearOperator, aslinearoperator
import numpy as np
# Set a seed for reproducibility
np.random.seed(0)
# Size of the matrix
N = 100
# Generate a random matrix of size N x N
# and compute its eigenvalues
A = np.random.random_sample((N, N))
eigvals = eigs(A, sigma=0.0, which='LM', return_eigenvectors=False)
print eigvals
# Convert the matrix to a LinearOperator
A_op = aslinearoperator(A)
# Try to solve the same eigenproblem again.
# This time it produces an error:
#
# ValueError: Error in inverting M: function gmres did not converge (info = 1000).
eigvals2 = eigs(A_op, sigma=0.0, which='LM', return_eigenvectors=False)
最佳答案
我试过运行你的代码,但没有通过 sigma
eigs()
的参数它运行没有问题(阅读 eigs() docs 以了解其含义)。我在你的例子中没有看到它的好处。
关于numpy - 计算 scipy LinearOperator : "gmres did not converge" 的特征值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24216273/
我对 CBMutableCharacteristic 的特征值可以有多长感到困惑。如果我有一个归档对象数组,我可以将特征值设置为这个归档数组吗?或者我最好为数组中的每个归档对象设置一个单独的特征? 最
我在 Python Sympy 中使用来计算带有变量的矩阵 A 的特征值(例如)。有谁知道如何计算这样的矩阵的特征值?命令 A.eigenvals() 不起作用。例如下面的代码: x = symbol
我正在计算协方差矩阵的特征值,它是实数且对称的半正定矩阵。因此,特征值和特征向量都应该是实数,然而numpy.linalg.eig()返回具有(几乎)零虚部的复数值。 协方差矩阵太大,这里贴不出来,但
我正在尝试对图像使用光谱聚类。我首先计算亲和性矩阵,然后尝试获取特征向量。但是,在 7056x7056 矩阵上,eig() 调用花费的时间太长。关于如何改进这个的任何建议?也许我应该使用不同形式的亲和
我目前正在使用 Dart/Flutter BLE 插件来更好地了解 BLE 设备。 插件: https://pub.dartlang.org/packages/flutter_blue 当我连接到我的
我在使用 Eigen 库时遇到错误,我想做的就是从 Eigen::VectorXf 中减去一个标量。所以,我的代码如下: #define VECTOR_TYPE Eigen::VectorXf #de
假设我有一个对称矩阵 M,它不是正(半)定的,我想计算它的 k 顶(绝对值)特征值(和相应的特征向量)。现在,可以使用截断的 SVD 来做到这一点,它将返回所述特征值的绝对值,然后必须检查符号并找到相
我有一个关于 split 节点的问题。我有 4 个特征,想要预测这个人是否会玩,可能会玩,也可能不会玩。根据信息增益,我将“天气”作为第一个要分割的特征,其中“多雨”、“炎热”和“潮湿”作为分支。下雨
我有一个 ~3000x3000 类似协方差的矩阵,我在该矩阵上计算特征值-特征向量分解(它是一个 OpenCV 矩阵,我使用 cv::eigen() 来完成工作)。 但是,我实际上只需要前 30 个特
我想计算 K*es,其中 K 是一个 Eigen 矩阵(维度 pxp)和 es 是一个 px1 随机二进制 vector ,值为 1。 例如,如果 p=5 和 t=2 一个可能的 es 是 [1,0,
我正在尝试使用 CoreBluetooth 框架从设备读取所有可用服务及其特征值。 - (void)centralManager:(CBCentralManager *)central didDisc
我已经在 Internet 上多次看到这个主题,但从未见过一个完整、全面的解决方案,它可以适用于当前库版本的 sklearn 的所有用例。有人可以尝试使用以下示例解释如何实现吗? In this ex
我的输入 数据框(缩短)如下所示: >>> import numpy as np >>> import pandas as pd >>> df_in = pd.DataFrame([[1, 2, 'a
我想读取低功耗蓝牙(智能)的特征值。我不想使用 gatttool 或 btgatt-client。 d-bus 也没有帮助。我想在 Python 中执行此操作。我在以下内容中找不到任何示例: http
我是一名优秀的程序员,十分优秀!