ga optimization changing answer
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Chunru
le 11 Mai 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)
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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!