[SciPy-user] optimize.fmin_powell and extra arguments

Klaus Maisinger maising at mrao.cam.ac.uk
Thu Nov 11 11:50:00 CST 2004


Dear SciPy experts,

the following little test script causes errors on the last two lines for 
fmin_powell, but not for fmin. Did I get the calling convention wrong 
(SciPy 0.3.2, Numeric 23.6, Python 2.2.2, RH9)?

Cheers,
Klaus

################################################################
from scipy import *

def fun(x,y):
     return x*x+y

def fun2(x,y,z):
     return x*x+y[0]+z[0]

a=array([1,2])
b=array([3,4])
print optimize.fmin(fun, [ 2.], (4.,))
print optimize.fmin(fun2, [ 2.], (a,b))
print optimize.fmin_powell(fun, [ 2.], (4.,))
print optimize.fmin_powell(fun2, [ 2.], (a,b))
###############################################

Output:

Optimization terminated successfully.
          Current function value: 4.000000
          Iterations: 18
          Function evaluations: 36
[ -1.77635684e-15]
Optimization terminated successfully.
          Current function value: 4.000000
          Iterations: 18
          Function evaluations: 36
[ -1.77635684e-15]
Traceback (most recent call last):
   File "./test_fun.py", line 15, in ?
     print optimize.fmin_powell(fun, [ 2.], (4.,))
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1491, in fmin_powell
     fval, x, direc1 = _linesearch_powell(func, x, direc1, args=args, 
tol=xtol*100)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1420, in _linesearch_powell
     full_output=1, tol=tol)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1196, in brent
     xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1354, in bracket
     fa = apply(func, (xa,)+args)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1410, in _myfunc
     funcargs = (x0 + alpha * direc,)+args
TypeError: can only concatenate tuple (not "float") to tuple



or (if I comment out the penultimate line):

Traceback (most recent call last):
   File "./test_fun.py", line 15, in ?
     print optimize.fmin_powell(fun2, [ 2.], (a,b))
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1491, in fmin_powell
     fval, x, direc1 = _linesearch_powell(func, x, direc1, args=args, 
tol=xtol*100)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1420, in _linesearch_powell
     full_output=1, tol=tol)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1196, in brent
     xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args)
   File "/usr/lib/python2.2/site-packages/scipy/optimize/optimize.py", line 
1354, in bracket
     fa = apply(func, (xa,)+args)
TypeError: _myfunc() takes at most 5 arguments (6 given)





More information about the SciPy-user mailing list