[SciPy-User] Minimization of a function that can return nan
I'm using fmin_l_bfgs_b to find the best fit parameters for a system of ordinary differential equations. Since the system has multiple local minima, I found that it's very convenient to divide the parameter space in hypercubes, and perform multiple local minimizations.
Occasionally, for certain regions of the parameter space, the numerical integration routine fails. What's the correct way to handle this gracefully? Capture the exception, and return inf as the cost function value, and set the gradient to equal to all nan?