Mathematica does-not have a function to compute the log-det of matrix? Naively computing Log[Det[M]] can be numerically unstable.

  • 3
    $\begingroup$ If speed isn't an issue, you could just do a SingularValueDecomposition, take the log of the singular values and take the Total $\endgroup$ – Niki Estner Feb 13 '20 at 11:48
  • $\begingroup$ Yes, speed (and memory) are an issue. Having to compute and store all the singular vectors is very wasteful. $\endgroup$ – becko Feb 13 '20 at 12:01
  • $\begingroup$ SingularValueList is about 2-3 times faster, and I would like to know too if there are significantly better ways to compute the log-determinant. $\endgroup$ – aooiiii Feb 13 '20 at 12:08
  • 1
    $\begingroup$ LUDecomposition is much faster, but potentially less stable. So, something like Total[Log[Abs[Diagonal[First[LUDecomposition[m]]]]]] should work (this removes the sign of the determinant, though) $\endgroup$ – Niki Estner Feb 13 '20 at 13:33
  • 1
    $\begingroup$ For general $\mathbf M$, I don't expect that you can do better than $O(n^3)$ effort for $\log\det\mathbf M$, even if it's SPD. But if the matrix has some sort of exploitable structure, perhaps... $\endgroup$ – J. M.'s torpor May 24 '20 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.