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/KPMtools/collapse_mog.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/KPMtools/collapse_mog.m')
| -rw-r--r-- | sourcecodes/bnt-master/KPMtools/collapse_mog.m | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/collapse_mog.m b/sourcecodes/bnt-master/KPMtools/collapse_mog.m new file mode 100644 index 00000000..2fe6436f --- /dev/null +++ b/sourcecodes/bnt-master/KPMtools/collapse_mog.m @@ -0,0 +1,22 @@ +function [new_mu, new_Sigma, new_Sigma2] = collapse_mog(mu, Sigma, coefs) +% COLLAPSE_MOG Collapse a mixture of Gaussians to a single Gaussian by moment matching +% [new_mu, new_Sigma] = collapse_mog(mu, Sigma, coefs) +% +% coefs(i) - weight of i'th mixture component +% mu(:,i), Sigma(:,:,i) - params of i'th mixture component + +% S = sum_c w_c (S_c + m_c m_c' + m m' - 2 m_c m') +% = sum_c w_c (S_c + m_c m_c') + m m' - 2 (sum_c m_c) m' +% = sum_c w_c (S_c + m_c m_c') - m m' + +new_mu = sum(mu * diag(coefs), 2); % weighted sum of columns + +n = length(new_mu); +new_Sigma = zeros(n,n); +new_Sigma2 = zeros(n,n); +for j=1:length(coefs) + m = mu(:,j) - new_mu; + new_Sigma = new_Sigma + coefs(j) * (Sigma(:,:,j) + m*m'); + new_Sigma2 = new_Sigma2 + coefs(j) * (Sigma(:,:,j) + mu(:,j)*mu(:,j)'); +end +%assert(approxeq(new_Sigma, new_Sigma2 - new_mu*new_mu')) |
