% This script tests the Matlab XMeans MEX file. Make sure to first
% compile the xmeans.c file using the supplied Makefile. Simply type
% 'make' at the command line to generate the needed MEX file. If the
% compilation does not work, you might need to edit the Makefile to
% suite your specific development environment.
%

X1=load('5class.ds');
X2=load('11class.ds');
X3=load('5class1000.ds');

disp(' ');
disp('X-Means Matlab Wrapper Test Program');
disp(' ');
disp('Datasets    1 : 5class.ds');
disp('            2 : 11class.ds');
disp('            3 : 1 & 2 combined');
disp('            4 : 5class1000.ds');
disp('            5 : 2 & 4 combined');
disp(' ');
ds=input('Pick one : ');

switch ds
 case 1
  X=X1';
 case 2
  X=X2';
 case 3
  X=[X1' X2'];
 case 4
  X=X3';
 case 5
  X=[X2' X3'];
 otherwise
  error('You have to either pick 1, 2 or 3!');
end


figure(1);
p1=plot(X(1,:),X(2,:),'.');
hold on;
xlabel('x1');
ylabel('x2');
title('X-Means Clustering of Data');
drawnow

[C, N, BIC] = xmeans(X, 3, 40, 0.05, 0.5, 300, 12, 40);

p2=plot(C(1,:),C(2,:),'ro','linewidth',3);
hold off;
legend([p1 p2],'data','centers',0);

weights = N/sum(N);

k=length(N);

disp(' ');
disp(['X-Means : Number of final clusters = ' num2str(k)]);
disp(' ');
for j=1:k,
  disp(['  Center ' num2str(j) ' : [' num2str(C(:,j)') ']    Weight = ' num2str(weights(j))]);
end
disp(' ');
disp(['Final BIC score = ' num2str(BIC)]);
disp(' ');

