# NAR - How can I make a prediction more spaced?

1 view (last 30 days)
andre con on 20 Jun 2021
Hello,
I am using TDNN (NAR - Nonlinear Autoregressive). An simple example is presented below.
I am using 25 hidden neurons and the number of delays is equals to 8. The NN is working quite well to forecast y(t). However, I would like to forecast y(t+12) and y(t+24).
Is it possible to choose the time step that I intend to forecast in this present formulation?
Regards
clc; clear all;close all
% input
t2 = linspace(0,20*pi,500);
y = sin(t2) + sin(0.25*t2);
% convert
T = tonndata(y,true,false);
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network
feedbackDelays = 1:8;
hiddenLayerSize = 25;
net = narnet(feedbackDelays,hiddenLayerSize,'open',trainFcn);
% numbers of delays, with open loop or closed loop feedback modes.
[x,xi,ai,t] = preparets(net,{},{},T);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y);
% Forecast Data
THAT = linspace(20*pi,100*pi,2500);
YHAT = sin(THAT) + sin(0.25*THAT);
% coverter double - cell
YHAT = con2seq(YHAT);
% Forecast
YHAT = net(YHAT,xi,ai);
% converter cell - double (plotar)
YHAT = cell2mat(YHAT);
figure
THAT = linspace(20*pi,100*pi,2500);
yhat = sin(THAT)+ sin(0.25*THAT);
hold on
plot(THAT,YHAT,'--o')
%plot(THAT,yhat,':r');
% %
yz = sin(t2) + sin(0.25*t2);
plot(t2,yz,'--r')
legend('Forecast','training')

### Categories

Find more on Deep Learning with Time Series and Sequence Data 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!

Translated by