Custódio_54 asked . 2021-07-13

How I can add more hidden layers on the nftool code that I exported from the nnstart GUI?

Since I don't know much about how to implement a network using command line, I tried using the GUI from NNSTART and exported the code so I could try to figure out how to make the changes I need. the problems is that I don't how to add more layers/neurons, even more ephocs.
 
Here is the code I got from my first attempt:
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 13-Sep-2017 20:47:36
%
% This script assumes these variables are defined:
%
%   Input_train - input data.
%   Target_train - target data.

x = Input_train;
t = Target_train;

% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainlm';  % Levenberg-Marquardt backpropagation.

% Create a Fitting Network
hiddenLayerSize = 23;
net = fitnet(hiddenLayerSize,trainFcn);

% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.output.processFcns = {'removeconstantrows','mapminmax'};

% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand';  % Divide data randomly
net.divideMode = 'sample';  % Divide up every sample
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 10/100;
net.divideParam.testRatio = 10/100;

% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse';  % Mean Squared Error

% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
  'plotregression', 'plotfit'};

% Train the Network
[net,tr] = train(net,x,t);

% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)

% Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)

% View the Network
view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)
end

 

neural network , matlab , nntool

Expert Answer

John Michell answered . 2024-04-25 19:35:33

you can use :
 
 
trainFcn = 'trainlm';
 hiddenLayerSize = 23;
 numberhiddenlayers=2;%more hidden layers 
net = fitnet([hiddenLayerSize numberhiddenlayers],trainFcn);
 net.trainParam.epochs=2000;% more epochs
 view(net)

with your code:

% Solve an Input-Output Fitting problem with a Neural Network
      % Script generated by Neural Fitting app
      % Created 13-Sep-2017 20:47:36
      %
      % This script assumes these variables are defined:
      %
      %   Input_train - input data.
      %   Target_train - target data.
      x = Input_train;
      t = Target_train;
      % Choose a Training Function
      % For a list of all training functions type: help nntrain
      % 'trainlm' is usually fastest.
      % 'trainbr' takes longer but may be better for challenging problems.
      % 'trainscg' uses less memory. Suitable in low memory situations.
      trainFcn = 'trainlm';  % Levenberg-Marquardt backpropagation.
      % Create a Fitting Network
      hiddenLayerSize = 23;
      numberhiddenlayers=2; %more hidden layers
      net = fitnet([hiddenLayerSize numberhiddenlayers],trainFcn);
      net.trainParam.epochs=2000; %more epochs
      % Choose Input and Output Pre/Post-Processing Functions
      % For a list of all processing functions type: help nnprocess
      net.input.processFcns = {'removeconstantrows','mapminmax'};
      net.output.processFcns = {'removeconstantrows','mapminmax'};
      % Setup Division of Data for Training, Validation, Testing
      % For a list of all data division functions type: help nndivide
      net.divideFcn = 'dividerand';  % Divide data randomly
      net.divideMode = 'sample';  % Divide up every sample
      net.divideParam.trainRatio = 80/100;
      net.divideParam.valRatio = 10/100;
      net.divideParam.testRatio = 10/100;
      % Choose a Performance Function
      % For a list of all performance functions type: help nnperformance
      net.performFcn = 'mse';  % Mean Squared Error
      % Choose Plot Functions
      % For a list of all plot functions type: help nnplot
      net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
        'plotregression', 'plotfit'};
      % Train the Network
      [net,tr] = train(net,x,t);
      % Test the Network
      y = net(x);
      e = gsubtract(t,y);
      performance = perform(net,t,y)
      % Recalculate Training, Validation and Test Performance
      trainTargets = t .* tr.trainMask{1};
      valTargets = t .* tr.valMask{1};
      testTargets = t .* tr.testMask{1};
      trainPerformance = perform(net,trainTargets,y)
      valPerformance = perform(net,valTargets,y)
      testPerformance = perform(net,testTargets,y)
      % View the Network
      view(net)
      % Plots
      % Uncomment these lines to enable various plots.
      %figure, plotperform(tr)
      %figure, plottrainstate(tr)
      %figure, ploterrhist(e)
      %figure, plotregression(t,y)
      %figure, plotfit(net,x,t)
      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.