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)

7 次查看(过去 30 天)
% 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 个评论
Ranjeet
Ranjeet 2023-5-12
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.
Adeb
Adeb 2023-5-16
Thanks Ranjeet, see the attached image... the plot of the output (elapsed time vs no of hidden neurons) should be in a single line ascending and not the way its showing (see attached image)

请先登录,再进行评论。

回答(1 个)

Anjaneyulu Bairi
Anjaneyulu Bairi 2023-8-25
编辑:Anjaneyulu Bairi 2023-8-25
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.

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by