samer@4: function y = logabsdet(A) samer@4: % logabsdet - logabsdet(X)=log(abs(det(X))) samer@4: % samer@4: % logabsdet :: [[N,N]] -> nonneg. samer@4: % samer@4: % This is faster and more stable than using log(det(A)). samer@4: % (Except when A is not positive definite, in which case samer@4: % we fall back to computing det(A) the usual way.) samer@4: samer@4: % From Tom Minka's lightspeed toolbox samer@4: % Samer: added clause incase A not pos def. samer@4: samer@4: % this only works for HERMITIAN POS DEF matrix. samer@4: % y = 2*sum(log(diag(chol(A)))); samer@4: samer@4: [R,p]=chol(A*A'); samer@4: if p>0, samer@4: fprintf('*** logabsdet warning: matrix is singular'); samer@4: y=-inf; samer@4: else samer@4: y = sum(log(full(diag(R)))); samer@4: end