Mahfuz
Mahfuz

Reputation: 11

How to save the parameters values of a function of every iteration in differential evolution Optimization

I'm comparatively new in python. I want to optimize a function with differential_evolution which has 11 parameters and these parameters have a bound(min,max). How can I save the parameters values after every iteration. Suppose if I put maxiter=100, I want to save all my changing parameters. Until now I got the optimum result(parameters) but couldn't find a way that will save the changing parameters.

Upvotes: 1

Views: 1119

Answers (1)

Hugh Ward
Hugh Ward

Reputation: 121

The scipy differential_evolution function contains a callback parameter which runs after each iteration.

From scipy.optimize.differential_evolution Documentation:

callback : callable, callback(xk, convergence=val), optional A function to follow the progress of the minimization. xk is the current value of x0. val represents the fractional value of the population convergence. When val is greater than one the function halts. If callback returns True, then the minimization is halted (any polishing is still carried out).

So the function you run after each iteration would be for example:

def printCurrentIteration(xk, convergence):
    print('finished iteration')
    print(xk)
    print(convergence)

Called like this:

result = differential_evolution(objectiveFunction,
                                bounds,
                                args=data,
                                callback=printCurrentIteration)

Upvotes: 1

Related Questions