Log determinant of positive definite matrices in Matlab

In Bayesian data analysis, the log determinant of symmetric positive definite matrices often pops up as a normalizing constant in MAP estimates with multivariate Gaussians (ie, chapter 27 of Mackay). Oftentimes, the determinant of A will evaluate as infinite in Matlab although the log det is finite, so one can’t use log(det(A)). However, we know that:

  1. \mathbf{A} = \mathbf{L}\mathbf{L}' (Cholesky decomposition)
  2. |\mathbf{L}| = \prod_i L_{ii} (determinant of a lower triangular matrix)
  3. \log \prod_i x_i = \sum_i \log x_i (log rule)

Thus to calculate the log determinant of a symmetric positive definite matrix:

L = chol(A);
logdetA = 2*sum(log(diag(L)));

6 thoughts on “Log determinant of positive definite matrices in Matlab

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s