Borrar filtros
Borrar filtros

ga optimization changing answer

2 visualizaciones (últimos 30 días)
shirin mhd
shirin mhd el 11 de Mayo de 2022
Comentada: shirin mhd el 11 de Mayo de 2022
Hi everyone
I have a question about GA optimization answer.
I want to optimize this function with 5 variable, as below:
Q=ga(@(b) -(-1e-6*((b(1))^2)+5.69e2*(b(1))+...
-1e-6*((b(2))^2)+8e2*(b(2))+...
-1e-6*((b(3))^2)+4e2*(b(3))+...
-1e-6*((b(4))^2)+4e2*(b(4))+...
-1e-6*((b(5))^2)+5e2*(b(5))),5)
at first i run the code and the answer was what you can see below:
Optimization terminated: maximum number of generations exceeded.
Q =
1.0e+03 *
1.6325 2.2597 1.5050 1.4811 1.4940
i run the code for second time and the answer changed to:
Optimization terminated: maximum number of generations exceeded.
Q =
1.0e+03 *
1.8045 2.3893 1.4345 1.5154 1.5075
and for the third time the answer was:
Optimization terminated: maximum number of generations exceeded.
Q =
1.0e+03 *
1.8864 2.3098 1.4213 1.5103 1.2786
as you can see, the answer for each run was changed. why is this happening? I know that ga uses several iterations to obtain the answer, but I thought that the final answer is unique and fixed. am I doing something wrong? could you please explain this result for me?

Respuesta aceptada

Chunru
Chunru el 11 de Mayo de 2022
GA need random initialization of population and it also involves random processing in generating children. Therefore, the results of different run may be different. To make the result reproducible, you need to reset the random generator before each run. For example:
rng default
Q=ga(@(b) -(-1e-6*((b(1))^2)+5.69e2*(b(1))+...
-1e-6*((b(2))^2)+8e2*(b(2))+...
-1e-6*((b(3))^2)+4e2*(b(3))+...
-1e-6*((b(4))^2)+4e2*(b(4))+...
-1e-6*((b(5))^2)+5e2*(b(5))),5)
Optimization terminated: maximum number of generations exceeded.
Q = 1×5
1.0e+03 * 1.8729 2.0826 1.6439 1.5220 1.7711
rng default
Q=ga(@(b) -(-1e-6*((b(1))^2)+5.69e2*(b(1))+...
-1e-6*((b(2))^2)+8e2*(b(2))+...
-1e-6*((b(3))^2)+4e2*(b(3))+...
-1e-6*((b(4))^2)+4e2*(b(4))+...
-1e-6*((b(5))^2)+5e2*(b(5))),5)
Optimization terminated: maximum number of generations exceeded.
Q = 1×5
1.0e+03 * 1.8729 2.0826 1.6439 1.5220 1.7711

Más respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by