Hi; Is it possible to predict EFFECTIVELY into the future using NAR neural network. I used Neural Networks to predict a simple line using multisteps (closed loop ), but it turns out that it is very good but only till the training part whereas it miserably fails in the multistep (predict ahead ) part. here is my code: Please help, where am I wrong ? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MULTISTEP PREDICTION USING NAR AND CLOSED LOOP NEURAL NETWORK
clc; clear all; close all;
% A simple line which I want to predict
DATA= (1:1000)';
%% Create a Nonlinear Autoregressive Network
feedbackDelays = 1:5;
hiddenLayerSize = 5;
net = narnet(feedbackDelays,hiddenLayerSize);
net.divideParam.trainRatio = 85/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 0/100; % NO TEST DATA as I only want to test the multistep part in future
net.divideFcn = 'dividerand'; % Divide data randomly
% TRAINING
N=500; % Number of bars used for training
TDATA = DATA(1:N); % Training Data
T = tonndata(TDATA,false,false);
[x,xi,ai,t] = preparets(net,{},{},T); % prepare data
[net,tr] = train(net,x,t,xi,ai); % Train the Network
y = net(x,xi,ai);
% MULTISPTEP PREDICTION – Closed Loop Network
MSDATA = DATA(N-feedbackDelays(end):end); % multistep predict ahead data
T = tonndata(MSDATA,false,false);
netc = closeloop(net);
[xc,xic,aic,tc] = preparets(netc,{},{},T);
yc = netc(xc,xic,aic);
%% PLot training and multistep predicted part
hold on;
plot(cell2mat(t)); % targets in training part
plot(cell2mat(y),'r'); % nn results in training part
plot([nan(1,length(t)'),cell2mat(tc)],'g'); % targets in multistep predicted part
plot([nan(1,length(y)'),cell2mat(yc)],'r'); % nn in multistep predicted part
Best Answer