Ask Your Question
1

set minimize function/value-tolerance

asked 2011-10-13 04:12:05 +0100

Xaver gravatar image

Hi,

can I somehow set function/value tolerances in sages minimizer? From sage's help(minimize) I don't see how.

sage: help(minimize)
minimize(func, x0, gradient=None, hessian=None, algorithm='default', **args)

The Problem: even for a trivial function with a 'shallow' minimum, say,

sage: f=(x-1)^10
sage: minimize(f,[.5])
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 11
         Function evaluations: 12
         Gradient evaluations: 12
(0.790308276599)

That's not optimal. Sage seems to have some rather moderate default tolerances preset.

B.t.w. that's not the case in SciPy:

~> ipython -pylab -wthread
In [1]: from scipy.optimize import fmin
In [2]: def f(x):
   ...:     return (x-1.)**10
In [3]: fmin(f,.5)
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 16
         Function evaluations: 32
Out[3]: array([ 1.])

So, Python's default tolerance is much stricter, even though, in principle, in that case I could change default tolerances.

In [4]: help(fmin)
fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None)

Finally, not speaking of Mathematica ;):

In[1]:= NMinimize[(x - 1)^10, x]
Out[1]= {1.11155*10^-68, {x -> 1.}}

Thanks for your help,

Xaver

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2011-10-13 08:08:05 +0100

Jason Grout gravatar image

If you use the algorithm="simplex" option, it uses the optimize.fmin command, and passes any arguments you specify into fmin. The simplex method is default for python functions, but the bfgs method is default for symbolic expressions.

sage: minimize(f,[.5],algorithm='simplex')
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 16
         Function evaluations: 32
(1.0)
sage: def callback(xk): 
....:     print xk
....:     
sage: minimize(f,[.5],algorithm='simplex',callback=callback)
[ 0.575]
[ 0.675]
[ 0.875]
[ 1.075]
[ 0.975]
[ 0.975]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 16
         Function evaluations: 32
(1.0)
edit flag offensive delete link more

Comments

Ok. That's what I was looking for. Xaver

Xaver gravatar imageXaver ( 2011-10-13 12:00:17 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-10-13 04:12:05 +0100

Seen: 2,279 times

Last updated: Oct 13 '11