NARX with multiple Inputs
3 views (last 30 days)
Show older comments
Dear All;
I am trying use NARX for time series prediction, the problem that i have multiple inputs and i receiving the following error:
Error using preparets (line 185)
The number of input signals does not match network's non-feedback inputs.
Error in NN_Prediction (line 48)
[Xs,Xi,Ai,Ts] = preparets(net,inputSeries,{},targetSeries);
How can i resolve it ?
MATLAB Code:
clc ;
clear ;
%% Read input and output values
data=readtable ('FoulingData.xlsx','sheet','AI_Data');
I1=data.DP_Tube;
I2=data.Tout_Tube;
I3=data.Tout_Shell;
I=[I1 I2 I3];
I=I'
T=data.Fouling;
T=T'
% Normalization between -1 and 1
[In,ps] = mapminmax(I);
[Tn,ts] = mapminmax(T);
X=num2cell(In);
T=num2cell(Tn);
%Data Preparation
N = 3; % Multi-step ahead prediction
% Input and target series are divided in two groups of data:
% 1st group: used to train the network
inputSeries = X(:,1:end-N);
targetSeries = T(1:end-N);
% 2nd group: this is the new data used for simulation. inputSeriesVal will
% be used for predicting new targets. targetSeriesVal will be used for
% network validation after prediction
inputSeriesVal = X(:,end-N+1:end);
targetSeriesVal = T(end-N+1:end); % This is generally not available
% Network Architecture
delay = 2;
neuronsHiddenLayer = 10;
% Network Creation
net = narxnet(1:delay,1:delay,neuronsHiddenLayer);
net.numInputs = 3; % adding an input
net.inputConnect =[1 1 1; 0 0 0]; %connecting 3 inputs to the first layer
[Xs,Xi,Ai,Ts] = preparets(net,inputSeries,{},targetSeries);
net = train(net,Xs,Ts,Xi,Ai);
view(net)
Y = net(Xs,Xi,Ai);
% Performance for the series-parallel implementation, only
% one-step-ahead prediction
perf = perform(net,Ts,Y);
% Multistep prediction
[Xs1,Xio,Aio] = preparets(net,inputSeries(1:end-delay),{},targetSeries(1:end-delay));
[Y1,Xfo,Afo] = net(Xs1,Xio,Aio);
[netc,Xic,Aic] = closeloop(net,Xfo,Afo);
[yPred,Xfc,Afc] = netc(inputSeriesVal,Xic,Aic);
multiStepPerformance = perform(net,yPred,targetSeriesVal);
view(netc)
figure;
plot([cell2mat(targetSeries),nan(1,N);
nan(1,length(targetSeries)),cell2mat(yPred);
nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]')
legend('Original Targets','Network Predictions','Expected Outputs')
1 Comment
Sunil Patidar
on 28 Jan 2021
Can you try removing the bellow mentioned two lines of codes as this might be changing your network's structure.
net.numInputs = 3; % adding an input
net.inputConnect =[1 1 1; 0 0 0]; %connecting 3 inputs to the first layer
Also, Here is a link to an example workflow of how to perform prediction with a closed loop network. While it is not your exact workflow it may be a helpful example:
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!