文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
放到一起
def eigen(A, max_iter=20):
Q, H = arnoldi(A)
Ak, QQ = practical_qr(H, max_iter)
U = Q @ QQ
D = np.diag(Ak)
return U, D
n = 10
A0 = np.random.rand(n,n)
A = A0 @ A0.T
U, D = eigen(A, 40)
'''
14.897422908
1.57451192745
1.4820012435
0.668164424736
0.438450319682
0.674050723258
1.19470880942
0.217103444634
0.105443975462
3.8162597576e-15
[ 27.34799 1.22613 1.29671 0.70253 0.49651 0.56779 0.60974
0.70123 0.19209 0.04905]
[ 27.34981 1.85544 1.04793 0.49607 0.44505 0.7106 1.00724
0.07293 0.16058 0.04411]
[ 27.34981 2.01074 0.96045 0.54926 0.61117 0.8972 0.53424
0.19564 0.03712 0.04414]
[ 27.34981 2.04342 0.94444 0.61517 0.89717 0.80888 0.25402
0.19737 0.03535 0.04414]
[ 27.34981 2.04998 0.94362 0.72142 1.04674 0.58643 0.21495
0.19735 0.03534 0.04414]
[ 27.34981 2.05129 0.94496 0.90506 0.95536 0.49632 0.21015
0.19732 0.03534 0.04414]
[ 27.34981 2.05156 0.94657 1.09452 0.79382 0.46723 0.20948
0.1973 0.03534 0.04414]
[ 27.34981 2.05161 0.94863 1.1919 0.70539 0.45628 0.20939
0.19728 0.03534 0.04414]
[ 27.34981 2.05162 0.95178 1.22253 0.67616 0.45174 0.20939
0.19727 0.03534 0.04414]
[ 27.34981 2.05162 0.95697 1.22715 0.66828 0.44981 0.2094
0.19725 0.03534 0.04414]
[ 27.34981 2.05162 0.96563 1.22124 0.66635 0.44899 0.20941
0.19724 0.03534 0.04414]
[ 27.34981 2.05162 0.97969 1.20796 0.66592 0.44864 0.20942
0.19723 0.03534 0.04414]
[ 27.34981 2.05162 1.00135 1.18652 0.66585 0.44849 0.20943
0.19722 0.03534 0.04414]
[ 27.34981 2.05162 1.03207 1.15586 0.66584 0.44843 0.20943
0.19722 0.03534 0.04414]
[ 27.34981 2.05162 1.07082 1.11714 0.66584 0.4484 0.20944
0.19721 0.03534 0.04414]
[ 27.34981 2.05162 1.11307 1.07489 0.66585 0.44839 0.20944
0.1972 0.03534 0.04414]
[ 27.34981 2.05162 1.15241 1.03556 0.66585 0.44839 0.20945
0.1972 0.03534 0.04414]
[ 27.34981 2.05162 1.18401 1.00396 0.66585 0.44839 0.20945
0.1972 0.03534 0.04414]
[ 27.34981 2.05162 1.20652 0.98145 0.66585 0.44839 0.20946
0.19719 0.03534 0.04414]
[ 27.34981 2.05162 1.22121 0.96676 0.66585 0.44839 0.20946
0.19719 0.03534 0.04414]
[ 27.34981 2.05162 1.23026 0.95771 0.66585 0.44839 0.20946
0.19719 0.03534 0.04414]
[ 27.34981 2.05162 1.23563 0.95234 0.66585 0.44839 0.20946
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.23876 0.94921 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24056 0.94741 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24158 0.94639 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24216 0.94581 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24249 0.94548 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24268 0.94529 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24278 0.94519 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24284 0.94513 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.24288 0.94509 0.66585 0.44839 0.20947
0.19718 0.03534 0.04414]
[ 27.34981 2.05162 1.2429 0.94507 0.66585 0.44839 0.20947
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24291 0.94506 0.66585 0.44839 0.20947
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24291 0.94506 0.66585 0.44839 0.20947
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24292 0.94505 0.66585 0.44839 0.20947
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24292 0.94505 0.66585 0.44839 0.20947
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24292 0.94505 0.66585 0.44839 0.20948
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24292 0.94505 0.66585 0.44839 0.20948
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24292 0.94505 0.66585 0.44839 0.20948
0.19717 0.03534 0.04414]
[ 27.34981 2.05162 1.24292 0.94505 0.66585 0.44839 0.20948
0.19717 0.03534 0.04414]
'''
D
'''
array([ 5.10503, 0.58805, 0.49071, -0.65174, -0.60231, -0.37664,
-0.13165, 0.0778 , -0.10469, -0.29771])
np.linalg.eigvals(A)
array([ 27.34981, 2.05162, 1.24292, 0.94505, 0.66585, 0.44839,
0.20948, 0.19717, 0.04414, 0.03534])
'''
np.linalg.norm(U @ np.diag(D) @ U.T - A)
# 0.0008321887107978883
np.allclose(U @ np.diag(D) @ U.T, A, atol=1e-3)
# True
扩展阅读
让我们找一些特征值!
来自 非对称特征值问题 章节:
注意,“直接”方法仍然必须迭代,因为找到特征值在数学上等同于找到多项式的零,因此不存在非迭代方法。 如果经验表明它(几乎)永远不会在固定数量的迭代中收敛,我们就直接调用一个方法。
迭代方法通常仅对特征值和特征向量的子集提供近似,并且通常仅运行足够长的时间,来获得一些足够精确的特征值而不是大量的特征值。
我们的最终算法:带移位的海森堡 QR 算法。
阅读更多:
- 对称特征问题和 SVD
- 特征值问题的迭代方法 :Rayleigh-Ritz 方法,Lanczos 算法
接下来
我们将来会编写自己的 QR 分解(两种不同的方式!),但首先我们将看到另一种可以使用 QR 分解的方法:计算线性回归。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论