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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Odette
am 11 Mär. 2024
Kommentiert: Odette
am 12 Mär. 2024
[z, f] = ga(@objfun,2);
disp(z)
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
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Mär. 2024
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 Kommentare
Walter Roberson
am 12 Mär. 2024
Bearbeitet: Walter Roberson
am 12 Mär. 2024
initial=[1 2];
nvars=2;
opts=optimoptions('ga','InitialPopulationMatrix',initial,'PopulationSize',1);
[z, f] = ga(@objfun,nvars,[],[],[],[],[],[],[],opts);
disp(z)
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surrogate Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!