필터 지우기
필터 지우기

Fitness function run twice / stopping a GA

조회 수: 4 (최근 30일)
Boris Huljak
Boris Huljak 2018년 5월 23일
편집: Boris Huljak 2018년 5월 23일
Hello.
I have currently two problem with my GA code. My elements are defined by 4 value, and each time my fitness function is called, I display the values. What I get is :
-0.1827 0.2077 -0.0817 0.0275
-0.1827 0.2077 -0.0817 0.0275
0.8208 -0.6566 0.1232 0.0194
-0.8640 0.7799 -0.1599 0.0242
As you can see, the first element is plotted twice,meaning the fitness function is called twice with that element. But if I look at the population, it is not in it.
Here is my "run" code :
clear all
ObjectiveFunction = @fitnescalc;
nvars = 4; % Number of variables
ConstraintFunction = @constraint;
CreationFcn=@populationInit;
IP=[populationInit()]
for i=1:2
IP = [IP;populationInit()]; % Population MAtrix goes here
end
options = optimoptions('ga','InitialPopulationMatrix',IP,'OutputFcn',@gaoutfun,'PopulationSize',length(IP(:,1)));
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],[],[], ...
ConstraintFunction,options);
Do you see where it could come from ? Thank you
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2018년 5월 23일
Boris - what does populationInit() do? i.e. what is the code for this function? Does it return a single element or multiple ones? It looks like you initialize IP as
IP=[populationInit()]
and then update it twice with two calls to this same function so how large is your initial population?
Please copy and paste the code for populationInit to your question.
Boris Huljak
Boris Huljak 2018년 5월 23일
편집: Boris Huljak 2018년 5월 23일
he code is the following :
function [ p_shape ] = populationInit()
p_shape_degree=3;
%%%The computed polynomial degree will be : p_shape_degree + 1
% Constants declaration
Xlenght=60e-2;
Ylenght=9e-2; %Diametre TOTAL
X_max = Xlenght;
Y_min = 1e-2; % Minimum radius accepted
Y_max = Ylenght/2; % Maximum radius accepted
thickness_min =10e-3; % Minimum thickness accepted
is_poly_ok = 0;
iteration_nb = 1; % Convergence security
X = 0:.05:X_max;
% polynomial computation
while(~is_poly_ok)
Y_in = Y_min + rand()*(Y_max - Y_min);
Y_out = Y_min + rand()*(Y_max - Y_min);
p_in = [-1/X_max 1];
p_out = [1/X_max 0];
p = Y_in*p_in + Y_out*p_out;
p_fit = zeros(1, p_shape_degree + 1);
p_fit(p_shape_degree : p_shape_degree + 1) = p;
% Shape polynomial
p_conv = 5*randn(1, p_shape_degree - 1)/iteration_nb;
for i = 1:p_shape_degree-1
p_conv(i) = p_conv(i)/(X_max^(p_shape_degree - 1 - i));
end
p_shape = p_fit + conv(conv(p_in, p_out), p_conv);
vals = polyval(p_shape, X);
if (min(vals)> Y_min && max(vals) < Y_max - thickness_min)
is_poly_ok = 1;
end
iteration_nb = iteration_nb + 1;
end
end
It is a bit messy, but what it does, it simply returns a vector of the form p=[A B C D].
My initial population is weirdly made, I agree, but once I inspect the vector, it seems fine with no duplicate

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by