[SciPy-user] Correct syntax for optimize.fmin_powell

Dan Christensen jdc at uwo.ca
Mon Sep 12 21:23:36 CDT 2005


Robert Kern <rkern at ucsd.edu> writes:

> J. Stark wrote:
> 
>> I am typically trying to something like
>> 
>> def test_arg((x,y),(a,b)):
>>     return (x-a)**2 + (y-b)**2
>> 
>> min = optimize.fmin_powell(test_arg,(1.0,2.0), ((5.0,6.0),))
>> 
>> This works with optimize.fmin, but fails with optimize.fmin_powell.
>
> Works for me.
>
> In [2]: def test_arg((x,y),(a,b)):
>    ...:     return (x-a)**2 + (y-b)**2
>    ...:
>
> In [3]: min = optimize.fmin_powell(test_arg,(1.0,2.0), ((5.0,6.0),))

Doesn't work for me.  Debian, python 2.4.1, Debian's scipy packages:

ii  python2.4-scipy          0.3.2-6
ii  python2.4-scipy-core     0.3.2-3

exceptions.TypeError                                 Traceback (most recent call last)

/home/jdc/<console> 

/usr/lib/python2.4/site-packages/scipy/optimize/optimize.py in fmin_powell(func, x0, args, xtol, ftol, maxiter, maxfun, full_output, disp, retall)
   1495             direc1 = direc[i]
   1496             fx2 = fval
-> 1497             fval, x, direc1 = _linesearch_powell(func, x, direc1, args=args, tol=xtol*100)
   1498             if (fx2 - fval) > delta:
   1499                 delta = fx2 - fval

/usr/lib/python2.4/site-packages/scipy/optimize/optimize.py in _linesearch_powell(func, p, xi, args, tol)
   1424     extra_args = (func, p, xi) + args
   1425     alpha_min, fret, iter, num = brent(_myfunc, args=extra_args,
-> 1426                                            full_output=1, tol=tol)
   1427     xi = alpha_min*xi
   1428     _powell_funcalls += num

/usr/lib/python2.4/site-packages/scipy/optimize/optimize.py in brent(func, args, brack, tol, full_output, maxiter)
   1205     _cg = 0.3819660
   1206     if brack is None:
-> 1207         xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args)
   1208     elif len(brack) == 2:
   1209         xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args)

/usr/lib/python2.4/site-packages/scipy/optimize/optimize.py in bracket(func, xa, xb, args, grow_limit)
   1358     _gold = 1.618034
   1359     _verysmall_num = 1e-21
-> 1360     fa = apply(func, (xa,)+args)
   1361     fb = apply(func, (xb,)+args)
   1362     if (fa < fb):                      # Switch so fa > fb 

/usr/lib/python2.4/site-packages/scipy/optimize/optimize.py in _myfunc(alpha, func, x0, direc, args)
   1415 def _myfunc(alpha, func, x0, direc, args=()):
   1416     funcargs = (x0 + alpha * direc,)+args
-> 1417     return func(*funcargs)
   1418     
   1419 def _linesearch_powell(func, p, xi, args=(), tol=1e-3):

TypeError: test_arg() takes exactly 2 arguments (3 given)

Dan



More information about the SciPy-user mailing list