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

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