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 slgaussinv
Home > sltoolbox > stat > slgaussinv.m

slgaussinv

PURPOSE ^

SLGAUSSINV Computes the inverse of variance/covariance in Gaussian model

SYNOPSIS ^

function R = slgaussinv(GS, fn, invparams)

DESCRIPTION ^

SLGAUSSINV Computes the inverse of variance/covariance in Gaussian model

 $ Syntax $
   - R = slgaussinv(GS, fn, invparams)

 $ Arguments $
   - GS:           The Gaussian struct
   - fn:           the fieldname representing thr variance: 'vars'|'covs'
   - invparams:    the cell array of parameters for computing inverses
   - R:            the computed result

 $ Description $
   - R = slgaussinv(GS, fn, invparams) computes the inverse of variances or 
     covariances for Gaussian models. 

 $ Remarks $
   - For vars, the inverses will be computed using slinvevals, while
     for covs, the inverses will be computed using slinvcov.

 $ History $
   - Created by Dahua Lin, on Aug 26, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slinvcov SLINVCOV Compute the inverse of an covariance matrix
  • slinvevals SLINVEVALS Compute the reciprocals of eigenvalues in a robust way
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:
  • slgausscomb SLGAUSSCOMB Collects the means and variances/covariances to form GS
  • slgaussest SLGAUSSEST Estimates the Gaussian models from samples

SOURCE CODE ^

0001 function R = slgaussinv(GS, fn, invparams)
0002 %SLGAUSSINV Computes the inverse of variance/covariance in Gaussian model
0003 %
0004 % $ Syntax $
0005 %   - R = slgaussinv(GS, fn, invparams)
0006 %
0007 % $ Arguments $
0008 %   - GS:           The Gaussian struct
0009 %   - fn:           the fieldname representing thr variance: 'vars'|'covs'
0010 %   - invparams:    the cell array of parameters for computing inverses
0011 %   - R:            the computed result
0012 %
0013 % $ Description $
0014 %   - R = slgaussinv(GS, fn, invparams) computes the inverse of variances or
0015 %     covariances for Gaussian models.
0016 %
0017 % $ Remarks $
0018 %   - For vars, the inverses will be computed using slinvevals, while
0019 %     for covs, the inverses will be computed using slinvcov.
0020 %
0021 % $ History $
0022 %   - Created by Dahua Lin, on Aug 26, 2006
0023 %
0024 
0025 %% parse and verify input arguments
0026 
0027 if nargin < 3
0028     raise_lackinput('slgaussinv', 3);
0029 end
0030 
0031 if ~isstruct(GS)
0032     error('sltoolbox:invalidarg', ...
0033         'GS should be a struct');
0034 end
0035 
0036 if ~isfield(GS, fn)
0037     error('sltoolbox:invalidarg', ...
0038         '%s should be a field of GS', fn);
0039 end
0040 
0041 %% computation
0042 
0043 switch fn
0044     case 'vars'
0045         vars = GS.vars;
0046         [dv, kv] = size(vars);
0047         if dv == 1
0048             if kv == 1
0049                 invvars = 1 / vars;
0050             else
0051                 invvars = 1 ./ vars;
0052             end
0053         else
0054             if kv == 1
0055                 invvars = slinvevals(vars, invparams{:});
0056             else
0057                 invvars = zeros(dv, kv);
0058                 for i = 1 : kv
0059                     invvars(:,i) = slinvevals(vars(:,i), invparams{:});
0060                 end
0061             end
0062         end
0063         R = invvars;
0064         
0065     case 'covs'
0066         covs = GS.covs;
0067         invcovs = slinvcov(covs, invparams{:});
0068         R = invcovs;
0069         
0070     otherwise
0071         error('sltoolbox:invalidarg', ...
0072             'Invalid variance/covariance fieldname %s', fn);
0073 end
0074         
0075         
0076         
0077

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

Contact us at files@mathworks.com