From the source code of scipy, rhok is,
rhok = 1.0 / (numpy.dot(yk, sk))
where both yk
and sk
depend on intput array x0
.
A possible causes of this error may be a bad choice of initial condition x0
which tends to singularities in your function f
. I would suggest plotting your function and maybe ensuring initial conditions are always away from possible divergent values. If this is part of a larger training routine, you could possibly use try
and on catching an ZeroDivisionError
try shifting the initial condition shifted by some amount. You may also find a different minimisation method is more robust from scipy minimize.
If you add the full_output
option to scipy.optimize.fmin_bfgs
it should give you more information about you particular case.