% Load syn data
close all;
clear;
k = 3;
load data;

data = Xe(1:3, :, 1);
num = size(data, 2);

figure
% scatter3(data(1,1:k*100), data(2,1:k*100), data(3,1:k*100), 'filled'), view(-60,60);
scatter3(data(1,1:num), data(2,1:num), data(3,1:num), 'filled'), view(-60,60);
%%
r =  1;
dmp = datamap(data, r);

%%
iter = 1;
err = zeros(3, iter);
for i = 1:iter
    [lamkm, Ikm, errorkm] = mykmeans(data', k, dmp);
    err(1,i) = min(errorkm);
%     for j = 1:k
%         figure
%         scatter3(data(1,Ikm==i), data(2,Ikm==i), data(3,Ikm==i), 'filled');
%     end

    [lamkio, Ikio, errorkio] = isodata(data', k, dmp);
    err(2,i) = min(errorkio);
%     for j = 1:k
%         figure
%         scatter3(data(1,Ikio==i), data(2,Ikio==i), data(3,Ikio==i), 'filled'), view(-60,60);
%     end

    [lamda, Ida, errorda] = kda(data', k, dmp);
    err(3,i) = min(errorda);
%     for i = 1:k
%         figure
%         scatter3(data(1,Ida==i), data(2,Ida==i), data(3,Ida==i), 'filled'), view(-60,60);
%     end
end
%%

figure

scatter3(data(1,Ikm == 1)', data(2,Ikm == 1)', data(3,Ikm == 1)',  'r', 'filled'), view(-60,60);
hold on;
scatter3(data(1,Ikm == 2)', data(2,Ikm == 2)', data(3,Ikm == 2)',  'b', 'filled'), view(-60,60);
hold on;
scatter3(data(1,Ikm == 3)', data(2,Ikm == 3)', data(3,Ikm == 3)',  'g', 'filled'), view(-60,60);
hold on;
%     
figure

scatter3(data(1,Ikio == 1)', data(2,Ikio == 1)', data(3,Ikio == 1)',  'r', 'filled'), view(-60,60);
hold on;
scatter3(data(1,Ikio == 2)', data(2,Ikio == 2)', data(3,Ikio == 2)',  'b', 'filled'), view(-60,60);
hold on;
scatter3(data(1,Ikio == 3)', data(2,Ikio == 3)', data(3,Ikio == 3)',  'g', 'filled'), view(-60,60);
hold on;

figure

scatter3(data(1,Ida == 1)', data(2,Ida == 1)', data(3,Ida == 1)',  'r', 'filled'), view(-60,60);
hold on;
scatter3(data(1,Ida == 2)', data(2,Ida == 2)', data(3,Ida == 2)',  'b', 'filled'), view(-60,60);
hold on;
scatter3(data(1,Ida == 3)', data(2,Ida == 3)', data(3,Ida == 3)',  'g', 'filled'), view(-60,60);
hold on;
