Mercurial > hg > ishara
annotate general/numerical/matrix/logabsdet.m @ 61:eff6bddf82e3 tip
Finally implemented perceptual brightness thing.
author | samer |
---|---|
date | Sun, 11 Oct 2015 10:20:42 +0100 |
parents | db7f4afd27c5 |
children |
rev | line source |
---|---|
samer@4 | 1 function y = logabsdet(A) |
samer@4 | 2 % logabsdet - logabsdet(X)=log(abs(det(X))) |
samer@4 | 3 % |
samer@4 | 4 % logabsdet :: [[N,N]] -> nonneg. |
samer@4 | 5 % |
samer@4 | 6 % This is faster and more stable than using log(det(A)). |
samer@4 | 7 % (Except when A is not positive definite, in which case |
samer@4 | 8 % we fall back to computing det(A) the usual way.) |
samer@4 | 9 |
samer@4 | 10 % From Tom Minka's lightspeed toolbox |
samer@4 | 11 % Samer: added clause incase A not pos def. |
samer@4 | 12 |
samer@4 | 13 % this only works for HERMITIAN POS DEF matrix. |
samer@4 | 14 % y = 2*sum(log(diag(chol(A)))); |
samer@4 | 15 |
samer@4 | 16 [R,p]=chol(A*A'); |
samer@4 | 17 if p>0, |
samer@4 | 18 fprintf('*** logabsdet warning: matrix is singular'); |
samer@4 | 19 y=-inf; |
samer@4 | 20 else |
samer@4 | 21 y = sum(log(full(diag(R)))); |
samer@4 | 22 end |