Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-11-27, 00:02   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 Different EigenVALUES between matlab and Python

I have two 19x19 covariance matrices Ron2 and Roff2, and need to translate matlab eig(Ron2, Roff2) to a python scipy.linalg.eig(Ron2, Roff2) so that the eigenvalues e follow Ron2*e = Roff2. I know the returned eigenvectors don't have to be the same values because of normalization differences (although they should point in the same direction)



However, the eigenvalues that are returned are not the same, usually. I've verified that the two matrices are indeed the same between the two languages. Here's what I've found:




  • On a separate machine with RHEL6 python 3.6.5, scipy 1.1.0, and numpy 1.14.3: Correct eigenvalues (this machine is also not connected to the data server)


  • On the desired machine with a custom conda environment with RHEL7, python 3.5.5/3.6.5, numpy 1.14.3/1.17.4, and scipy 1.1.0/1.3.1/1.3.3/1.3.4rc0 : Incorrect eigenvalues


  • On separate machines with RHEL6/RHEL7, python3.6.5, scipy 1.1.0, and numpy 1.14.3: Incorrect eigenvalues (these are connected to the data server, but not preferred)


  • Here's the fun part. If I isolate and save the matrices, then run the eigenvalue calc in a dummy matlab side script, I get matching eigenvalues to the 'incorrect' ones from the machines I mentioned above.




Does anyone have any ideas why the values won't be the same, despite the redhat/python/numpy/scipy versions matching? Are there other dependencies I don't know about that I should match? Since it is two square matrices, I can't use the numpy eigenvalue solver. The end goal of this code is to grab the normalized e-vector corresponding to the maximum eigenvalue. The matlab version used is '9.2.0.556344(R2017a)'. We also don't have to assume which set of eigenvalues is 'correct'.



Code snippets:



[V,e] = eig(Ron2,Roff2,'vector');
[d,idx]=max(e);
v=V(:,idx);
a=Roff2*v;
a=a./norm(a);


and



e,V=scipy.linalg.eig(Ron2,Roff2)
d=e.max()
idx=np.argmax(e)
v=V[:,idx]
a=np.matmul(Roff2,v)
a=a/np.linalg.norm(a)


These snippets run many times with the data I have, so I'm just testing the eigenvalues on the Ron2,Roff2 that goes through the first time. What is with the discrepancy?





More answer...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 23:27


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.