how to write suitable stop criteria to my GA code

9 Ansichten (letzte 30 Tage)
nadia nadi
nadia nadi am 15 Nov. 2015
Beantwortet: Nadiia Huskova am 20 Aug. 2018
Dear,
I used genetic algorithm from matlab toolbox and I got a good min result using this options.
function [x,fval,exitflag,output,population,score] = optim(nvars,PopulationSize_Data,Generations_Data,InitialPopulation_Data)
%%This is an auto generated MATLAB file from Optimization Tool.
%%Start with the default options
options = gaoptimset;
%%Modify options setting
options = gaoptimset(options,'PopulationSize', PopulationSize_Data);
options = gaoptimset(options,'Generations', Generations_Data);
options = gaoptimset(options,'InitialPopulation', InitialPopulation_Data);
options = gaoptimset(options,'Display', 'off');
options = gaoptimset(options,'PlotFcns', { @gaplotbestf @gaplotbestindiv});
%options = gaoptimset(options,'OutputFcns', { @outputBox });
[x,fval,exitflag,output,population,score] = ...
ga(@fitness,nvars,[],[],[],[],[],[],[],[],options);
But because it cost a lot off time I wrote my code by my self using the same options. See the code
clc;clear all;close all;format short g;
for ki=1:1
clear bestSofar
clear totalFitness
tic;
m=2;
hold on
populationSize=200;
populationSize = 4*ceil(populationSize/4);
corssOverPercentage=0.8;
noOfElites=10;
noOfGeneration=200;
%%=========================================
noOfCrossOvers=corssOverPercentage*populationSize;
noOFMutaion=10;
%%Initial population
for i=1: populationSize
here initialize population x;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z=0;
for l=1:noOfGeneration
y=x;
for i=1:populationSize
% % MY fitness function for all the population
FitnessValue;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Normlization
xFit= FitnessValue';
fitCumSum=1/cumsum(xFit) ; % i change this to 1/cumsum(xFit) to get minimum
rouletteWheel=fitCumSum/fitCumSum(end);
y=[y,xFit];
[j,k]=sort(y(:,end),'descend');
y=y(k,:); % sort rows according to last column
y=y(:,1:end-1);
size(y);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for crindex=1:2:noOfCrossOvers-1
ran=rand;
for i=1:populationSize-1
if (ran>rouletteWheel(i))
parent1=x(i+1,:);
parent1Index=i+1;
end
end
ran=rand;
for i=1:populationSize-1
if (ran>rouletteWheel(i))
parent2=x(i+1,:);
parent2Index=i+1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Scattered crossover
% here my crossover
end %noOfCrossOvers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%mutation Gaussian
% here my mtation
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=y;
totalFitness(l)=sum(xFit);
sortedFit=sort(xFit,'descend'); %minimisation
%sortedFit=sort(xFit,'ascend'); %max
bestSofar(l)=sortedFit(end);
if l>1 & bestSofar(l)< bestSofar(l-1)
z=0;
else
z=z+1;
end
if z==500 break
end
end
finalSolution=x(end,:) %Best solution
end %ki
figure;
z=finalSolution;
Plot(z);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
from this code I got a result but is not as good as the code from toolbox. I checked the selection operator it has no effect on the result. this code works perfect for 2 dimensions with number generation=100, but for m>=3 I got this different in result, I need to minimize a shape but is not as minimum as the result from matlab toolbox. Can any one tell me what is missed in it. I tried to read some code from the GA toolbox to see what is missed but I couldn't.
I checked and I found when I set the generation less than 100 I got not bad result, the problem I need the GA stop when the result reach the minimum value by itself without specifying Number generation by my self. I think the stop criteria in this code is not reliable like the GA from toolbox.
Nadia
Thanks for any help

Antworten (1)

Nadiia Huskova
Nadiia Huskova am 20 Aug. 2018
Dear Nadia,
I also looking for optimal stopping criteria for the GA. I think, number of iterations and time criteria are not good ideas. The original GA (from toolbox) calculates values of standard deviation after every iteration and compares results every time.

Community Treasure Hunt

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

Start Hunting!

Translated by