Kostrzewa asked . 2021-08-04

Neural Network generated code gives me different result then my own code

Hi !
Neural Network script generated by Matlab gets some set X and then we set paremters traing set ratio, validation set ratio and test set ratio. In my case this ratio is 0.55/0.15/0.3. However I would like to write script which predict the same number of elements but gets only training set and number h - horizon (how many values neural network should predict).Because I give Neural Network only training set (instead of the whole set) by proportion I should split training set into ratio 0.78/0.22/0.0 (there is no test set so test ratio is 0). 
 
function y_predykcja = matlabNeuralNetworkScript(training_set, horizon)
%T = simplenarTargets;
T= tonndata(training_set,true,false);
trainFcn = 'trainlm';  % Levenberg-Marquardt
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narnet(feedbackDelays,hiddenLayerSize,'open',trainFcn);
net.input.processFcns = {'removeconstantrows','mapminmax'};
[x,xi,ai,t] = preparets(net,{},{},T);
net.divideParam.trainRatio = 0.78;
net.divideParam.valRatio = 0.22;
net.divideParam.testRatio = 0;
net.trainParam.showWindow = false;
net.performFcn = 'mse';  % Mean squared error
% Train the Network
[net tr Ys Es Xf Af ] = train(net,x,t,xi,ai,'useParallel','no');
y = net(x,xi,ai);
y_predykcja = zeros(1,horizon);
for i=1:horizon
  Xnew = net(x,Xf,Af);
  Xf = [Xf Xnew];
  Xf = Xf(1,2:3);
  y_predykcja(1,i) = cell2mat(Xf(1,2));
end
end

My solution is working... but not as good as normal generated by Matlab script. For example I use series load ice_dataset. If I use ntstool where the whole series is divied into ratio 0.55/0.15/0.3 I get MSE 0.02. When I split this data to training_set (0.7 of whole set) and then use my script I get MSE 2. If I use sinus seris MSE of Matlab script is 1.4-e10 in my case is 1.4-e8. Could anybody explain me why ? How to fix my script to get expected accuracy ?

neural network , nn , ntstool , prediction , forecasting , time , time series

Expert Answer

John Michell answered . 2024-12-22 01:42:55

I don't quite follow your logic. You seem to be trying to mimic the effect of using a closed loop configuration. I'm not sure of the validity. However, it seems that the last loop should be something like

 Xnew = Ys; Xinew = Xf, Ainew = Af; Ypred = {[]}
 for i=1:horizon
       [Ynew Xfnew Afnew] = net(Xnew,Xinew,Ainew)
       Ypred = [Ypred Ynew ];
       Xnew = Ynew; Xinew = Xfnew; Ainew = Afnew;
end


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.