tina-nini90 asked . 2021-06-22

How do you make predictions with a trained Neural Network (NAR)?

Hello. I’m new here and I have a problem with the neural network toolbox that is unbearably frustrating because it should be the easiest thing in the world but I’m not getting it. My general Matlab skills are very moderate and I have never used the Neural Network function before until now.
 
I want to create a neural network that based on an input data series can predict values in the future. From what I understand the Nonlinear Autoregressive neural network should be perfect for this and I have tried for hours and hours to watch all of Matlabs own tutorials on how to use the neural network toolbox and read about it but it seems like all the tutorials basically stop after the data has been trained and refuses to tell you how to make any useful predictions at all with the network. Or I am just simply missing something that is really obvious to everyone else except me.
 
I read on a Matlab tutorial that they recommend you to use the GUI way of making a neural network first until you get the hang of it and can code it. So here is pretty much what I do when I follow the guides:
 
Write nnstart -> go to Time series app -> select NAR and chose my 1x1826 data series as a matrix row (imported from an excel sheet) -> select 10 hidden neurons & 2 delays.
 
Then I train the data using Levenberg-Marquardt and after the training it seems to have worked great. I click next and save the results and Finnish.
 
My workspace is now full of things generated by the neural network, for example a data series called “output” which of course sounds promising, but it is 1x1824 cells, in other words 2 values shorter than the original data series (because delay was set to 2 I guess).
 
And at this point I am totally lost. How do I make any predictions with this? I have also tried using the example input data in the toolbox instead of my own data series but it makes no difference. So after the training and everything is done, how in god’s name do I get the network to tell me the 1825th value of my data series?!
 
I have tired generating the script and trying to understand it from there, and If I’m lucky the script can tell me things like “perfc = 1.5278” and “stepAheadPerformance = 5.8328e-04”. I’m not sure what that means but it feels like Matlab is bragging about how good it could theoretically predict the next values, but it sure doesn’t like to give up its predicted values without a fight! :)
So can anyone help me out here? How do I predict values after the network has been trained?

neural network , nar , predict , data series , deep learning

Expert Answer

John Williams answered . 2024-05-18 06:59:33

%Peta on 2 Sep 2014 at 18:01
% Thanks for answering, I’m not sure what the ”autocorrelation function” is
Suggestions, not necessarily in order:
1. Use the command lookfor
 
 
     lookfor autocorrelation

then use the help and doc commands on functions that are listed. For example

 help nncorr
 doc nncorr
2. Search in wikipedia
 
3. Search in the NEWSGROUP and ANSWERS. To reduce the results to a manageable size, use in combination with other reasonable searchwords e.g., some SUBSET of these
 
     autocorrelation neural narnet nncorr greg
% but I when I change the number of hidden layers in the GUI and plot the “Error Autocorrelation” it basically looks exactly the same regardless of how many hidden layers I have. So I should set it to 1 in that case then?
 
I only use 1 hidden layer and try to minimize the number of hidden nodes subject to an upper bound on the MSE.
 
 
 net = narnet(FD,H);
For efficient predictions FD should be a subset of the significant lags of the TARGET autocorrelation function. This calculation is independent of H. See some of my previous posts for examples
 
% I found the net.divideFcn in the script code and changed it like you said. But at point 4 and 5 I’m afraid I have pretty much no idea what you are talking about. I found nothing about Ntrails in the script, is this something I need to write myself? And if so is there any kind of example somewhere on how to do it? I’m afraid it is new to me.
 
Ntrials, not Ntrails. The number of trials for random initial weights given the number of hidden nodes.
 
I don't find the MATLAB help/doc script to be very helpful. For example, it says nothing about
 
 
 1. Using capitals to indicate cell variables.
 2. Using nncorr to find a reasonable subset of feedback delays
 3. Using a for loop to find a reasonable value for H (e.g., Hmin:dH:Hmax)
 4. Not using the default 'dividerand' because it destroys the correlations between the output and feedback signals
 5. For each of numH candidate values for H, training success depends on starting with a good set of random initial weights. The best way to find one or more is to have an inner for loop over Ntrial random weight initializations that are created by the configure function.
 6. Explicitly initializing the random number generator before the outer loop so that you can duplicate any of the numH*Ntrials designs
 7. Often closing the loop on an openloop design to obtain netc does not yield acceptable results when inputted with original data. Therefore, the closeloop net should be trained beginning with the weights obtained from the openloop design to obtain netc2.

% And I’m not sure what to do with the LHS syntax thing, I did have xs ts xi and ai in my workspace so I tried adding the piece of code you wrote: % % [ net tr Ys Es Xf Af ] = train( net, Xs, Ts, Xi, Ai );

This code replaces the 3 step script

 [ net tr  ]  = train( net, Xs, Ts, Xi, Ai );
 [ Ys Xf Af ] = net( Xs, Xi, Ai );
 Es          = gsubtract(net,Ts,Ys);

 Finally, to predict into the future M timesteps beyond the end of the target data

 Xic2 = Xf; 
 Aic2 = Af;
 Ypred = netc2( cell(1,M), Xic2, Aic2);


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.