wolffd@0: function [mu, Sigma, weights] = mixgauss_init(M, data, cov_type, method) wolffd@0: % MIXGAUSS_INIT Initial parameter estimates for a mixture of Gaussians wolffd@0: % function [mu, Sigma, weights] = mixgauss_init(M, data, cov_type. method) wolffd@0: % wolffd@0: % INPUTS: wolffd@0: % data(:,t) is the t'th example wolffd@0: % M = num. mixture components wolffd@0: % cov_type = 'full', 'diag' or 'spherical' wolffd@0: % method = 'rnd' (choose centers randomly from data) or 'kmeans' (needs netlab) wolffd@0: % wolffd@0: % OUTPUTS: wolffd@0: % mu(:,k) wolffd@0: % Sigma(:,:,k) wolffd@0: % weights(k) wolffd@0: wolffd@0: if nargin < 4, method = 'kmeans'; end wolffd@0: wolffd@0: [d T] = size(data); wolffd@0: data = reshape(data, d, T); % in case it is data(:, t, sequence_num) wolffd@0: wolffd@0: switch method wolffd@0: case 'rnd', wolffd@0: C = cov(data'); wolffd@0: Sigma = repmat(diag(diag(C))*0.5, [1 1 M]); wolffd@0: % Initialize each mean to a random data point wolffd@0: indices = randperm(T); wolffd@0: mu = data(:,indices(1:M)); wolffd@0: weights = normalise(ones(M,1)); wolffd@0: case 'kmeans', wolffd@0: mix = gmm(d, M, cov_type); wolffd@0: options = foptions; wolffd@0: max_iter = 5; wolffd@0: options(1) = -1; % be quiet! wolffd@0: options(14) = max_iter; wolffd@0: mix = gmminit(mix, data', options); wolffd@0: mu = reshape(mix.centres', [d M]); wolffd@0: weights = mix.priors(:); wolffd@0: for m=1:M wolffd@0: switch cov_type wolffd@0: case 'diag', wolffd@0: Sigma(:,:,m) = diag(mix.covars(m,:)); wolffd@0: case 'full', wolffd@0: Sigma(:,:,m) = mix.covars(:,:,m); wolffd@0: case 'spherical', wolffd@0: Sigma(:,:,m) = mix.covars(m) * eye(d); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: