comparison toolboxes/FullBNT-1.0.7/KPMtools/collapse_mog.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 [new_mu, new_Sigma, new_Sigma2] = collapse_mog(mu, Sigma, coefs)
2 % COLLAPSE_MOG Collapse a mixture of Gaussians to a single Gaussian by moment matching
3 % [new_mu, new_Sigma] = collapse_mog(mu, Sigma, coefs)
4 %
5 % coefs(i) - weight of i'th mixture component
6 % mu(:,i), Sigma(:,:,i) - params of i'th mixture component
7
8 % S = sum_c w_c (S_c + m_c m_c' + m m' - 2 m_c m')
9 % = sum_c w_c (S_c + m_c m_c') + m m' - 2 (sum_c m_c) m'
10 % = sum_c w_c (S_c + m_c m_c') - m m'
11
12 new_mu = sum(mu * diag(coefs), 2); % weighted sum of columns
13
14 n = length(new_mu);
15 new_Sigma = zeros(n,n);
16 new_Sigma2 = zeros(n,n);
17 for j=1:length(coefs)
18 m = mu(:,j) - new_mu;
19 new_Sigma = new_Sigma + coefs(j) * (Sigma(:,:,j) + m*m');
20 new_Sigma2 = new_Sigma2 + coefs(j) * (Sigma(:,:,j) + mu(:,j)*mu(:,j)');
21 end
22 %assert(approxeq(new_Sigma, new_Sigma2 - new_mu*new_mu'))