gmm_entropy.m
来自「高斯滤波器 matlab toolbox For GMMs and Gauss」· M 代码 · 共 52 行
M
52 行
function p = gmm_entropy(g,N)
g = gmm_normalise(g);
if nargin == 2
p = gmm_entropy_montecarlo(g, N);
else
p = gmm_entropy_unscented(g);
end
%
%
function p = gmm_entropy_montecarlo(g, N)
% Monte Carlo approximation of entropy for Gaussian mixtures.
s = gmm_samples(g, N);
w = gmm_evaluate(g, s);
p = -mean(log(w(w~=0)));
%
%
function p = gmm_entropy_unscented(g)
% Unscented gmm entropy, based on Goldberger's KLD approximation
[D,N] = size(g.x);
Ds = sqrt(D);
p = 0;
for i=1:N
Ps = Ds * matrix_square_root(g.P(:,:,i), 1);
x = repvec(g.x(:,i), D);
s = [x+Ps, x-Ps]; % unscented samples for i-th component of g
w = gmm_evaluate(g, s);
p = p - g.w(i)*sum(log(w));
end
p = p/(2*D);
%
%
function R = matrix_square_root(P, type)
switch type
case 1 % svd decomposition, P = U*D*U' = R*R' (UDU form is also called modified Cholesky decomposition)
[U,D,V] = svd(P);
R = U*sqrt(D);
case 2 % cholesky decomposition (triangular), P = R*R'
R = chol(P)';
case 3 % principal square root (symmetric), P = R*R
R = sqrtm(P);
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?