view general/numerical/matrix/logabsdet.m @ 42:ae596261e75f

Various fixes and development to audio handling
author samer
date Tue, 02 Dec 2014 14:51:13 +0000
parents db7f4afd27c5
children
line wrap: on
line source
function y = logabsdet(A)
% logabsdet - logabsdet(X)=log(abs(det(X))) 
%
% logabsdet :: [[N,N]] -> nonneg.
%
% This is faster and more stable than using log(det(A)).
% (Except when A is not positive definite, in which case
% we fall back to computing det(A) the usual way.)

%  From Tom Minka's lightspeed toolbox
%  Samer: added clause incase A not pos def.

% this only works for HERMITIAN POS DEF matrix.
% y = 2*sum(log(diag(chol(A))));

[R,p]=chol(A*A');
if p>0,
	fprintf('*** logabsdet warning: matrix is singular');
	y=-inf;
else
	y = sum(log(full(diag(R))));
end