Reputation: 3149
In Eigen there are recommendations that warn against the explicit calculation of determinants and inverse matrices.
I'm implementing the posterior predictive for the multivariate normal with a normal-inverse-wishart prior distribution. This can be expressed as a multivariate t-distribution.
In the multivariate t-distribution you will find a term |Sigma|^{-1/2}
as well as (x-mu)^T Sigma^{-1} (x-mu)
.
I'm quite ignorant with respect to Eigen. I can imagine that for a positive semidefinite matrix (it is a covariance matrix) I can use the LLT solver.
There are however no .determinant()
and .inverse()
methods defined on the solver itself. Do I have to use the .matrixL()
function and inverse the elements on the diagonal myself for the inverse, as well as calculate the product to get the determinant? I think I'm missing something.
Upvotes: 3
Views: 6147
Reputation: 18807
If you have the Cholesky factorization of Sigma=LL^T
and want (x-mu)^T*Sigma^{-1}*(x-mu)
, you can compute: (llt.matrixL().solve(x-mu)).squaredNorm()
(assuming x
and mu
are vectors).
For the square root of the determinant, just calculate llt.matrixL().determinant()
(calculating the determinant of a triangular matrix is just the product of its diagonal elements).
Upvotes: 2