-
-
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
Provide logabsdet(::Matrix)? #3070
Comments
There is a bug in cholfact:
Also, is there or can there be some interface for getting log(abs(det)) and the sign? Or det of non-positive-definite matrices? |
@JeffBezanson A det method for the LU type already exists. So logdet for a square matrix should be defined similarly although it would need to return log(abs(det)) and the sign separately. |
The inconsistency is that at present |
Having logdet always return a complex result occurred to me too and feels more appealing than returning both a value and a sign, bu it does seem inconsistent with our other functions, which return NaN when applied to a real value in such a way that the result would be non-real. |
We now throw domain errors instead of returning NaN. |
Oh, right. But same idea. |
The thinking among the R developers was that returning the logarithm of the absolute value of the determinant along with its sign was done to provide a more stable calculation and to avoid overflow/underflow. However I will admit that almost all the time I use logdet it is for a positive definite matrix, usually some form of a variance-covariance matrix. |
While we're on logdet, it might be nice to supply Woodbury with a logdet too. Woodbury is e.g. useful in probability theory when doing factor analysis, in which case the determinants also end up being positive. Since the woodbury matrices can be huge, the determinant may well under/overflow, but logdet won´t. |
Restricting For example, in some problems arising in integral-equation methods for quantum field theory, we need the logdet of a real matrix Also, currently the |
I agree with @stevengj that returning a complex result from |
So returning a complex number from
Are there other options I'm missing? If not, which of these is the better choice? |
It could work like |
I'm not a fan of |
Then I'd prefer |
Another option is to have two functions, of which one could be called |
@StefanKarpinski, I would tend to (2) restrict
In theory, I suppose that you could also have an unsymmetrical complex matrix that nevertheless has a positive real determinant, but I'm not sure that this case arises enough that it is worth the trouble to figure out how to compute |
@ViralBShah, @timholy Tim proposed |
I think Viral was acknowledging that, but |
Another option would be a keyword argument indicating whether to take the absolute value or not. |
Of course - let's go with a keyword argument. |
Could someone enlighten me on the advantage of |
I was proposing |
I think @stevengj 's point was that But if we do give it a separate name, I think |
Yeah, I'm not sold on using a keyword, just an idea. Calling it logdetabs seems outright obtuse. |
It sounds like |
Yeah, good point. I was imagining the keyword as only affecting whether a negative determinant causes an error or a sign flip (I realize it may not be implemented that way). |
Ok. The arguments for logabsdet are quite persuasive. |
See my comment in #3295, where I give a tyre-kicking implementation of a generalized, but type-stable logdet for the LU factorization. There is a |
FWIW, in numpy the |
Fix #3070. Rename logdet2 to logabsdet + export and tests.
The current logdet implementation in linalg/dense.jl,
would probably be cleaner if implemented as:
The text was updated successfully, but these errors were encountered: