% just a little question ....

% this is a 2
x(1,:)=[0 1 1 1 0];
x(2,:)=[1 0 0 0 1];
x(3,:)=[0 0 1 1 0];
x(4,:)=[0 1 0 0 0];
x(5,:)=[1 1 1 1 1];

% this is another 2
y(1,:)=[1 1 1 0 0];
y(2,:)=[0 0 0 1 0];
y(3,:)=[0 0 1 0 0];
y(4,:)=[0 1 0 0 0];
y(5,:)=[1 1 1 1 0];

% this is a 3
z(1,:)=[1 1 1 1 0];
z(2,:)=[0 0 0 1 0];
z(3,:)=[0 0 1 0 0];
z(4,:)=[0 0 0 1 0];
z(5,:)=[1 1 1 1 0];

% you can visualise these using e.g.

figure; imagesc(x); colormap('gray');
figure; imagesc(y); colormap('gray');
figure; imagesc(z); colormap('gray');

% QUESTION :
% By converting x y and z to a vector representation :

xv = reshape(x,prod(size(x)),1);
yv = reshape(y,prod(size(y)),1);
zv = reshape(z,prod(size(z)),1);
%
% calculate the distance between x and y 
dxy=sqrt(sum((xv-yv).^2));
% calculate the distance between y and z 
dyz=sqrt(sum((yv-zv).^2));
% calculate the distance between x and z 
dxz=sqrt(sum((xv-zv).^2));
% calculate the angle between x and y 
axy = acos(xv'*yv/(sqrt((xv'*xv)*(yv'*yv))));
% calculate the angle between y and z 
ayz = acos(yv'*zv/(sqrt((yv'*yv)*(zv'*zv))));
% calculate the angle between x and z 
axz = acos(xv'*zv/(sqrt((xv'*xv)*(zv'*zv))));



e = eye(5); rp = e(:,[5 1 4 3 2]);
xx = x*rp; yy = y*rp; zz = z*rp;

% QUESTION :
% Visualise (using three figures) the new data xx, and yy, and zz.
figure; imagesc(xx);colormap('gray')
figure; imagesc(yy);colormap('gray')
figure; imagesc(zz);colormap('gray')

%
% By converting xx yy and zz to a vector representation :
xxv = reshape(xx,prod(size(xx)),1);
yyv = reshape(yy,prod(size(yy)),1);
zzv = reshape(zz,prod(size(zz)),1);
% calculate the distance between xx and yy 
dxxyy=sqrt(sum((xxv-yyv).^2));
% calculate the distance between yy and zz 
dyyzz=sqrt(sum((yyv-zzv).^2));
% calculate the distance between xx and zz 
dxxzz=sqrt(sum((xxv-zzv).^2));
% calculate the angle between xx and yy 
axxyy = acos(xxv'*yyv/(sqrt((xxv'*xxv)*(yyv'*yyv))));
% calculate the angle between yy and zz 
ayyzz = acos(yyv'*zzv/(sqrt((yyv'*yyv)*(zzv'*zzv))));
% calculate the angle between xx and zz 
axxzz = acos(xxv'*zzv/(sqrt((xxv'*xxv)*(zzv'*zzv))));
% calculate the distance between xx and x
dxxx=sqrt(sum((xxv-xv).^2));
%
% Comment on your results.

% angles and distances between the new vectors are the same as the angles
% and distances between the old vectors.
% Since angles and distances only depend on summations of distances
% between two corresponding vector components, as long as we are
% consistent in converting the matrices into vectors, we will always get
% the same answer for the angle and distance between the matrices
% representation of the vectors.
%
% It is revealing the one can permute the components of the vectors and
% still get the same distances. This means that we could not make a good
% `generative' model of the data based solely on the euclidean
% distance. To make a good model, we need to prefer some directions in
% space over others -- that is, the data must be anisotropically
% distributed.











