0
votes

I have trained the NARX net in MATLAB with below code.I want to test the trained network from new inputs (testX) and targets (testY).But i am getting error in last line forecastLoad = sim(net, testX')';

 X = tonndata(trainX,false,false);
 T = tonndata(trainY,false,false);

 inputSeries = X;

 targetSeries = T;

% Create a Nonlinear Autoregressive Network with External Input
 inputDelays = 1:3;
feedbackDelays = 1:3;
hiddenLayerSize = 20;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);

% Prepare the Data for Training and Simulation
% The function PREPARETS prepares time series data 

[inputs,inputStates,layerStates,targets] = ... 
    preparets(net,inputSeries,{},targetSeries);

% Set up 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,inputs,targets,inputStates,layerStates);
%% 

% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
MAE = mae(errors);


 %Test on new data
  forecastLoad = sim(net, testX')';
  error = testY-forecastLoad;
1
Please add the error messageMikhail_Sam
looks like inputs you used for training and testX' has different dimensions. Check it!Mikhail_Sam

1 Answers

1
votes

Take a look in the line Matlab test the data:

% Test the Network
outputs = net(inputs,inputStates,layerStates);

Why do not you enter the data in the same way? Lets do this:

% Prepare first the data.

[inputs,inputStates,layerStates,targets] = ... 
     preparets(net,textX,{},testY);
% And then predict.
forecastLoad = net(inputs,inputStates,layerStates);