- https://www.mathworks.com/help/deeplearning/ref/preparets.html
NARX network setup preparets function errors
11 views (last 30 days)
Show older comments
I need help setting up my NARX network. Input is pressure, output is current that should be predicted prediction_horizon steps in advance. Also 16 past samples of pressure should be used for prediciton and last 4 samples of current.
input_series = con2seq(Effective_pressure_normalized);
% Feedback: Past current values (used as input to the network)
feedback_series = con2seq(Motor_current_normalized);
% Target: Future current values to predict (shifted by prediction horizon)
target_series = con2seq(Motor_current_normalized(prediction_horizon_samples+1:end)); % target = feedback in NARX
%% Define Delay Structure
input_delays = 1:16;
feedback_delays = 1:4;
hidden_neurons = round(best_params(3)); % from GA
%% Create and Configure NARX Network
narx_net = narxnet(input_delays, feedback_delays, hidden_neurons, 'closed');
narx_net.trainFcn = 'trainlm';
narx_net.trainParam.lr = best_params(4); % from GA
narx_net.performParam.regularization = best_params(5); % from GA
narx_net.trainParam.showWindow = true;
%% Prepare Input and Target Data for Training
[Xs, Xi, Ai, Ts] = preparets(narx_net, input_series, feedback_series, target_series);
%% Train NARX Network
narx_net = train(narx_net, Xs, Ts, Xi, Ai);
Problem is in this line [Xs, Xi, Ai, Ts] = preparets(narx_net, input_series, feedback_series, target_series);
When I put feedback_series as third argument it gives out this error
"Error using preparets
Number of output signals does not match number of network's non-feedback outputs.
Error in model_analysis_nn_ga_curr_simulink2 (line 65)
[X, Xi, Ai, T] = preparets(narx_net, input_series, feedback_series, target_series);"
And when I put {} instead of feedback series (since third argument in preparets is
- Tnf — Non-feedback targets)
I get this error
"Error using preparets
Number of output signals does not match number of network's non-feedback outputs.
Index in position 2 exceeds array bounds. Index must not exceed 1.
Error in preparets (line 317)
xi = xx(:,FBS+((1-net.numInputDelays):0));
Error in model_analysis_nn_ga_curr_simulink2 (line 70)
[Xs, Xi, Ai, Ts] = preparets(narx_net, input_series, {}, target_series);"
Any idea how to fix this, thanks in advance!
0 Comments
Answers (1)
Manish
on 12 May 2025
Hi,
I understand that you are encountering an error when using the 'preparets' function. When you use 'feedback_series' as the third argument, you see the error because the 'target_series' is not aligned with the network's outputs. In the second approach, the error is possibly due to incorrect dimensions.
Check that the input and feedback series are properly formatted as cell arrays, and ensure that the target_series is correctly aligned with the network's output. This could resolve the issue.
These errors depend on the data passed to the function.
Please refer to the sample code with dummy data below, which works:
%Dummy data
n_samples = 200;
prediction_horizon = 5;
prediction_horizon_samples = prediction_horizon;
Effective_pressure_normalized = sin(0.05*(1:n_samples)) + 0.05*randn(1,n_samples);
Motor_current_normalized = 0.5*sin(0.05*(1:n_samples) + 1) + 0.05*randn(1,n_samples);
input_series = con2seq(Effective_pressure_normalized);
feedback_series = con2seq(Motor_current_normalized);
target_series = feedback_series(prediction_horizon_samples + 1:end);
input_series = input_series(1:end - prediction_horizon_samples);
feedback_series = feedback_series(1:end - prediction_horizon_samples);
% NARX Network
input_delays = 1:16;
feedback_delays = 1:4;
hidden_neurons = 10;
narx_net = narxnet(input_delays, feedback_delays, hidden_neurons, 'closed');
narx_net.trainFcn = 'trainlm';
narx_net.trainParam.lr = 0.01;
narx_net.performParam.regularization = 0.1;
narx_net.trainParam.showWindow = true;
[Xs, Xi, Ai, Ts] = preparets(narx_net, input_series, {}, target_series);
% Train
narx_net = train(narx_net, Xs, Ts, Xi, Ai);
% Simulate
Y = narx_net(Xs, Xi, Ai)
Refer to the documentation link below for better understanding:
hope this helps!
0 Comments
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!