%close all; clear;
d = 3;
k = 4;
n = 5000;
%% Generate data 
[X,label] = kmeansRnd(d,k,n);
whos

figure(1); clf;
plotClass(X,label); title('data and labels')

%% kmeans init with kmeans++ seeding (recomended)
y = kmeans(X,kseeds(X,k));
figure(2); clf;
plotClass(X,y); title('kmeans with kseeds')

%% kmeans with random initialization 
y = kmeans(X,k);
figure(3); clf;
plotClass(X,y); title('kmeans random seeds')

%% kmeans init with labels
y = kmeans(X,label);
figure(4); clf;
plotClass(X,y); title('kmeans with seeds=labels')

%% kmeans init with centers 
mu = rand(d,k);
y = kmeans(X,mu);
figure(5); clf;
plotClass(X,y); title('kmeans with random centers')

%% kmeans++ seeding 
mu = kseeds(X,k);
[~,y] = min(dot(mu,mu,1)'/2-mu'*X,[],1); % assign sample labels
figure(6); clf;
plotClass(X,y); title('kmeans++ seeds')
