Safe computation of logarithm-determinat of large matrix

버전 1.0.0.0 (2.25 KB) 작성자: Dahua Lin
Computes the logarithm of determinant of a matrix in a safe way that avoids overflow/underflow.
다운로드 수: 3.7K
업데이트 날짜: 2008/11/8

라이선스 보기

Logarithm of determinant of a matrix widely occurs in the context of multivariate statistics. The log-pdf, entropy, and divergence of Gaussian distribution typically comprises a term in form of log-determinant. This function might be useful there, especially in a high-dimensional space.

However, the standard way of computing log-determinant:

log(det(A));

is likely to run into underflow or overflow, especially for large matrices, such as 1000 x 1000 or larger ones. The main cause of the problem is that the value of determinant is too large to be represented by a single or double number. However, what is needed is the logarithm of this value rather than the determinant itself. So an approach to circumvent this difficulty is to keep the computation at logarithm scale.

The key idea of the implementation is based on the mathematical fact that the determinant of a triangular matrix equals the product of its diagonal elements. Hence, the matrix's log-determinant is equal to the sum of their logarithm values. Therefore, we can effectively tackle the problem by computing sum-of-log rather than computing log-of-product. For generic matrix, it uses LU factorization, while for positive definite matrices, cholesky factorization can be used, which is typically more efficient.

The core of the implementation contains only several lines. Actually, this function is not to solve kind of complicated problems, but rather it is aimed at offering convenient help for you when you want to compute log-determinant of large matrices. The usage is very simple:

For generic matrix:

v = logdet(A);

for positive definite matrix (such as covariance matrix), it is faster to write

v = logdet(A, 'chol');

Hope it helps.

인용 양식

Dahua Lin (2024). Safe computation of logarithm-determinat of large matrix (https://www.mathworks.com/matlabcentral/fileexchange/22026-safe-computation-of-logarithm-determinat-of-large-matrix), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2008a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
도움

줌: Control Functionals

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0