comparison toolboxes/FullBNT-1.0.7/KPMstats/mixgauss_sample.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 [data, indices] = mixgauss_sample(mu, Sigma, mixweights, Nsamples)
2 % mixgauss_sample Sample data from a mixture of Gaussians
3 % function [data, indices] = mixgauss_sample(mu, Sigma, mixweights, Nsamples)
4 %
5 % Model is P(X) = sum_k mixweights(k) N(X; mu(:,k), Sigma(:,:,k)) or Sigma(k) for scalar
6 % data(:,i) is the i'th sample from P(X)
7 % indices(i) is the component from which sample i was drawn
8
9 [D K] = size(mu);
10 data = zeros(D, Nsamples);
11 indices = sample_discrete(mixweights, 1, Nsamples);
12 for k=1:K
13 if ndims(Sigma) < 3
14 sig = Sigma(k);
15 else
16 sig = Sigma(:,:,k);
17 end
18 ndx = find(indices==k);
19 if length(ndx) > 0
20 data(:,ndx) = sample_gaussian(mu(:,k), sig, length(ndx))';
21 end
22 end