genetic algorithm with different results at each run
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Abdullah Al Shereiqi
il 19 Gen 2019
Commentato: Walter Roberson
il 18 Ott 2021
I tried to run the code, but unfortunatelly I found different solutions at each run. How to solve the issue, although I am sure about the objective function.
This is for your kind support please.
0 Commenti
Risposta accettata
Walter Roberson
il 20 Gen 2019
Use rng() to set the random number generator to a known value.
3 Commenti
Walter Roberson
il 20 Gen 2019
rng() sets the seed not the limits of random generation. Roughly speaking, it affects the order that random numbers are generated in.
Più risposte (2)
John D'Errico
il 19 Gen 2019
A genetic algorithm is a stochastic algorithm, based on random sampling! What do you seriously expect?
No matter what, you will see small differences, even for a function that has a nice global min. So you can think of the results as all being effectively the same within a tolerance.
If you get different solutinos, you still need to accept that for a function that has multiple local minima, the solver can get trapped in different solutions. Sometimes they may all be equivalent solutions. For example, use any solver to minimize sin(x). Depending on the route to the solution and the start points, you will find different local minima, all of which are equivalent, none are better than the others.
3 Commenti
Walter Roberson
il 20 Gen 2019
Remember that ga never promises to find the global minima, just to use strategies that are sometimes useful in finding minima. Getting caught in local minima is something you should expect with ga.
John D'Errico
il 20 Gen 2019
Exacty. There is no absolute assurance that a genetic algorithm, or any optimization, will always result in the same solution, or the best possible solution.
The genetic algorithm is designed to improve that characteristic, as are other optimizers, like simulated annealing, PSO, etc. But they cannot assure you will get the same result always. And this is the behavior you are seeing.
As Walter said, you can set the random seed. But that will not assure the globally optimal solution results, merely that you get the same solution.
Abdullah Al Shereiqi
il 20 Gen 2019
2 Commenti
kam Pal
il 18 Ott 2021
Did you solve the issue by using random number generator?
Or did you use any other approach? From what I understood, the problem of getting different solutions is trapping in local minimas. I am having a similar issue. Would you please throw some light on this?
Kam
Walter Roberson
il 18 Ott 2021
They solved the problem of getting different solutions each time by using rng so that they will get the same results each time.
However there is no possible solution to the problem of ga or pso getting caught in local minima. Consider the function
f(x) = sin(x) - 2*(x==42971372.1673492437)
The global minimum is at that constant, and no numeric evaluation at any other location can possibly give any hint of the location of the minimum: if the evaluation does not happen to test exactly that one location then it will never find the minimum.
You need non-numeric methods such as calculus to solve such functions. But it can also be proven that even calculus is not enough.
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!