wildart / Evolutionary.jl

Evolutionary & genetic algorithms for Julia
Other
322 stars 61 forks source link

Return of status #71

Open craftsmanhe opened 3 years ago

craftsmanhe commented 3 years ago

Hi, I am wondering how can I get the status from the result variable, is there a function call on result and return the status: success or failure? Thanks.

wildart commented 3 years ago

converged(result)

craftsmanhe commented 3 years ago

Thanks. But converged(result) only give true or false. I would like get the information when I type result and hit enter in Julia REPL, it show the reason why the algorithm stop, e.g. Status: success or Status: failure (reached maximum number of iterations). How can I get this information?

wildart commented 3 years ago

Look at the OptimizationResults interface, you may find what you need there.

craftsmanhe commented 3 years ago

Thanks a lot. I tried them. I would like to know why the algorithm stop, but looks no one works.

wildart commented 3 years ago

I would like to know why the algorithm stop

That would depend on a problem you're trying to solve. I assume you didn't get a desired result which prompted this issue. There are many things that affect the outcome of the optimization: choice of algorithm, its initial conditions & parameters. Depending of the parameter combination, the performance of the algorithm can widely vary.

I can only comment on the mechanics of termination condition. There are two termination conditions: a) the algorithm ran over specified number of the iterations, and b) the algorithm reached the specified tolerance level. In any case, you first check if the algorithm converged with converged(result). Then:

In addition, you may want to setup the trace to gather information about the optimization process which may give you more insights. See tests for examples.

craftsmanhe commented 3 years ago

Thanks a lot for the kind explanation. I can get a desired result at most of the time. The reason I would like that it returns some information because at some specific settings, e.g. different iterations or I selected a weird parameter range, the algorithm fails. I do this specific setting in a for loop, so I would like it return something and I can print in the loop.

By your help, I add the converged(result), iteration_limit_reached(result) and tol(result). I have one more question, if converged(result) is true, it means the algorithm is success and iteration_limit_reached(result) is false. And if converged(result) is false, it means that the algorithm is failed for what ever reason?

wildart commented 3 years ago

so I would like it return something and I can print in the loop.

The debug trace can be enabled through the the show_trace parameter in the Options object, see here https://wildart.github.io/Evolutionary.jl/dev/tutorial/#General-options-1. For more detailed trace specify a trace function. See also how it's done in here https://github.com/wildart/Evolutionary.jl/blob/master/test/onemax.jl

I have one more question, if converged(result) is true, it means the algorithm is success and iteration_limit_reached(result) is false.

That means you reach some minimum within the specified number of the iterations, which is a good thing. But you need to inspect the solution in case if it's a local minima.

And if converged(result) is false, it means that the algorithm is failed for what ever reason?

It could be the case, but it depends on a problem setup. Maybe the optimal solution was found but your tolerance level is too low, so the algorithm continues to refine it, and unable to do that in the specified number of the iterations. Or the optimization on the right track to discover the optimal solution, but the changes in the population are small, and so it take more iterations of the algorithm to reach the global minimum. You need to experiment with various parameters and verify the result at the end.

craftsmanhe commented 3 years ago

Thanks for the kind explanation. I got the idea.