annotate toolboxes/FullBNT-1.0.7/netlab3.3/gmmunpak.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function mix = gmmunpak(mix, p)
wolffd@0 2 %GMMUNPAK Separates a vector of Gaussian mixture model parameters into its components.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % MIX = GMMUNPAK(MIX, P) takes a GMM data structure MIX and a single
wolffd@0 6 % row vector of parameters P and returns a mixture data structure
wolffd@0 7 % identical to the input MIX, except that the mixing coefficients
wolffd@0 8 % PRIORS, centres CENTRES and covariances COVARS (and, for PPCA, the
wolffd@0 9 % lambdas and U (PCA sub-spaces)) are all set to the corresponding
wolffd@0 10 % elements of P.
wolffd@0 11 %
wolffd@0 12 % See also
wolffd@0 13 % GMM, GMMPAK
wolffd@0 14 %
wolffd@0 15
wolffd@0 16 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 17
wolffd@0 18 errstring = consist(mix, 'gmm');
wolffd@0 19 if ~errstring
wolffd@0 20 error(errstring);
wolffd@0 21 end
wolffd@0 22 if mix.nwts ~= length(p)
wolffd@0 23 error('Invalid weight vector length')
wolffd@0 24 end
wolffd@0 25
wolffd@0 26 mark1 = mix.ncentres;
wolffd@0 27 mark2 = mark1 + mix.ncentres*mix.nin;
wolffd@0 28
wolffd@0 29 mix.priors = reshape(p(1:mark1), 1, mix.ncentres);
wolffd@0 30 mix.centres = reshape(p(mark1 + 1:mark2), mix.ncentres, mix.nin);
wolffd@0 31 switch mix.covar_type
wolffd@0 32 case 'spherical'
wolffd@0 33 mark3 = mix.ncentres*(2 + mix.nin);
wolffd@0 34 mix.covars = reshape(p(mark2 + 1:mark3), 1, mix.ncentres);
wolffd@0 35 case 'diag'
wolffd@0 36 mark3 = mix.ncentres*(1 + mix.nin + mix.nin);
wolffd@0 37 mix.covars = reshape(p(mark2 + 1:mark3), mix.ncentres, mix.nin);
wolffd@0 38 case 'full'
wolffd@0 39 mark3 = mix.ncentres*(1 + mix.nin + mix.nin*mix.nin);
wolffd@0 40 mix.covars = reshape(p(mark2 + 1:mark3), mix.nin, mix.nin, ...
wolffd@0 41 mix.ncentres);
wolffd@0 42 case 'ppca'
wolffd@0 43 mark3 = mix.ncentres*(2 + mix.nin);
wolffd@0 44 mix.covars = reshape(p(mark2 + 1:mark3), 1, mix.ncentres);
wolffd@0 45 % Now also extract k and eigenspaces
wolffd@0 46 mark4 = mark3 + mix.ncentres*mix.ppca_dim;
wolffd@0 47 mix.lambda = reshape(p(mark3 + 1:mark4), mix.ncentres, ...
wolffd@0 48 mix.ppca_dim);
wolffd@0 49 mix.U = reshape(p(mark4 + 1:end), mix.nin, mix.ppca_dim, ...
wolffd@0 50 mix.ncentres);
wolffd@0 51 otherwise
wolffd@0 52 error(['Unknown covariance type ', mix.covar_type]);
wolffd@0 53 end
wolffd@0 54