%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Simple script to test hierarchical clustering with single linkage
% on a simple 2-cluster dataset
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load the data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
load twocluster.crd;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% perform hierarchical clustering with Euclidean distance and single linkage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
D = pdist(twocluster,'euclidean');
Z = linkage(D,'single');
C = cluster(Z,'maxclust',2);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot side-by-side original data and clustered data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
figure;
%
subplot(1,2,1);
plot(twocluster(1:100,1),twocluster(1:100,2),'or');
hold on;
plot(twocluster(101:200,1),twocluster(101:200,2),'ob');
title('Ground truth')
%
subplot(1,2,2);
hold on;
for i = 1:200
	if C(i) == 1
		plot(twocluster(i,1),twocluster(i,2),'og');
	else
		plot(twocluster(i,1),twocluster(i,2),'ok');
	end
end
title('Clustered data: HC with single linkage')
%
