[SciPy-Dev] suggest a class Stop to unify fmin* convergence and output

denis denis-bz-gg@t-online...
Thu Dec 13 12:52:04 CST 2012


Optimizer folks,

  would a class Stop help unify the different conevergence criteria in fmin* ?
Today (12.1) some have maxiter ftol and xtol, others have ...
https://github.com/denis-bz/opt/tree/master/util/stopmod.py
is a 1-page prototype, doc below.

Stop() is also an easy hook for uniform verbose= output
to help people track what an optimizer is doing, e.g.
    ...
    iter 16 cost 121  f 4.64997     df .00288   x -.507 .266 ...
    iter 17 cost 128  f 4.64855     df .00142   x -.507 .268 ...
    Stop Rosenbrock-dim5 ftol met: iter 18 cost 135  f 4.64783  df .00072   x
-.506 .269 ...

https://github.com/denis-bz/opt/tree/master/scopt/bfgs
has an fmin_bfgs using Stop, and example logs on Rosenbrock 5dim and 10dim.
(Sorry if the git stuff is mangled -- git noob.)

cheers
  -- denis


    class Stop:
        """ Stop( maxiter, ftol, verbose ... ): a class for convergence tests

        Example
        -------
            stop = Stop( maxiter=  ftol=  xtol=  verbose= ... )
            while 1:
                ... optimization loop ...
                if stop( iter, f=f, x=x ):  # compare, print
                    break
                ...
               ...

        Parameters
        ----------
        maxiter : stop if iter >= maxiter
        ftol : stop if fprev - ftol <= f <= fprev
                -- for minimizing, f decreasing
        xtol : stop if average |x - xprev| <= xtol
        maxcost, func : stop if func.cost >= maxcost.  E.g.
            def func():
                func.cost += 1
                ...
            func.cost = 0  # init outside
        verbose :
            print the stop reason when done, like
                Stop ftol met: iter 18 cost 135  f 4.64783  x ...
            default verbose=2: print iter f x on each iteration



More information about the SciPy-Dev mailing list