[SciPy-user] bug in fmin_bfgs?

David M. Cooke cookedm at physics.mcmaster.ca
Wed Jan 26 17:59:51 EST 2005


Jason Rennie <jrennie at csail.mit.edu> writes:

> On Mon, Jan 24, 2005 at 03:55:01PM -0500, Jason Rennie wrote:
>> Is fmin_bfgs not meant to be used with multidimensional arrays?
>
> Inspection of the scipy code answers my question: no it was not meant
> to be used with multidimensional arrays...
>
> Correct me if I'm wrong, but it doesn't look like it (I'm looking at
> lbfgsb.py) would be difficult to make it work with multdimensional
> parameter vectors...

BTW, fmin_bfgs != lbfgsb.fmin_l_bfgs_b

fmin_bfgs is defined in Lib/optimize/optimize.py in the scipy code.

What you could is flatten and reshape the parameter vectors:

x0 = <a multidimensional array>
flat_x0 = ravel(x0)
flat_xopt = fmin_bfgs(f, flat_x0, args=(x0.shape,) ...)
xopt = resize(flat_xopt, x0.shape)

and in your definition of f:
def f(flat_x, shape):
    x = resize(flat_x, shape)
    ... do stuff with our multi-dimensional x ...

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the SciPy-User mailing list