www.gusucode.com > 用粒子滤波算法进行跟踪的matlab代码 > gmm_utilities/gmm_entropy.m

    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