GA initial solution not used in problem base solver
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I am using ga with integer variables to solve a minimization problem. I started by using a single point as the initial guess, but found out that it was not used, as ga resulted in worse solutions than the initial point. After this I tried with a population, but it did as poorly, losing to the original solution I had.
After this, I tried the example for initial population generation for GA when using solve(). Example is the first one in this link Create values for optimization problem - MATLAB optimvalues - MathWorks Nordic
I modified the example to include the best solution it finds with default rng and also to display each iteration. My script for this is below, with my additions commented. I concluded that having the best solution (x,y) = (1,1) in the initial population does not change the output, which to me seems that it is not actually using the given population. Same result with a single point guess.
Am I making some mistake, or is the initial population actually ignored here? I am using R2022b.
%%
clc
x = optimvar("x",LowerBound=-5,UpperBound=5);
y = optimvar("y",LowerBound=-5,UpperBound=5);
rosenbrock = (10*(y - x.^2)).^2 + (1-x).^2;
prob = optimproblem(Objective=rosenbrock);
rng default % For reproducibility
xval = -5 + 10*rand(1,100);
yval = -5 + 10*rand(1,100);
xval(1) = 1; %The best
yval(1) = 1; %solution
x0.x = 1; %The best solution for
x0.y = 1; %single point guess
vals = optimvalues(prob,x=xval,y=yval);
opts = optimoptions("ga",PopulationSize=100,Display="iter"); %Added 'iter' display
[sol,fv] = solve(prob,vals,Solver="ga",Options=opts)%Use x0 or vals as 2nd argument
0 Kommentare
Antworten (2)
Nikhilesh
am 9 Mär. 2023
It seems that you have correctly modified the example code to add a custom initial population and display the iterations. Regarding your question, the initial population is indeed used by the genetic algorithm solver, but there is no guarantee that any of the solutions in the initial population will be selected to create the next generation. The genetic algorithm solver starts by evaluating the fitness of each individual in the population, and then uses selection, crossover, and mutation operators to create the next generation of solutions. The selected individuals are not necessarily the fittest individuals from the previous generation, but rather a probabilistic selection process is used to favor fitter individuals. This means that even if you include the best solution in the initial population, it may not be selected to create the next generation if it is not one of the fittest individuals.
Alan Weiss
am 10 Mär. 2023
When using the problem-based approach you must pass initial points to ga using optimvalues. See https://www.mathworks.com/help/releases/R2022a/gads/global-initial-points.html
Alan Weiss
MATLAB mathematical toolbox documentation
2 Kommentare
Alan Weiss
am 13 Mär. 2023
Thanl you for letting me know about the typo. I'll fix it in the next release.
Alan Weiss
MATLAB mathematical toolbox documentation
Siehe auch
Kategorien
Mehr zu Genetic Algorithm 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!