Correct syntax for optimize.fmin_powell
Can someone point me to the correct syntax for optimize.fmin_powell when the objective function takes side arguments. I have tried every possibility I can think of, most of which work fine for optimize.fmin, but keep getting error messages, mainly due to an incorrect number of arguments. I have looked at the source, but that hasn't helped. 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. Thanks Jaroslav
J. Stark wrote:
Can someone point me to the correct syntax for optimize.fmin_powell when the objective function takes side arguments. I have tried every possibility I can think of, most of which work fine for optimize.fmin, but keep getting error messages, mainly due to an incorrect number of arguments. I have looked at the source, but that hasn't helped.
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),)) Optimization terminated successfully. Current function value: 0.000000 Iterations: 2 Function evaluations: 22 -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
Robert Kern <rkern@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
Dan Christensen wrote:
Robert Kern <rkern@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:
[snip]
TypeError: test_arg() takes exactly 2 arguments (3 given)
Could you also copy-and-paste the code that you ran to yield this error? Because it looks to me like you may have executed min = optimize.fmin_powell(test_arg,(1.0,2.0), (5.0,6.0)) instead. -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
Robert Kern <rkern@ucsd.edu> writes:
Dan Christensen wrote:
TypeError: test_arg() takes exactly 2 arguments (3 given)
Could you also copy-and-paste the code that you ran to yield this error? Because it looks to me like you may have executed
min = optimize.fmin_powell(test_arg,(1.0,2.0), (5.0,6.0))
instead.
Nope, I copy-and-pasted the code from your message. And I've also had this bug affect me in completely different code as well. Just like the original poster, args works fine for all the other fmin* routines, but not for fmin_powell. Dan
Dan Christensen wrote:
Robert Kern <rkern@ucsd.edu> writes:
Dan Christensen wrote:
TypeError: test_arg() takes exactly 2 arguments (3 given)
Could you also copy-and-paste the code that you ran to yield this error? Because it looks to me like you may have executed
min = optimize.fmin_powell(test_arg,(1.0,2.0), (5.0,6.0))
instead.
Nope, I copy-and-pasted the code from your message.
And I've also had this bug affect me in completely different code as well. Just like the original poster, args works fine for all the other fmin* routines, but not for fmin_powell.
Dan
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
python -i powell.py results in Optimization terminated successfully. Current function value: 0.000000 Iterations: 2 Function evaluations: 22
min array([ 5., 6.])
BTW
scipy.__version__ '0.3.3_309.4626'
Nils
participants (4)
-
Dan Christensen -
J. Stark -
Nils Wagner -
Robert Kern