Ask an expert. Trust the answer.

How to train NARX neural network in closed loop

Your academic and career questions answered by verified experts

Teacher helping student with MATLAB programming

How to train NARX neural network in closed loop

Joshua asked: neural network , neural networks , narx , closed loop , time series

Learn how to train a NARX neural network in closed loop using MATLAB. This resource provides a step-by-step guide, examples, and best practices. Get started now

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-07-05 10:11:23

 close all, clear all, clc
disp('DIRECT TRAINING OF A CLOSELOOP NARXNET')
load('maglev_dataset');
whos
%   Name              Size      Bytes   Class 
%   maglevInputs      1x4001    272068  cell                
%   maglevTargets     1x4001    272068  cell                
X   = maglevInputs; 
T   = maglevTargets;
ID  = 1:2, FD = 1:2, H  = 10   % Default values
netc                    = closeloop(narxnet(ID,FD,H));
view(netc)
netc.divideFcn          = 'divideblock';
[ Xcs, Xci, Aci, Tcs ]  = preparets( netc, X, {}, T );
tcs                     = cell2mat(Tcs);
whos X T Xcs Xci Aci Tcs tcs
%  Name     Size     Bytes   Class
%   Aci     2x2         416  cell                
%   T       1x4001   272068  cell                
%   Tcs     1x3999   271932  cell                
%   X       1x4001   272068  cell                
%   Xci     1x2         136  cell                
%   Xcs     1x3999   271932  cell                
%   tcs     1x3999    31992  double              

 MSE00cs = var(tcs,1)  % 2.0021 ( 1-dim MSE reference)

 rng(4151941)
tic
[netc trc Ycs Ecs Xcf Acf ] = train(netc,Xcs,Tcs,Xci,Aci);
toc                           % 197 sec
view(netc)
whos Ycs Ecs Xcf Acf
%   Name    Size     Bytes     Class
%   Acf     2x2         416    cell               
%   Ecs     1x3999   271932    cell               
%   Xcf     1x2         136    cell               
%   Ycs     1x3999   271932    cell               

 stopcriterion  = trc.stop                    % Validation stop
bestepoch      = trc.best_epoch               % 4
ecs            = cell2mat(Ecs);
NMSEcs         = mse(ecs)/MSE00cs             %  1.2843
tcstrn         = tcs(trc.trainInd);
tcsval         = tcs(trc.valInd);
tcstst         = tcs(trc.testInd);
NMSEcstrn      = trc.best_perf/var(tcstrn,1)  %  1.3495
NMSEcsval      = trc.best_vperf/var(tcsval,1) %  0.9325
NMSEcstst      = trc.best_tperf/var(tcstst,1) %  1.6109
I consider a good design to have a normalized MSE, NMSE <= 0.01 implying that 99% of the target variance is successfully modeled. Obviously this design is a failure.
 
However, as I mentioned before, my objective was to obtain an error free code for you.
 
Presumably, a search for the proper combination of ID, FD, H and RNG seed would yield a more successful design.
 
I will let you have fun with that.
 
I prefer to convert an openloop design as demonstrated in my reference.


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.