gmm_to_gaussian.m

来自「高斯滤波器 matlab toolbox For GMMs and Gauss」· M 代码 · 共 35 行

M
35
字号
function [x,P,wn] = gmm_to_gaussian(g)
% Convert gmm to a single Gaussian (ie, compute first two moments of mixture). 

[g, wn] = gmm_normalise(g); % gmm must be normalised for weighted sums to be meaningful

[D,N] = size(g.x);
w = reprow(g.w, D);
x = sum(w.*g.x, 2);

P = zeros(D);
for i=1:N
    P = P + g.w(i) * g.P(:,:,i);
end
xerr = g.x - repcol(x, N);
P = P + w.*xerr*xerr'; 

return 


% TODO: implement faster version: ... 
[D,N] = size(g.x);

w = reprow(g.w, D);
x = sum(w.*g.x, 2);

xerr = g.x - repcol(x, N);
P = reshape(g.P, [N,D*D,1]);
Pw = sum(w.*P, 1);
Pw = reshape(Pw, [D,D]);
%Pw = reshape(sum(w.*reshape(g.P, [N,D*D,1]), 1), [D,D]); % reshape permits summing over P values
P = Pw + w.*xerr*xerr'; 

% g.P is DxDxN
% g.w is N
% w is DxN

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?