X1 = linspace(1,100,100);
X2 = linspace(100,199,100);
X3 = linspace(200,299,100);
Y = linspace(300,399,100);
X1 = (X1 - min(X1)) / (max(X1)-min(X1));
X2 = (X2 - min(X2)) / (max(X2)-min(X2));
X3 = (X3 - min(X3)) / (max(X3)-min(X3));
X_MAT = [X1;X2;X3];
X_Cell = con2seq(X_MAT,100);
Y_MAT = Y;
Y_Cell = con2seq(Y,100);
numFeatures = 3;
numResponses = 1;
numHiddenUnits = 400;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.5, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',1, ...
'Plots','training-progress');
net_Mat = trainNetwork(X_MAT,Y_MAT,layers,options);
net_Cell = trainNetwork(X_Cell,Y_Cell,layers,options);
for i = 1: 100
[net_Mat,YpredMat(:,i)] = predictAndUpdateState(net_Mat,X_MAT(:,i));
end
for i = 1: 100
[net_Cell,YpredCell(:,i)] = predictAndUpdateState(net_Cell,X_Cell(:,i));
end
CVRMSE_MAT = sqrt(abs(mean(YpredMat.^2-Y_MAT.^2)))/mean(Y_MAT) * 100;
YpredCell = cell2mat(YpredCell);
Y_Cell = cell2mat(Y_Cell);
CVRMSE_Cell = sqrt(abs(mean(YpredCell.^2-Y_Cell.^2)))/mean(Y_Cell) * 100;