  function TestDist()
% Checks out the function Dist

% Small example...
clc
rand('seed',0)
m = 3; n = 7; X = rand(m,n);
D = DistCVL(X)
D0 = Dist(X)

% Larger example
m = 10; n = 100; X = rand(m,n);
err = norm(DistCVL(X)-Dist(X))


  function D = DistCVL(X)
% X is an m-by-n matrix
% D is an n-by-n matrix with D(i,j) = exp(-norm((X(:,i)-X(:,j))^2))

% Note that 
%       exp(-norm(u-v)^2) = exp(-u'*u + 2u'v -v'*v) 
%                         = exp(-u'*u)*exp(2u'*v)*exp(-v'*v)
% so it follows that
%                  D(i,j) = exp(2*X(:,i)'*X(:j))/(d(i)*d(j))
% where 
%                    d(k) = 1/exp(X(:,k)'*X(:,k)).
 
Z = X'*X;
d = 1./exp(diag(Z));
D = exp(2*Z).*(d*d');

% -1 for each loop

