[SciPy-dev] Bugs in scipy.optimize

Ed Schofield schofield at ftw.at
Wed Jul 21 14:21:50 CDT 2004


Hi all,

I've uncovered one bug and two "buglets" in scipy.optimize v0.3

---- BUG 1 ----
Arguments passed as 'args' to fmin_powell() get mangled.

The following code illustrates the problem:

from Numeric import array
from scipy import optimize

params = array([3.0, 6.0])

def f(x,params):
    return (x-params[0])**2

x0 = 0.0

result1 = optimize.fmin(f, x0, args=(params,))

result2 = optimize.fmin_cg(f, x0, args=(params,))

result3 = optimize.fmin_bfgs(f, x0, args=(params,))

result4 = optimize.fmin_powell(f, x0, args=(params,))

The first three routines work without error.  The fmin_powell function
throws an exception:

  File ".../optimize/optimize.py", line 1389, in _myfunc
    return func(*funcargs)
TypeError: f() takes exactly 2 arguments (1 given)


The argument tuple is unpacked incorrectly.  I suggest changing the line
in _linesearch_powell() in optimize.py from:

    extra_args = (func, p, xi) + args

to
    extra_args = (func, p, xi) + (args,)

This seems to work.  Otherwise a star operator (*args) in the right place
might do the job.


---- BUG 2 ----
The output of the fmin() ("result1" above) is a scalar
>>> result1
3.0000000000000031

whereas the other outputs result2, result3, and (when it works) result4
are Numeric arrays:
>>> result2
array([ 3.])

These ought to be consistent.


---- BUG 3 ----
A line in the docstring comment for fmin_powell() is wrong.  Instead of
reading:

    Outputs: (xopt, {fopt, xi, direc, iter, funcalls, warnflag},
{allvecs})

it should read:

    Outputs: (xopt, {fopt, direc, iter, funcalls, warnflag},
{allvecs})

(No xi parameter is returned.)


Best wishes,
Ed Schofield




More information about the Scipy-dev mailing list