clc; clear

%B2:B79 pondìli; B80:B157 úterý, B158:B235 støeda, B236:B313 ètvrtek,
%B470:B547 pátek; B392:B469 sobota;B470:B547 nedìle
dDejvicka1 = readtable('dDejvicka.xls', 'Sheet', '1005', 'ReadVariableNames', false, 'Range', 'B2:B79'); 
dDejvicka2 = readtable('dDejvicka.xls', 'Sheet', '1705', 'ReadVariableNames', false, 'Range', 'B2:B79');
dDejvicka3 = readtable('dDejvicka.xls', 'Sheet', '2405', 'ReadVariableNames', false, 'Range', 'B2:B79');
dDejvicka4 = readtable('dDejvicka.xls', 'Sheet', '3105', 'ReadVariableNames', false, 'Range', 'B2:B79');
dDejvicka5 = readtable('dDejvicka.xls', 'Sheet', '0706', 'ReadVariableNames', false, 'Range', 'B2:B79');
dDejvicka6 = readtable('dDejvicka.xls', 'Sheet', '1406', 'ReadVariableNames', false, 'Range', 'B2:B79');
dDejvicka7 = readtable('dDejvicka.xls', 'Sheet', '2106', 'ReadVariableNames', false, 'Range', 'B2:B79');
dDejvicka = [dDejvicka1; dDejvicka2; dDejvicka3; dDejvicka4; dDejvicka5; dDejvicka6; dDejvicka7];
dDejvicka = table2array(dDejvicka);
int = readtable('dDejvicka.xls', 'Sheet', '1005', 'ReadVariableNames', false, 'Range', 'a2:a79');
int = [int;int;int;int;int;int;int];
int = table2array(int);
Data = [dDejvicka]; %sem zpozdeni
Prediktory = [int];
XTrain = Prediktory';
YTrain = Data';


numFeatures = 1;
numResponses = 1;
numHiddenUnits = 100;
size = 64;
layers = [ ...
    sequenceInputLayer(numFeatures)
    lstmLayer(numHiddenUnits, 'OutputMode','sequence')
    fullyConnectedLayer(numResponses)
    regressionLayer];
options = trainingOptions('adam', ...
    'MaxEpochs',250, ...
    'GradientThreshold',1, ...
    'InitialLearnRate',0.005, ...
    'Shuffle','once', ...
    'LearnRateSchedule','piecewise', ...
    'LearnRateDropPeriod',125, ...
    'MiniBatchSize',size, ...
    'LearnRateDropFactor',0.2, ...
    'Verbose',0, ...
    'Plots','training-progress');

net = trainNetwork(XTrain,YTrain,layers,options);
Vstup=int(1:78);

for j = 1:78
    C(j,:) = predict(net,Vstup(j,:)','ExecutionEnvironment','cpu');
end

writematrix(C,'Historicky_model.xlsx', 'Sheet', 'NN','Range', 'B2');
