| Description of slgmm |
slgmm
PURPOSE 
SLGMM Learns Gaussian Mixture model from samples
SYNOPSIS 
function [GS, pp, info] = slgmm(X, varargin)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- slclassify_eucnn SLCLASSIFY_EUCNN Classifies samples using Euclidena-based NN
- slfmm SLFMM Learns a Finite Mixture Model (FMM)
- slgaussest SLGAUSSEST Estimates the Gaussian models from samples
- slgausspdf SLGAUSSPDF Computes the probability density of Gaussian models
- slgausstype SLGAUSSTYPE Judges the type of a Gaussian model struct
- slignorevars SLIGNOREVARS Ignores the input variables
- slparseprops SLPARSEPROPS Parses input parameters
This function is called by:
SUBFUNCTIONS 
- function GS = gmm_estfunc(GS, X, n, W, selinds, varform, sharevar, invparams)
- function condp = gmm_evalfunc(GS, X, n)
- function GS = gmm_manifunc(GS0, op, varargin)
SOURCE CODE 
0001 function [GS, pp, info] = slgmm(X, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 if ~isnumeric(X) || ndims(X) ~= 2
0060 error('sltoolbox:invalidarg', ...
0061 'X should be a 2D numeric matrix');
0062 end
0063
0064 opts.method = 'EM';
0065 opts.K = 3;
0066 opts.update = 'pass';
0067 opts.cyclecn = 1;
0068 opts.maxiter = 100;
0069 opts.tol = 1e-6;
0070 opts.verbose = true;
0071 opts.annthres = 0;
0072 opts.weights = [];
0073 opts.varform = 'covar';
0074 opts.sharevar = false;
0075 opts.invparams = {};
0076 opts = slparseprops(opts, varargin{:});
0077
0078 n = size(X, 2);
0079
0080
0081
0082
0083 if opts.K > n
0084 error('sltoolbox:sizoverflow', ...
0085 'The K is larger than the number of samples');
0086 end
0087
0088 init_centerinds = randsample(n, opts.K);
0089 init_centers = X(:, init_centerinds);
0090 initc = slclassify_eucnn(init_centers, X);
0091
0092
0093
0094 estfunctor = {@gmm_estfunc, opts.varform, opts.sharevar, opts.invparams};
0095 evalfunctor = {@gmm_evalfunc};
0096
0097 [GS, cw, pp, info] = slfmm(X, n, estfunctor, evalfunctor, ...
0098 'method', opts.method, ...
0099 'update', opts.update, ...
0100 'cyclecn', opts.cyclecn, ...
0101 'iter', {'maxiter', opts.maxiter}, ...
0102 'tol', opts.tol, ...
0103 'verbose', opts.verbose, ...
0104 'initc', initc, ...
0105 'annthres', opts.annthres, ...
0106 'weights', opts.weights, ...
0107 'estmode', 'innermul', ...
0108 'condpmode', 'log', ...
0109 'manifunc', @gmm_manifunc);
0110
0111
0112
0113 GS.mixweights = cw;
0114
0115
0116
0117
0118 function GS = gmm_estfunc(GS, X, n, W, selinds, varform, sharevar, invparams)
0119
0120 slignorevars(n);
0121
0122 if isempty(selinds)
0123 GS = slgaussest(X, 'weights', W, ...
0124 'varform', varform, 'sharevar', sharevar, ...
0125 'compinv', true, 'invparams', invparams);
0126 else
0127 if sharevar
0128 error('sltoolbox:rterror', ...
0129 'The selective updating scheme is only supported when sharevar is false');
0130 end
0131
0132 Wsel = W(selinds, :);
0133 GSu = slgaussest(X, 'weights', Wsel, ...
0134 'varform', varform, 'sharevar', sharevar, ...
0135 'compinv', true, 'invparams', invparams);
0136
0137 nu = length(selinds);
0138 switch varform
0139 case 'univar'
0140 for idx = 1 : nu
0141 iu = selinds(idx);
0142 GS.means(:, iu) = GSu.means(:,idx);
0143 GS.vars(iu) = GSu.vars(idx);
0144 GS.invvars(iu) = GSu.invvars(idx);
0145 end
0146 case 'diagvar'
0147 for idx = 1 : nu
0148 iu = selinds(idx);
0149 GS.means(:, iu) = GSu.means(:, idx);
0150 GS.vars(:, iu) = GSu.vars(:, idx);
0151 GS.invvars(:, iu) = GSu.invvars(:, idx);
0152 end
0153 case 'covar'
0154 for idx = 1 : nu
0155 iu = selinds(idx);
0156 GS.means(:, iu) = GSu.means(:, idx);
0157 GS.covs(:,:, iu) = GSu.covs(:,:, idx);
0158 GS.invcovs(:,:, iu) = GSu.invcovs(:,:, idx);
0159 end
0160 end
0161
0162 end
0163
0164 function condp = gmm_evalfunc(GS, X, n)
0165
0166 slignorevars(n);
0167 condp = slgausspdf(GS, X, 'output', 'log');
0168
0169
0170 function GS = gmm_manifunc(GS0, op, varargin)
0171
0172 switch op
0173 case 'select'
0174
0175 selinds = varargin{1};
0176
0177 tyi = slgausstype(GS0);
0178
0179 GS.dim = GS0.dim;
0180 GS.nmodels = length(selinds);
0181 GS.means = GS0.means(:, selinds);
0182
0183 switch tyi.varform
0184 case {'univar', 'diagvar'}
0185 if tyi.sharevar
0186 GS.vars = GS0.vars;
0187 GS.invvars = GS0.invvars;
0188 else
0189 GS.vars = GS0.vars(:, selinds);
0190 GS.invvars = GS0.invvars(:, selinds);
0191 end
0192 case 'covar'
0193 if tyi.sharevar
0194 GS.covs = GS0.covs;
0195 GS.invcovs = GS0.invcovs;
0196 else
0197 GS.covs = GS0.covs(:,:,selinds);
0198 GS.invcovs = GS0.invcovs(:,:,selinds);
0199 end
0200 end
0201
0202
0203 otherwise
0204 error('sltoolbox:invalidarg', ...
0205 'Unsupported manipulation option for GMM: %s', op);
0206 end
0207
0208
0209
0210
0211
0212
0213
Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003
|
|