I am using SciPy differential_evolution to solve an optimization problem. I have a web application that I want to show the progress in. What would be a good technique for giving intermediate feedback of the optimization process? Does SciPy support the yield keyword?
Python SciPy differential_evolution yield progress
36 views Asked by simonmarien AtThere are 2 answers
On
You can gain feedback on solver process by providing a callback:
A callable called after each iteration. Has the signature:
callback(intermediate_result: OptimizeResult)where intermediate_result is a keyword parameter containing an OptimizeResult with attributes x and fun, the best solution found so far and the objective function. Note that the name of the parameter must be intermediate_result for the callback to be passed an OptimizeResult.
The callback also supports a signature like:
callback(x, convergence: float=val)val represents the fractional value of the population convergence. When val is greater than 1.0, the function halts.
Introspection is used to determine which of the signatures is invoked.
Global minimization will halt if the callback raises StopIteration or returns True; any polishing is still carried out.
That intermediate_result will also contain the current population.
differential_evolution does not use yield. However, the internal solver backend is an iterator. This backend is considered private.
No, the
differential_evolutionfunction in SciPy does not directly support theyieldkeyword for providing intermediate feedback during the optimization process.However, you can implement a custom callback function that prints out or logs the optimization progress at each iteration. You can use this callback function to provide feedback to your web application. Here's an example of how you can do it:
In this example, the
callbackfunction is called at each iteration of the optimization process. It prints out the iteration number, the current best solution, the value of the objective function at the best solution, and the convergence status. You can modify this function to log the progress or send it to your web application as needed.