Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sllogdet
Home > sltoolbox > core > sllogdet.m

sllogdet

PURPOSE ^

SLLOGDET Computes the logarithm of determinant of a matrix in a robust way

SYNOPSIS ^

function r = sllogdet(A)

DESCRIPTION ^

SLLOGDET Computes the logarithm of determinant of a matrix in a robust way

 $ Syntax $
   - r = sllogdet(A)

 $ Arguments $
   - A:       the square matrix whose log-determinant is to be solved
   - r:       the log-determinant of A

 $ Description $
   - r = sllogdet(A) computes the logarithm of (absolute )determinant of a square
     matrix A in a robust way, to reduce the risk of underflow or overflow.

 $ Remarks $
   - If the matrix is singular, inf or -inf would be return.

 $ History $
   - Created by Dahua Lin on Dec 28th, 2005

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
  • slgausspdf SLGAUSSPDF Computes the probability density of Gaussian models

SOURCE CODE ^

0001 function r = sllogdet(A)
0002 %SLLOGDET Computes the logarithm of determinant of a matrix in a robust way
0003 %
0004 % $ Syntax $
0005 %   - r = sllogdet(A)
0006 %
0007 % $ Arguments $
0008 %   - A:       the square matrix whose log-determinant is to be solved
0009 %   - r:       the log-determinant of A
0010 %
0011 % $ Description $
0012 %   - r = sllogdet(A) computes the logarithm of (absolute )determinant of a square
0013 %     matrix A in a robust way, to reduce the risk of underflow or overflow.
0014 %
0015 % $ Remarks $
0016 %   - If the matrix is singular, inf or -inf would be return.
0017 %
0018 % $ History $
0019 %   - Created by Dahua Lin on Dec 28th, 2005
0020 %
0021 
0022 %% parse and verify input arguments
0023 if ndims(A) ~= 2
0024     error('sltoolbox:invalidarg', 'A should be a 2D matrix');
0025 end
0026 d = size(A, 1);
0027 if size(A, 2) ~= d
0028     error('sltoolbox:invalidarg', 'A shoule be a square matrix');
0029 end
0030 
0031 %% compute
0032 
0033 % triangular decomposition
0034 [L, U] = lu(A);
0035 diagU = diag(U);
0036 slignorevars(L);
0037 clear L U;
0038 
0039 % sign controlling
0040 neg_u_entries = find(diagU < 0);
0041 if ~isempty(neg_u_entries)
0042     diagU(neg_u_entries) = -diagU(neg_u_entries);
0043 end
0044 
0045 % log-product
0046 wid = 'MATLAB:log:logOfZero';
0047 st = warning('query', wid);
0048 st = st.state;
0049 
0050 warning('off', wid);
0051 r = sum(log(diagU));
0052 warning(st, wid);
0053 
0054 
0055 
0056

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com