필터 지우기
필터 지우기

how to pass initial guess to ga(),this is my sample code and i want to initialize complex initial guess in the code please help

조회 수: 40 (최근 30일)
[z, f] = ga(@objfun,2);
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.
disp(z)
0.4017 0.4718
function f = objfun(X)
% Create complex value from real and imaginary
z = X(:, 1) + i*X(:, 2);
f = z.^2 - z + 1;
f = abs(f);
end

채택된 답변

Walter Roberson
Walter Roberson 2024년 3월 11일
In order to pass in an initial guess, you need to create an options structure and set
InitialPopulationMatrix specifies an initial population for the genetic algorithm. The default value is [], in which case ga uses the default CreationFcn to create an initial population. If you enter a nonempty array in the InitialPopulationMatrix, the array must have no more than PopulationSize rows, and exactly nvars columns, where nvars is the number of variables, the second input to ga or gamultiobj. If you have a partial initial population, meaning fewer than PopulationSize rows, then the genetic algorithm calls CreationFcn to generate the remaining individuals.
  댓글 수: 4
Walter Roberson
Walter Roberson 2024년 3월 12일
편집: Walter Roberson 2024년 3월 12일
initial=[1 2];
nvars=2;
opts=optimoptions('ga','InitialPopulationMatrix',initial,'PopulationSize',1);
[z, f] = ga(@objfun,nvars,[],[],[],[],[],[],[],opts);
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.
disp(z)
1 2
function f = objfun(X)
% Create complex value from real and imaginary
z = X(:, 1) + i*X(:, 2);
f = z.^2 - z + 1;
f = abs(f);
end
A population as small as 1 is likely to cause problems.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by