Hello, I have a very basic doubt regarding genetic algorithm. GA gives different answers each time we run it and so how can we rely on it. I mean to ask how far can we take the results for granted. I googled about it and came across using 'optimoptions' and 'gs' in order to see that the solution approaches global minima rather than local, but could not understand even a bit. Can anyone help me in understanding that? How do we code it in Matlab?
Following is the code I have written in Matlab to minimise a function defined in square brackets (called as 'calculations' in the code). This code, as told above returns different values every time I execute it. How do I refine it for precise results?
%defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
%creating 2d mesh
[xx yy]=meshgrid(x,y);
%evaluation
for i=1:length(xx)
for j=1:length(yy)
inputvector(1)=xx(i,j);
inputvector(2)=yy(i,j);
f(i,j)=calculations(inputvector);
end
end
%plotting the inputs vs function
surfc(xx,yy,f)
xlabel('xvalues');
ylabel('yvalues');
zlabel('functionvalues');
%getting a shaded plot rather the one with grids
shading interp
%optimising the funtion
[inputs_of_optimal_solution,optimal_fvalue]=ga(@calculations,2)
disp('The f minima is')
disp(optimal_fvalue)
disp('The input values corresponding to f minima are')
disp(inputs_of_optimal_solution)
[
function [actualfunc]=calculations(inputvector)
f1x=(sin((5.1*pi*inputvector(1))+0.5))^6;
f1y=(sin((5.1*pi*inputvector(2))+0.5))^6;
f2x=exp((-4*log(2)*(inputvector(1)-0.0667)^2)/0.64);
f2y=exp((-4*log(2)*(inputvector(2)-0.0667)^2)/0.64);
actualfunc=f1x*f2x*f1y*f2y;
end
]