clear
close all
%------------------------------------------------
% GENEROVANI DAT
dim = 10; %Pocet dimenzi, tedy priznaku
numSamples = 2000; %Celkovy pocet vzorku

sigma1 = ones(numSamples*0.5,dim); %rozptyl je u vsech stejny
sigma2 = ones(numSamples*0.5,dim); 
mi1 = zeros(numSamples*0.5,dim);
mi2 = ones(numSamples*0.5,1)*[2 1 0.5 1 0 0 0 0 0 0]; %pouze u prvnich ctyrech priznaku je rozpoznatelny rozdil mezi tridami

green = (randn(numSamples*0.5,dim)+mi1).*sigma1; %vygenerovani tridy "zeleny"
blue = (randn(numSamples/2,dim)+mi2).*sigma2; %vygenerovani tridy "modry"
obs = [green; blue];
clear sigma1 sigma2 mi1 mi2 green blue

figure(1) %pohled na data, pouze prvni dva priznaky - dimenze
plot(obs(1:1000,1),obs(1:1000,2),'g.');
hold on
plot(obs(1001:2000,1),obs(1001:2000,2),'b.');
hold off

% oznaceni trid - labeling
for i = 1:numSamples
    if (i<=numSamples*0.5)
        class{i} = 'green';
    else
        class{i} = 'blue';
    end
end
%-------------------------------------------------
trainSize = round(numSamples*0.1); %Velikost trenovaci mnoziny
testSize = numSamples-trainSize; %Velikost testovaci mnoziny
numSteps = 500; %pocet kroku k opakovani
costs = nan(numSteps,20); %priprava tabulky pro ruzne misclassification costs

for step = 1:numSteps
    step %vypis kroku
    perm = randperm(numSamples); %nahodne zamichani vzorku
    trainInd = perm(1:trainSize);
    testInd = perm(trainSize+1:end);
    obsTrain = obs(trainInd,:); %rozdeleni vzorku na trenovaci a testovaci mnozinu
    obsTest = obs(testInd,:);

    classTrain = {};
    classTest = {};
    for ind = trainInd %rozdeleni trid na trenovaci a testovaci mnozinu
        classTrain{end+1} = class{ind};
    end
    for ind = testInd
        classTest{end+1} = class{ind};
    end

    %---------------------------------------
    %zde doplnte
    %1)vytvoreni stromu 
    %2)otestovani ruznych prorezani - zjisteni misclassification costs, 
    %3)zarazeni ruznych misclassification costs do tabulky costs

    %---------------------------------------
end
clear step perm trainInd testInd obsTrain obsTest classTrain classTest ind
figure(2)
t.view; %ukazka vytvoreneho stromu
figure(3)
%-----------------------------
%zde doplnte: vytvorte boxplot

