[SciPy-User] Setting an absolute tolerance to fmin_l_bfgs_b

Pauli Virtanen pav at iki.fi
Thu Jun 23 09:21:35 EDT 2011


Thu, 23 Jun 2011 12:42:21 +0100, Jose Gomez-Dans wrote:
[clip]
> I have ways to calculate the uncertainty in the parameters
> post-optimisation and I would rather the optimisation stopped once the
> function is under a given threshold. In the fortran version, I just have
> an if statement and bail out of it, but I was wondering whether the
> scipy version has something similar (the docs imply that you can only
> tweak m, pgtol and factr). Any ideas?

You can bail out by raising an exception in the evaluation function
and catching it outside.

-----------------------------------------------------

class Bailout(Exception):
    def __init__(self, x, f):
        self.x = x
        self.f = f

...

def func(x):
    ...
    if abs(f) < atol:
        raise Bailout(x, f)
    return f

try:
    x, f, d = fmin_l_bfgs_b(func, x0)
except Bailout, e:
    x = e.x
    f = e.f




More information about the SciPy-User mailing list