genetic algorithm with different results at each run

11 次查看(过去 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.

采纳的回答

Walter Roberson
Walter Roberson 2019-1-20
Use rng() to set the random number generator to a known value.
  3 个评论
Walter Roberson
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
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
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
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
Thanks a lot for your support.
It works fine with me
Regards,
A.Shereiqi
  2 个评论
kam Pal
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
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 CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by