ANN With GA
ANN With GA
------
% Training
%--------------------------------------------------------------------
------
% Define GA options
options = optimoptions('ga', 'MaxGenerations', 50, 'PopulationSize',
20, 'Display', 'iter');
[pn,mininputrain,maxinputrain,tn,mintargetrain,maxtargetrain] =...
premnmx(inputrain,targetrain);
% Task 5: Network call, simulation, and post-regression analysis
%
---------------------------------------------------------------------
%--------------------------------------------------------------------
------
% Fitness Function for GA
%--------------------------------------------------------------------
------
function mse = annFitness(params, net, pn, tn)
% Set network weights and biases
net = setwb(net, params);
% Simulate the network
an = sim(net, pn); % Simulate the trained network
% Calculate the mean squared error
mse = mean((an - tn).^2); % MSE
end