Problem with closeloop of network Narx

4 views (last 30 days)
FRANCISCO
FRANCISCO on 31 Jan 2013
Answered: Aditya on 3 Sep 2025 at 6:44
Hi, i have a problem with network Narx. i undestand the first steps but i want iterate 3 times with close loop and i don`t the code for this action. The code that i use is:
xlsread p %inputs% xlsread t %targets%
p1=p' t1=t' %transpose the data%
inputSeries=tonndata(p1,true,false) targetSeries=tonndata(t1,true,false)
%create the network" net=narxnet(1:2,1:2,16)
%preparets%
[x,xi,ai,t]=preparets(net,inputSeries,{},targetSeries)
%train network%
net=train(net,x,t,xi,ai)
%simulate%
[y,xf,af]=sim(net,x,xi,ai)
%now I want to iterate three times to value one day after using closeloop% %I do not know how to do it or how it should be the code%
netc=closeloop(net)
[xc,xic,aic,tc]=preparets(netc,y,{},{}) ????
here should get the simulated outputs above, for an iteration but do not know how to be this function (preparets) because I have not the targets in the future. Welcome clarification of the concept . Many thanks

Answers (1)

Aditya
Aditya on 3 Sep 2025 at 6:44
HI Francisco,
To perform multi-step (e.g., three-step) ahead prediction with a NARX network in MATLAB, you first convert your trained network to closed-loop mode using closeloop. Then, you prepare the initial input and state sequences using the last known values from your training data. For each future step, you provide the necessary input (if any) and let the network recursively predict the next value, using its own previous output as input for the next step. This process does not require future target values, as the network is now operating in prediction mode. The code provided demonstrates how to implement this process for three steps ahead.
% Assume you have already trained your NARX network as you described.
% Step 1: Convert to closed-loop for multi-step prediction
netc = closeloop(net);
% Step 2: Prepare initial input states
% Use the last available data points from your input series
% Let's say you want to start predicting after your last known target
% Prepare the initial input for prediction (last inputs used during training)
lastInputs = y(end-netc.numInputDelays+1:end); % last inputs to the net
lastStates = y(end-netc.numLayerDelays+1:end); % last outputs to the net
% Step 3: Predict next 3 steps
numSteps = 3;
futureInputs = cell(1, numSteps); % If you have future known inputs, fill here. Otherwise, zeros.
for i = 1:numSteps
futureInputs{i} = 0; % or whatever your exogenous input is, if any
end
% Simulate the network for 3 steps ahead
[yPred,~,~] = netc(futureInputs, lastInputs, lastStates);
% yPred will be a cell array with the 3 predicted outputs
disp('3-step ahead predictions:');
cell2mat(yPred)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!