genetic algorithm with different results at each run
조회 수: 19 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2019년 1월 20일
Use rng() to set the random number generator to a known value.
댓글 수: 3
Walter Roberson
2019년 1월 20일
rng() sets the seed not the limits of random generation. Roughly speaking, it affects the order that random numbers are generated in.
추가 답변 (2개)
John D'Errico
2019년 1월 19일
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
Walter Roberson
2019년 1월 20일
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
2019년 1월 20일
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
2019년 1월 20일
댓글 수: 2
kam Pal
2021년 10월 18일
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
2021년 10월 18일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!