[SciPy-user] number of function evaluation for leastsq

Achim Gaedke Achim.Gaedke@physik.tu-darmstadt...
Tue Apr 15 13:15:33 CDT 2008


I use scipy.optimize.leastsq to adopt paramters of a model to measured
data. Each evaluation of that model costs 1.5 h of computation time.
Unfortunately I can not specify a gradient function.

While observing the approximation process I found that the first 3 runs
were always with the same parameters. First I thought, the parameter
variation for gradient approximation is too tiny for a simple print
command. Later I found out, that these three runs were independent of
the number of fit parameters.

A closer look to the code reveals the reason (svn dir trunk/scipy/optimize):

1st call is to check with python code wether the function is valid

line 265 of minpack.py
m = check_func(func,x0,args,n)[0]

2nd call is to get the right amount of memory for paramters.

line 449 of __minpack.h
ap_fvec = (PyArrayObject *)call_python_function(fcn, n, x, extra_args,
1, minpack_error);

3rd call is from inside the fortran algorithm (the essential one!)

Unfortunately that behaviour is not described and I would eagerly demand
to avoid the superficial calls to the function.

Yours, Achim

More information about the SciPy-user mailing list