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

slgausstype

PURPOSE ^

SLGAUSSTYPE Judges the type of a Gaussian model struct

SYNOPSIS ^

function tyinfo = slgausstype(GS)

DESCRIPTION ^

SLGAUSSTYPE Judges the type of a Gaussian model struct

 $ Syntax $
   - tyinfo = slgausstype(GS)

 $ Arguments $
   - GS:       the Gaussian model struct
   - tyinfo:   the type information structure with following fields
               - varform:  the form of variance: 'univar'|'diagvar'|'covar'
               - sharevar: whether the variance(covariance) is shared
               - hasinv:   whether is invvars or invcovs exists
               - hasmw:    whether the mixture weights exist

 $ Remarks $
   - The function will check the validity of the struct and will raise
     an error for invalid models. So it can be used to check validity
     even you don't need to know the type of the model.

 $ History $
   - Created by Dahua Lin, on Aug 23rd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slisfields SLISFIELDS Judges whether the specified fieldnames are fields of S
This function is called by:
  • slgaussmdist SLGAUSSMDIST Computes the Malanobis distance between samples and centers
  • slgausspdf SLGAUSSPDF Computes the probability density of Gaussian models
  • slgaussrnd SLGAUSSRND Generates random samples from Gaussian models
  • slgmm SLGMM Learns Gaussian Mixture model from samples

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function tyinfo = slgausstype(GS)
0002 %SLGAUSSTYPE Judges the type of a Gaussian model struct
0003 %
0004 % $ Syntax $
0005 %   - tyinfo = slgausstype(GS)
0006 %
0007 % $ Arguments $
0008 %   - GS:       the Gaussian model struct
0009 %   - tyinfo:   the type information structure with following fields
0010 %               - varform:  the form of variance: 'univar'|'diagvar'|'covar'
0011 %               - sharevar: whether the variance(covariance) is shared
0012 %               - hasinv:   whether is invvars or invcovs exists
0013 %               - hasmw:    whether the mixture weights exist
0014 %
0015 % $ Remarks $
0016 %   - The function will check the validity of the struct and will raise
0017 %     an error for invalid models. So it can be used to check validity
0018 %     even you don't need to know the type of the model.
0019 %
0020 % $ History $
0021 %   - Created by Dahua Lin, on Aug 23rd, 2006
0022 %
0023 
0024 
0025 %% verify basic fields
0026 
0027 if ~isstruct(GS)
0028     gs_argerror('The Gaussian model should be a struct');
0029 end
0030 
0031 if ~all(slisfields(GS, {'dim', 'nmodels', 'means'}))
0032     gs_argerror('The Gaussian model struct should have all of the fields: dim, nmodels and means');
0033 end
0034 
0035 d = GS.dim;
0036 k = GS.nmodels;
0037 
0038 if ~isequal(size(GS.means), [d k])
0039     gs_sizerror('The means field should be an array of size d x k');
0040 end
0041 
0042 %% verify variance/covariance field
0043 
0044 if isfield(GS, 'vars')
0045     sizvf = size(GS.vars);
0046     if isequal(sizvf, [1 1])
0047         varform = 'univar';
0048         sharevar = true;
0049     elseif isequal(sizvf, [1 k])
0050         varform = 'univar';
0051         sharevar = false;
0052     elseif isequal(sizvf, [d 1])
0053         varform = 'diagvar';
0054         sharevar = true;
0055     elseif isequal(sizvf, [d k])
0056         varform = 'diagvar';
0057         sharevar = false;
0058     else
0059         gs_arrerror('The size of vars is illegal');
0060     end
0061     
0062     hasinv = isfield(GS, 'invvars');    
0063     
0064 elseif isfield(GS, 'covs')
0065     
0066     sizcvf = size(GS.covs);
0067     if isequal(sizcvf, [d d])
0068         varform = 'covar';
0069         sharevar = true;
0070     elseif isequal(sizcvf, [d d k])
0071         varform = 'covar';
0072         sharevar = false;
0073     else
0074         gs_arrerror('The size of covariance is illegal');
0075     end
0076     
0077     hasinv = isfield(GS, 'invcovs'); 
0078     
0079 else
0080     gs_arrerror('The Gaussian struct lacks a field for variance/covariance');
0081 end
0082 
0083 
0084 hasmw = isfield(GS, 'mixweights');
0085 
0086 if nargout >= 1 
0087     tyinfo = struct(...
0088         'varform', varform, ...
0089         'sharevar', sharevar, ...
0090         'hasinv', hasinv, ...
0091         'hasmw', hasmw);
0092 end
0093 
0094 
0095 
0096 function gs_argerror(errmsg)
0097 
0098 error('sltoolbox:invalidarg', errmsg);
0099 
0100 function gs_sizerror(errmsg)
0101 
0102 error('sltoolbox:sizmismatch', errmsg);

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

Contact us at files@mathworks.com