How to optimize patternnet using a genetic algorithm

2 次查看(过去 30 天)
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