How to optimize patternnet using a genetic algorithm

조회 수: 2 (최근 30일)
Syed Amin
Syed Amin 2013년 2월 3일
댓글: RAJA SEKHAR BATTU 2022년 12월 13일
This is how to optimize weights of feedforwardnet but I dont know how to do this for about patternnet please help
function mse_calc = mse_test(x, net, inputs, targets)
% 'x' contains the weights and biases vector
% in row vector form as passed to it by the
% genetic algorithm. This must be transposed
% when being set as the weights and biases
% vector for the network.
% To set the weights and biases vector to the
% one given as input
net = setwb(net, x');
% To evaluate the ouputs based on the given
% weights and biases vector
y = net(inputs);
% Calculating the mean squared error
mse_calc = sum((y-targets).^2)/length(y);
end
The following code example describes a script that sets up a basic Neural Network problem and the definition of a function handle to be passed to GA. It uses the above function to calculate the Mean Squared Error.
% INITIALIZE THE NEURAL NETWORK PROBLEM %
% inputs for the neural net
inputs = (1:10);
% targets for the neural net
targets = cos(inputs.^2);
% number of neurons
n = 2;
% create a neural network
net = feedforwardnet(n);
% configure the neural network for this dataset
net = configure(net, inputs, targets);
% create handle to the MSE_TEST function, that
% calculates MSE
h = @(x) mse_test(x, net, inputs, targets);
% Setting the Genetic Algorithms tolerance for
% minimum change in fitness function before
% terminating algorithm to 1e-8 and displaying
% each iteration's results.
ga_opts = gaoptimset('TolFun', 1e-8,'display','iter');
% PLEASE NOTE: For a feed-forward network
% with n neurons, 3n+1 quantities are required
% in the weights and biases column vector.
%
% a. n for the input weights
% b. n for the input biases
% c. n for the output weights
% d. 1 for the output bias
% running the genetic algorithm with desired options
[x_ga_opt, err_ga] = ga(h, 3*n+1, ga_opts);
  댓글 수: 2
Randy Souza
Randy Souza 2013년 3월 11일
I have restored the original text of this question.
Syed, this question has a clear subject and an accepted answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.
aleksandar
aleksandar 2014년 10월 8일
Hello, I'm new to this field and I'm sorry if my question is not appropriate, I would like to ask is it possible to modify this mse_calc function, so it can be used for the matrix of inputs not for the row, in that way there is much more weights (neurons *columns)? Best Regards

댓글을 달려면 로그인하십시오.

채택된 답변

Greg Heath
Greg Heath 2013년 2월 7일
편집: Randy Souza 2013년 3월 11일
See my three replies to your question in this Newsgroup thread: ga optimization of nn weights
Hope this helps.
Thank you for formally accepting my answer!!!
Greg
  댓글 수: 1
RAJA SEKHAR BATTU
RAJA SEKHAR BATTU 2022년 12월 13일
@Greg Heath Hi Greg, this link doesn't work. can you please provide any other link or answer.
Thanks in advance.
Best wishes,
Raja

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by