%%
%  load dataset
%
%rng('default') 
rng(5);
warning('off');
plt_cnt = 4;            % Number of spectra to plot

[ds, cnt, dist] = load_dataset('Prostrate');
perm = randperm(cnt, plt_cnt);

close all;
figure();

j = 1;
for i = 1:plt_cnt
    [s, l] = read_spectrum(ds, perm(i));
    subplot(plt_cnt, 2, j);
    plot_spectrum(s, l);
    j = j + 1;

    subplot(plt_cnt, 2, j);
    plot_spectrum(s, l);
    j = j + 1;
    xlim([7000 11000]);
end

% read all data and labels
data = cell(size(ds.Files));
labels = categorical(ds.Labels);
for i = 1:cnt
    [s, l] = read_spectrum(ds, i);
    data{i,1} = s.Intensity;
end

   
obs = cnt;
[idxTrn,idxVal,idxTst] = trainingPartitions(obs,[0.8 0.1 0.1]);
XTrain = data(idxTrn);
TTrain = labels(idxTrn);

XVal = data(idxVal);
TVal = labels(idxVal);

XTst = data(idxTst);
TTst = labels(idxTst);

[YTest,net] = conv_net_1d(XTrain, TTrain, XVal, TVal, XTst);

acc = mean(YTest == TTst)
figure()
confusionchart(TTst,YTest)
deepNetworkDesigner(net)
