diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/KPMstats/mixgauss_init.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/KPMstats/mixgauss_init.m')
| -rw-r--r-- | sourcecodes/bnt-master/KPMstats/mixgauss_init.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMstats/mixgauss_init.m b/sourcecodes/bnt-master/KPMstats/mixgauss_init.m new file mode 100644 index 00000000..5a4596e1 --- /dev/null +++ b/sourcecodes/bnt-master/KPMstats/mixgauss_init.m @@ -0,0 +1,49 @@ +function [mu, Sigma, weights] = mixgauss_init(M, data, cov_type, method) +% MIXGAUSS_INIT Initial parameter estimates for a mixture of Gaussians +% function [mu, Sigma, weights] = mixgauss_init(M, data, cov_type. method) +% +% INPUTS: +% data(:,t) is the t'th example +% M = num. mixture components +% cov_type = 'full', 'diag' or 'spherical' +% method = 'rnd' (choose centers randomly from data) or 'kmeans' (needs netlab) +% +% OUTPUTS: +% mu(:,k) +% Sigma(:,:,k) +% weights(k) + +if nargin < 4, method = 'kmeans'; end + +[d T] = size(data); +data = reshape(data, d, T); % in case it is data(:, t, sequence_num) + +switch method + case 'rnd', + C = cov(data'); + Sigma = repmat(diag(diag(C))*0.5, [1 1 M]); + % Initialize each mean to a random data point + indices = randperm(T); + mu = data(:,indices(1:M)); + weights = normalise(ones(M,1)); + case 'kmeans', + mix = gmm(d, M, cov_type); + options = foptions; + max_iter = 5; + options(1) = -1; % be quiet! + options(14) = max_iter; + mix = gmminit(mix, data', options); + mu = reshape(mix.centres', [d M]); + weights = mix.priors(:); + for m=1:M + switch cov_type + case 'diag', + Sigma(:,:,m) = diag(mix.covars(m,:)); + case 'full', + Sigma(:,:,m) = mix.covars(:,:,m); + case 'spherical', + Sigma(:,:,m) = mix.covars(m) * eye(d); + end + end +end + |
