NARX: Outputs are known today, target is not, I want to get estimated target value put in today position. Do I use the one step ahead method? Or the "default" method?
1 view (last 30 days)
Show older comments
% This is a basic question,but I have managed to confuse myself. I have already searched for prior answers unsuccessfully, and while there is likely one one among the many hundreds of submissions from over the past decade, I have not been to locate it.
% I have a target vector and several input vectors aligned with the target
% in time. That is, on any given day the input values are known, but the
% actual target value is not. The idea is to use the the input values to
% try to estimate the target value.
% first I will show the "default" method as returned as a simple script by
% MATLAB
% then I will show the one-step ahead prediction variant
% Which is correct for my goal? That is, whcih gives the correct alignment
% of the inputs, targets and estimated targets?
% For the "default" method I do the following:
% gather the n inputs for days=1,2,3,... into n columns, one for each input
% put the target for days=1,2,3,... into 1 column
% prepare inputs and targets
X = tonndata(inputs,false,false);
T = tonndata(target,false,false);
% choose the training function
trainFcn = 'trainlm';
% create a nonlinear autoregressive network
inputDelays = 1:4;
feedbackDelays = 1:4;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% prepare for training and simulation
[x,xi,ai,t] = preparets(net,X,{},T);
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);
% Next, I implement the alternative method, the Step-Ahead Prediction Network
nets = removedelay(net);
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
% The MATLAB comments in the script state that "The new network returns
% the same outputs as the original network, but outputs are shifted left
% one timestep." Well, that's true, except that there is also an additional new value
% at the end of ys not present in y!
% My question is: Which method puts the estimated target value into the
% same day as the outputs used to estimate it?
0 Comments
Accepted Answer
Himanshu
on 31 Mar 2023
Hello Kevin,
I understand that you have a target vector and several input vectors aligned with the target in time. You want to know which method, the "default" method or the one-step-ahead prediction (Step-Ahead Prediction Network) variant, aligns the estimated target value with the inputs used to estimate it.
The one-step-ahead prediction method, which uses the Step-Ahead Prediction Network, is the correct choice for your goal. This method is designed to predict the target value at time t using only the input values up to time t-1. This means that the estimated target value is aligned with the input values used for its estimation.
The "default" method does not align the estimated target value with the input values used for the estimation, as it considers the feedback from the target itself.
To implement the one-step-ahead prediction method, you can use the following code:
% remove the delay from the original network
nets = removedelay(net);
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
The output ys will be shifted left one timestep compared to y, and it will also have an additional value at the end. Based on the available input data, the step-ahead prediction network estimates each timestep, including the last one.
You can refer to the below documentation to understand more about the “removedelay” and "preparets" functions.
2 Comments
More Answers (0)
See Also
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!