wolffd@0: function mix = gmmunpak(mix, p) wolffd@0: %GMMUNPAK Separates a vector of Gaussian mixture model parameters into its components. wolffd@0: % wolffd@0: % Description wolffd@0: % MIX = GMMUNPAK(MIX, P) takes a GMM data structure MIX and a single wolffd@0: % row vector of parameters P and returns a mixture data structure wolffd@0: % identical to the input MIX, except that the mixing coefficients wolffd@0: % PRIORS, centres CENTRES and covariances COVARS (and, for PPCA, the wolffd@0: % lambdas and U (PCA sub-spaces)) are all set to the corresponding wolffd@0: % elements of P. wolffd@0: % wolffd@0: % See also wolffd@0: % GMM, GMMPAK wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: errstring = consist(mix, 'gmm'); wolffd@0: if ~errstring wolffd@0: error(errstring); wolffd@0: end wolffd@0: if mix.nwts ~= length(p) wolffd@0: error('Invalid weight vector length') wolffd@0: end wolffd@0: wolffd@0: mark1 = mix.ncentres; wolffd@0: mark2 = mark1 + mix.ncentres*mix.nin; wolffd@0: wolffd@0: mix.priors = reshape(p(1:mark1), 1, mix.ncentres); wolffd@0: mix.centres = reshape(p(mark1 + 1:mark2), mix.ncentres, mix.nin); wolffd@0: switch mix.covar_type wolffd@0: case 'spherical' wolffd@0: mark3 = mix.ncentres*(2 + mix.nin); wolffd@0: mix.covars = reshape(p(mark2 + 1:mark3), 1, mix.ncentres); wolffd@0: case 'diag' wolffd@0: mark3 = mix.ncentres*(1 + mix.nin + mix.nin); wolffd@0: mix.covars = reshape(p(mark2 + 1:mark3), mix.ncentres, mix.nin); wolffd@0: case 'full' wolffd@0: mark3 = mix.ncentres*(1 + mix.nin + mix.nin*mix.nin); wolffd@0: mix.covars = reshape(p(mark2 + 1:mark3), mix.nin, mix.nin, ... wolffd@0: mix.ncentres); wolffd@0: case 'ppca' wolffd@0: mark3 = mix.ncentres*(2 + mix.nin); wolffd@0: mix.covars = reshape(p(mark2 + 1:mark3), 1, mix.ncentres); wolffd@0: % Now also extract k and eigenspaces wolffd@0: mark4 = mark3 + mix.ncentres*mix.ppca_dim; wolffd@0: mix.lambda = reshape(p(mark3 + 1:mark4), mix.ncentres, ... wolffd@0: mix.ppca_dim); wolffd@0: mix.U = reshape(p(mark4 + 1:end), mix.nin, mix.ppca_dim, ... wolffd@0: mix.ncentres); wolffd@0: otherwise wolffd@0: error(['Unknown covariance type ', mix.covar_type]); wolffd@0: end wolffd@0: