Logarithm determinant, aka log-det, is useful in numerous statistical applications and related fields, including machine learning, for example, it is used in calculating log probability density function (logpdf) and maximum log-likelihood function.
The log-determinant of a positive definite matrix can be calculated by finding the trace of
We have previously seen ways to estimate trace of logarithm by using Stochastic Lanczos Quadrature and Chebyshev-Hutchinson Polynomial Interpolation (or Chebyhutch). In this article, we are going to focus on using Chebyhutch to calculate logdet for sparse matrices.
A relative error in the magnitude of 10is good enough for most of the numerical work.
Application - SparseMvNormal
I have already setup the environment for SparseMvNormal, which is internally using Chebyhutch for calculating the logdet. We are going to see a simple application where we find logpdf of a sparse covariance matrix with a random mean vector.
# Start by importing the code from environmentinclude("/SparseMvNormalCode")
# Generating the vectors for MvNormal examplev=rand(size(A, 1))
x=rand(-100.0:2:100.0, size(A, 1))
As we can see, the results are good for any numerical purposes.
Since MvNormal uses Cholesky decomposition to calculate logdet we should to do another execution time analysis.
# Wrapper for complete logpdf using MvNormalfunctionclogpdf(A::AbstractMatrix, v::AbstractVector, x::AbstractVector)
end# Wrapper for complete logpdf using SparseMvNormalfunctionclogpdf(A::AbstractSparseMatrix, v::AbstractVector, x::AbstractVector)