Hi Scott,
On Fri, Jun 19, 2015 at 1:35 PM, Scott Norris <
scott.no...@gmail.com> wrote:
>
> Hi,
>
> I am continuing to really enjoy using this library, so thanks again for the great code, documentation, and support!
>
> I am interested to learn more about the 'iter_cb' argument to minimize(), but I haven't been able to find much documentation for it. For instance,
>
> 1. exactly when is the callback function called during the fitting iteration?
Lmfit calls the minimization routine (say, scipy.optimize.leastsq()) with its own residual function. This does a few steps. First it updates all the parameter values with the ones sent from the minimizer function. Then it calls the user-supplied objective function. Then it calls the iteration callback, and finally returns the residual array as calculated by the user-supplied objective. This is all at
https://github.com/lmfit/lmfit-py/blob/master/lmfit/minimizer.py#L229In short: on each iteration, after the user-supplied objective function has returned.
> 2. what arguments does minimize() pass to the callback function by default?
The arguments sent to the iteration callback are (params, n_iter, resid, *args, **kwargs)
where params is the latest Parameters, n_iter is the iteration number, resid is the residual array from the objective function), and args and kwargs are the same ones sent to the objective function.
A simple example is at
https://github.com/lmfit/lmfit-py/blob/master/examples/doc_model_with_iter_callback.py> 3. can this list of arguments be customized?
Currently, no. You might be able to use kwargs for whatever you need though.
Hope that helps,
--Matt