Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/KPMstats/mixgauss_init.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [mu, Sigma, weights] = mixgauss_init(M, data, cov_type, method) | |
2 % MIXGAUSS_INIT Initial parameter estimates for a mixture of Gaussians | |
3 % function [mu, Sigma, weights] = mixgauss_init(M, data, cov_type. method) | |
4 % | |
5 % INPUTS: | |
6 % data(:,t) is the t'th example | |
7 % M = num. mixture components | |
8 % cov_type = 'full', 'diag' or 'spherical' | |
9 % method = 'rnd' (choose centers randomly from data) or 'kmeans' (needs netlab) | |
10 % | |
11 % OUTPUTS: | |
12 % mu(:,k) | |
13 % Sigma(:,:,k) | |
14 % weights(k) | |
15 | |
16 if nargin < 4, method = 'kmeans'; end | |
17 | |
18 [d T] = size(data); | |
19 data = reshape(data, d, T); % in case it is data(:, t, sequence_num) | |
20 | |
21 switch method | |
22 case 'rnd', | |
23 C = cov(data'); | |
24 Sigma = repmat(diag(diag(C))*0.5, [1 1 M]); | |
25 % Initialize each mean to a random data point | |
26 indices = randperm(T); | |
27 mu = data(:,indices(1:M)); | |
28 weights = normalise(ones(M,1)); | |
29 case 'kmeans', | |
30 mix = gmm(d, M, cov_type); | |
31 options = foptions; | |
32 max_iter = 5; | |
33 options(1) = -1; % be quiet! | |
34 options(14) = max_iter; | |
35 mix = gmminit(mix, data', options); | |
36 mu = reshape(mix.centres', [d M]); | |
37 weights = mix.priors(:); | |
38 for m=1:M | |
39 switch cov_type | |
40 case 'diag', | |
41 Sigma(:,:,m) = diag(mix.covars(m,:)); | |
42 case 'full', | |
43 Sigma(:,:,m) = mix.covars(:,:,m); | |
44 case 'spherical', | |
45 Sigma(:,:,m) = mix.covars(m) * eye(d); | |
46 end | |
47 end | |
48 end | |
49 |