I am trying to train my neural network multiple times (100 times) with hidden neurons range (1 to 100), then output the plots(Elapsed time vs Hidden neurons, MSE vs H neurons)
5 views (last 30 days)
Show older comments
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 03-May-2023 15:14:53
%
% This script assumes these variables are defined:
%
% inputONETWOTHREE - input data.
% outputThreeThree - target data.
x = inputONETWOTHREE;
t = outputThreeThree;
% 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.
elapsedTime = (hiddenLayerSize);
% Create a Fitting Network
net = fitnet(hiddenLayerSize,trainFcn);
%net.layers{1}.transferFcn = 'tansig'; % hidden layer 1
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 0/100;
net.divideParam.testRatio = 20/100;
for i = 1:100;
hiddenLayerSize = i;
tic;
% Train the Network
[net,tr] = train(net,x,t);
elapsedTime(i) = toc;
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,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)
figure;
plot(hiddenLayerSize,elapsedTime,'-ob');
xlabel('Number of Hidden Neurons');
ylabel('Elapsed Time (s)');
title('Elapsed Time vs Number of Hidden Neurons');
title('MSE vs Number of Hidden Neurons');
end
##INPUT,OUTPUT FILES ARE ATTACHED
2 Comments
Ranjeet
on 12 May 2023
It would be helpful if you can provide the issue you are facing while your training process. You have mentioned that you are training a network, but the question is not clear that you need help in.
Answers (1)
Anjaneyulu Bairi
on 25 Aug 2023
Edited: Anjaneyulu Bairi
on 25 Aug 2023
I ran your code and got some errors, to resolve those errors I made few changes and I am mentioning those changes below.
Error 1: “x”, ”t” are imported as tables into my workspace, So I converted them to matrix and transpose them.
Error 2: “hiddenLayerSize is not defined”.
Change 1: converted “x”,”t” to matrix and transposed it.
Change 2: I assigned value 100 to “hiddenLayerSize” as you are storing the values for 100th iteration.
Then I got the below results by running the code.
Please find the total code below.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 03-May-2023 15:14:53
%
% This script assumes these variables are defined:
%
% inputONETWOTHREE - input data.
% outputThreeThree - target data.
x = inputONETWOTHREE;
t = outputThreeThree;
%
%Changes stars here
x=x{:,:} % converting into matrix
x=transpose(x) % transpose the matrix
t=t{:,:} % converting into matrix
t=transpose(t) % transpose the matrix
hiddenLayerSize=100; % assigning value 100 to hiddenLayerSize
%Changes end here
%
% 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.
elapsedTime = (hiddenLayerSize);
% Create a Fitting Network
net = fitnet(hiddenLayerSize,trainFcn);
%net.layers{1}.transferFcn = 'tansig'; % hidden layer 1
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 0/100;
net.divideParam.testRatio = 20/100;
for i = 1:100;
hiddenLayerSize = i;
tic;
% Train the Network
[net,tr] = train(net,x,t);
elapsedTime(i) = toc;
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,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)
figure;
plot(hiddenLayerSize,elapsedTime,'-ob');
xlabel('Number of Hidden Neurons');
ylabel('Elapsed Time (s)');
title('Elapsed Time vs Number of Hidden Neurons');
title('MSE vs Number of Hidden Neurons');
end
Hope it 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!