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

    function [gr, alpha] = gmm_covariance_intersect(g1, g2, alpha)
% Conservative approx: Generalised covariance intersect
% TODO: confirm this algorithms correctness. Does it make sense???
% Is there a measure of compactness that we can use to quantify how
% conservative this is? say, entropy?
% 

if nargin == 3
    gr = gmm_covariance_intersect_alpha(g1, g2, alpha);
else
    alpha = fminbnd(@optimise_alpha, 0, 1, [], g1,g2);
    gr = gmm_covariance_intersect_alpha(g1, g2, alpha);
end

%
%

function gr = gmm_covariance_intersect_alpha(g1, g2, alpha)

D = size(g1.x, 1);
M = size(g1.x, 2);
N = size(g2.x, 2);
R = M*N;

gr.w = zeros(1, R);
gr.x = zeros(D, R);
gr.P = zeros(D, D, R);

k = 1;
for i=1:M
    for j=1:N
        [gr.x(:,k), gr.P(:,:,k), w] = covariance_intersect_weight(g1.x(:,i),g1.P(:,:,i), g2.x(:,j),g2.P(:,:,j), alpha);
        gr.w(k) = g1.w(i) * g2.w(j) * w;
        
        k = k+1;
    end
end

%
%

function [x,P,w] = covariance_intersect_weight(x1,P1, x2,P2, alpha)
[x,P] = covariance_intersect(x1,P1, x2,P2, alpha);
w = weight_update(x1,P1, x2,P2, alpha);
        
%
%

function w = weight_update(x1,P1, x2,P2, a)
if a==0 | a==1, w = eps; return, end
v = x1-x2;
S = P1/a + P2/(1-a);
%S = P1 + P2;
w = gauss_evaluate(v, S);

%
%

function w = optimise_alpha(alpha, g1,g2)
% Optimise alpha according to various measures. I am not yet sure which is
% the "right" one. For now, entropy and normalised determinant seem most promising.
gr = gmm_covariance_intersect_alpha(g1, g2, alpha);
gr = gmm_normalise(gr);
switch 1
    case 1 % Unscented entropy approximation
        w = gmm_entropy(gr);
    case 2 % Monte Carlo entropy approximation
        w = gmm_entropy(gr, 100000);
    case 3 % Sum of weighted determinants
        w = 0;
        for i=1:length(gr.w)
            w = w + det(gr.P(:,:,i))*gr.w(i);
        end
    case 4 % Sum of normalised determinants
        w = 0;
        for i=1:length(gr.w)
            w = w + det(gr.P(:,:,i))/gr.w(i);
        end
    otherwise
        error('Invalid switch selection')
end