Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/collapse_mog.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function [new_mu, new_Sigma, new_Sigma2] = collapse_mog(mu, Sigma, coefs) |
matthiasm@8 | 2 % COLLAPSE_MOG Collapse a mixture of Gaussians to a single Gaussian by moment matching |
matthiasm@8 | 3 % [new_mu, new_Sigma] = collapse_mog(mu, Sigma, coefs) |
matthiasm@8 | 4 % |
matthiasm@8 | 5 % coefs(i) - weight of i'th mixture component |
matthiasm@8 | 6 % mu(:,i), Sigma(:,:,i) - params of i'th mixture component |
matthiasm@8 | 7 |
matthiasm@8 | 8 % S = sum_c w_c (S_c + m_c m_c' + m m' - 2 m_c m') |
matthiasm@8 | 9 % = sum_c w_c (S_c + m_c m_c') + m m' - 2 (sum_c m_c) m' |
matthiasm@8 | 10 % = sum_c w_c (S_c + m_c m_c') - m m' |
matthiasm@8 | 11 |
matthiasm@8 | 12 new_mu = sum(mu * diag(coefs), 2); % weighted sum of columns |
matthiasm@8 | 13 |
matthiasm@8 | 14 n = length(new_mu); |
matthiasm@8 | 15 new_Sigma = zeros(n,n); |
matthiasm@8 | 16 new_Sigma2 = zeros(n,n); |
matthiasm@8 | 17 for j=1:length(coefs) |
matthiasm@8 | 18 m = mu(:,j) - new_mu; |
matthiasm@8 | 19 new_Sigma = new_Sigma + coefs(j) * (Sigma(:,:,j) + m*m'); |
matthiasm@8 | 20 new_Sigma2 = new_Sigma2 + coefs(j) * (Sigma(:,:,j) + mu(:,j)*mu(:,j)'); |
matthiasm@8 | 21 end |
matthiasm@8 | 22 %assert(approxeq(new_Sigma, new_Sigma2 - new_mu*new_mu')) |