How to effectively use inverse and determinant in Eigen?

Eigen has guidelines that warn against explicitly evaluating determinants and inverse matrices.

I am implementing backward prediction for a multivariate normal with a pre-distribution with normal inverse wish. This can be expressed as a multivariate t-distribution.

In the multivariate t-distribution, you will find the term |Sigma|^{-1/2}

as well (x-mu)^T Sigma^{-1} (x-mu)

.

I am completely ignorant of Eigen. I can imagine that for a positive semidefinite matrix (this is a covariance matrix) I can use the LLT solver.

However, there are no methods .determinant()

and .inverse()

defined on the solver. Should I use a function .matrixL()

and myself invert the elements on the diagonal for the opposite, and also compute the product to get the determinant? I think I am missing something.

+3


source to share


1 answer


If you have a Cholesky factorization Sigma=LL^T

and want (x-mu)^T*Sigma^{-1}*(x-mu)

, you can calculate: (llt.matrixL().solve(x-mu)).squaredNorm()

(assuming x

and mu

are vectors).



For a square root, the determinant is easy to compute llt.matrixL().determinant()

(computing the determinant of a triangular matrix is ​​simply the product of its diagonal elements).

+1


source







All Articles