3

As you may know, the lmfit module in python is convenient to extend capabilities of scipy.optimize functionnalities.

However I don't find something that seems to me necessary: the possibility to choose the step sizes (used for partial derivations, computation of the chi2 in parameter space, etc...) . I used to play with the steps when I was fitting under IDL and I am very surprised I don't find this under python.

It seems obvious that the default steps, which are very small, may lead to a constant chi2 when fitting a rough model... and thus are awkward.

So my question: how to choose the steps when fitting under python ?

Stéphane
  • 1,389
  • 3
  • 13
  • 34
  • In several optimizers such as ```scipy.optimize.fmin_bfgs```, there is a parameter called ```epsilon``` that controls the step size when the gradient is estimated by finite difference. If you use ```minimize```, you can pass it in the argument ```options``` (dict). Also, a clear example of input data and what you want to achieve would be better. – Kefeng91 May 25 '18 at 11:25
  • thanks, I will look into options and post a clear example – Stéphane May 25 '18 at 13:40

1 Answers1

5

lmfit's minimizer can wrap several of the optimizers from scipy.optimize. Unfortunately, there is not a very uniform interface to the various solvers, especially for options like step sizes, tolerances, and stopping conditions. That's partly because the algorithms are actually different, and partly because scipy.optimize itself wraps a lot of older code.

That said, the default solver with lmfit is scipy.optimize.leastsq, or MINPACK-1, which is very similar to the (very nice, as I recall) MPFIT package for IDL. As with those codes, you can specify the initial step used for calculating the partial derivatives with epsfcn.

To do that with lmfit sort of depends on how you're using lmfit. One way to do it is

result = lmfit.minimize(objective_function, params, args=(x, data),
                        epsfcn=0.001)

For a more detailed answer, please give a more detailed question.

M Newville
  • 7,486
  • 2
  • 16
  • 29
  • thx. yes, I used mpfit a bunch of times and was happy with it. your 'epsfcn' proposition is a start but it looks this is one absolute step for all variables... I used to control the value, the forward-backward scheme and the relative-absolute scheme for each variable independently... – Stéphane May 28 '18 at 20:15
  • Actually, epsfcn is used by MINPACK as a relative change in each parameter's value for estimating the partial derivative for that parameter. The finite-difference derivative computed in this way are then used to estimate the step taken in the fit. You don't set the step size per variable with MINPACK/leastsq. But, short of providing your own derivative function, you will have a difficult time beating its performance. – M Newville May 30 '18 at 00:04