%load simplecluster_dataset.MAT
load simplecluster_dataset
%inputs=simpleclusterInputs;
x = simplecluster_dataset;
net=selforgmap([4,4]);
%[net,tr]=train(net,inputs);
[net,tr]=train(net,x);
%outputs=net(inputs);
outputs=net(x);
SeedC=net.IW(1);
temp=SeedC(1);
w=cell2mat(temp);
%x=inputs';
E=evalclusters(x','kmeans','DaviesBouldin','klist',[2:6]);
plot(E)
clusters=4;
[idx,C]=kmeans(x',clusters);
meandist=0;
for i=1:clusters
    for k=1:16
        dist(k)=(C(i,1) -w(k,1))^2+(C(i,2)-w(k,2))^2;
    end
    kmin=1;
    mindist=dist(1);
    for k=2:16
        if dist(k)<mindist
            kmin=k;
            mindist=dist(k);
        end
    end
    disp([i,kmin,mindist])
    meandist=meandist+mindist;
end
meandist=meandist/clusters;
disp(meandist)