function dist = ClusterDistance(R1,R2,pi1,pi2)

% Compute covariance and prior probability of merged cluster
R3 = R1+R2;
pi3 = pi1+pi2;

[U1,S1,V1] = svd(R1);
[U2,S2,V2] = svd(R2);
[U3,S3,V3] = svd(R3);

% Compute distance formula
% The initial log likelihood is given by:
%   initialLL = -0.5*(const - (S1(1)+S2(1)));
% where const is the total variance of the cluster i.e. trace(R1+R2).
% The final log likelihood after merging is:
%   finalLL = -0.5*(const - S3(1));
% where const is trace(R3) = trace(R1+R2).
% So the value of initialLL-finilLL
% 
% This change will generally be negative, since the fit is generally
% reduced by reducing the number of clusters. However, in special
% cases, it may be positive.

dist = 0.5*( (S1(1)+S2(1)) - S3(1) );





