Closed timholy closed 9 years ago
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 eig
also returns 2.5495e-10
for the smallest eigenvalue.
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 sumabs(A - Mr*Mr)
, comparing that against a threshold? The problem I see with that test is that it's a second O(N^3)
operation. It's one with a smaller coefficient (by about 4-fold in my tests), but it would still be a measurable burden.
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 sqrtm
then remember that you can ask for a specific part of the spectrum which will save you a little time, i.e. eigfact(Symmetric(A), 0.0, Inf)
.
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.