%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Simple script to test hierarchical clustering with complete linkage
% on the Mouse dataset
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load the data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
load mouse.crd;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% perform hierarchical clustering with Euclidean distance and complete linkage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
D = pdist(mouse,'euclidean');
Z = linkage(D,'complete');
C = cluster(Z,'maxclust',3);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot side-by-side original data and clustered data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
figure;
%
subplot(1,2,1);
plot(mouse(1:290,1),mouse(1:290,2),'or');
hold on;
plot(mouse(291:390,1),mouse(291:390,2),'ob');
plot(mouse(391:490,1),mouse(391:490,2),'og');
title('Ground truth')
%
subplot(1,2,2);
hold on;
for i = 1:490
	if C(i) == 1
		plot(mouse(i,1),mouse(i,2),'or');
	elseif C(i) == 2
		plot(mouse(i,1),mouse(i,2),'ob');
	elseif C(i) == 3
		plot(mouse(i,1),mouse(i,2),'og');
	end
end
title('Clustered data: HC with single linkage')
%
