How to optimize patternnet using a genetic algorithm
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Syed Amin
il 3 Feb 2013
Commentato: RAJA SEKHAR BATTU
il 13 Dic 2022
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 Commenti
Randy Souza
il 11 Mar 2013
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
il 8 Ott 2014
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
Risposta accettata
Greg Heath
il 7 Feb 2013
Modificato: Randy Souza
il 11 Mar 2013
Hope this helps.
Thank you for formally accepting my answer!!!
Greg
1 Commento
RAJA SEKHAR BATTU
il 13 Dic 2022
@Greg Heath Hi Greg, this link doesn't work. can you please provide any other link or answer.
Thanks in advance.
Best wishes,
Raja
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Deep Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!