NARX type NN - Multi Step Ahead Prediction issue

1 view (last 30 days)
I've created a NARX Neural Network so as to forecast next 24h consumption profile.
The inputs that I use are:
  • Hourly temperature of the last 7 days (e.g from January 14 to 21)
  • Hourly consumption of the previous week (e.g January 7 to 13)
The target will be:
  • Last 7 days hourly measued consumption (e.g from January 14 to 21)
In this way, the prediction of the consumption profile will be done for January 22 (1x24 dimmension array)
After making the trainig in OP, I have closed the loop and train it again in order to improve the performarnce of NN.
Everything works well until this step.
My problems come when trying to make the Multi-step ahead prediction.
I have read several answers of similar doubts and try to implement the code that is proposed addapting it to my study case. However, I still have doubts with the prediction part. I understand that I need to prepare the CL net again with the new input (predicted temperature of the day that the prediction wants to be done, January 22), but not with the target, because in the prediction part we do not ave the measured values.
I add all the code. I think that you will find the the problematic part at the end, in %Multi-step ahead prediction.
The problem is that even if I'm able to obtain the output vecto "ycp", it only contain NaN and I cannot guess why.
clear all
% load All data;
load Inputs;
Target = targetn;
D = [previousCn temperaturen];
pIG = [predCn predTn];
IG = [con2seq(D') con2seq(pIG')]; %Inputs
TG = [con2seq(Target') cell(1,24,1)]; %Target
N = 24; %Nº of steps that we want to predict
inputSeries = IG(1:end-N);
targetSeries = TG(1:end-N);
%%NN design
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
net.dividefcn = 'divideblock';
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
perf = perform(net,targets,outputs)
%%Close-loop
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
[xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
[netc,trc,xfc,afc] = train(netc,xc,tc,xic,aic);
yc = netc(xc,xic,aic);
perfc = perform(netc,tc,yc)
%Multi-step ahead prediction
[xcp,xicp,aicp] = preparets(netc,IG(end-N+1:end),{}); % pInputSeries = IG(end-N+1:end);
ycp = netc(IG(end-N+1:end),xicp,aicp);
%Plotting
figure, plot(cell2mat(yc))
hold on
plot(cell2mat(outputs))
targetn(3:end); %Solution to the signal shifting. Was a display problem.
plot(targetn)
I hope I have made it clear.
Thank you very much.
Irati

Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!