I am trying to use lmfit.minimize to minimize an objective function (which is a sum of squared error). I can use lmfit.minimize(function,params,args) to do it and it returns a Minimizer object with fit statistics. However, I want to see how the objective function value changes in each iteration.
I could print values in each iteration or plot individual residual values using an iteration callback function but I want to get the values of objective function as an array that I can later use/plot.
How can it be done ?
I am trying to get something like this:

Here's what you can do with the iterative callback function (using the example from the lmfit homepage):
and
itervalueswill have the values you're looking for, in progressive order. (There's often a high number at the start, when the algorithm is trying out different directions.)This uses the mutability of Python lists, since that's the only way
callbackcan changeitervalues; its return value is used for something different, so that can't be used to changeitervalues.