Take the 2-minute tour ×

I recently started working with scipy.optimize and I am unclear why in fmin_cg, at start-up, sets the 'previous' value of the function to a fixed value depending on the current function value

xk = x0
old_fval = f(xk)
old_old_fval = old_fval + 5000

which circumvents the way the line search functions later in the code deal (more correctly?) with this situation. Surely it should say:

xk = x0
old_fval = f(xk)
old_old_fval = None

Or did I miss something, there?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Yes, it probably should be None. Looking a bit further in the code, both values however seem to lead to using 1.0 as the initial step size, but having "magic" numbers in code is just bad style even if happens to work.

Want to submit a patch? (Nowadays we prefer pull requests also for small changes over patches, though, and it's not much more work.)

share|improve this answer
Thank you for confirming that. The code leading to an initial step size of 1.0 ( and fixed max/min step sizes ) is another small issue I came across. Having very small amplitudes in my gradients makes large step sizes necessary which never are achieved because of the max step size limit of 50 (another option is scaling of the gradient, though). –  Philip Apr 15 '13 at 14:11

Your Answer


