-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Real-valued results for sqrtm #11655
Comments
For completeness, I should have referenced relevant discussions in #4006. |
How to make the correct tolerancing decision on "sloppiness" in slightly negative eigenvalues is something that gives me pause. Would not want to do something like that without carefully thinking through the consequences. edit: I'm wondering whether we might want to move towards user-provided positive definiteness annotations via the type system as a long-term direction for this. |
cc: @alanedelman |
Agreed it's a slippery slope. One data point: Matlab returns a real-valued matrix for this problem, but their |
If we consider your matrix a realization of random matrix, the smallest computed eigenvalues are symmetrically distributed around zero even though the true value is in fact zero. Therefore, the right choice of cutoff value or the sloppiness parameter would probably depend on the distribution of the entries and the true rank neither of which we know. It could be fun to take the statistical aspects of this seriously, but I guess a simplified approach is often preferred. E.g. it seems that MATLAB handles this in the same way as we are doing now. We use a different default eigensolvers, but we can reproduce MATLAB with julia> LAPACK.syev!('V', 'U', copy(A))[1][1]
2.549678219012986e-10 so it is just chance that MATLAB happens to return a real result. >> A = randi([1 100], 3,2);
>> sqrtm(A*A')
ans =
42.4942 + 0.0000i 53.0067 - 0.0000i 40.1066 - 0.0000i
53.0067 - 0.0000i 77.7233 + 0.0000i 35.7965 + 0.0000i
40.1066 - 0.0000i 35.7965 + 0.0000i 55.3089 + 0.0000i |
What about retrospectively deciding what to return? For example, does it make sense to take the real component and do something like |
I think it is too costly to add such a test and effectively it must be very to setting small negative eigenvalues to zero which would be much cheaper. My feeling is that we should keep the present behavior unless we can come up with something more clever than the solutions mentioned so far. I you plan to roll your own positive semidefinite |
Sounds reasonable to me, too. |
The following matrix:
poses problems for
sqrtm
. Currently,sqrtm
gives a complex result, but that result is no more accurate than the real-valued version:The fundamental reason why it returns a complex-valued matrix seems to be this:
On balance, I suspect we should make
sqrtm
more inclined to return a real-valued matrix. If others agree, I'm not sure where the right place to change this is, but my money is on adding a "sloppiness" here.The text was updated successfully, but these errors were encountered: