[SciPy-user] fmin_bfgs - Loglik Estimation leads to strange error

Benjamin Eberlei kontakt@beberlei...
Wed Aug 13 17:07:28 CDT 2008


Hello everybody,

i am quite new to numpy/scipy and currently porting some algorithms i wrote
for Ox to python and run into a very strange error inside the bfgs
optimization algorithm I cannot track down. I want to estimate Log
Liklihood functions from different distributions. I prepared a small
snippet:

class fLoglik(object):
    def __init__(self, y):
        self._y = asmatrix(y).T
        pass
    
    def __call__(self, params):
        print params
        y = self._y
        a = _exp(-(params[0] * y))
        return asmatrix(a)
        
f = fLoglik( _log(data[:,16]) )

params = array(ones((1,1)))
max = fmin_bfgs(f, params)

data is a matrix so the input comes in correct. The fLoglik.__call__ is
called twice before a ValueError occurs exactly as in the following
backtrace:

[ 1.]
[ 1.00000001]

Traceback (most recent call last):
  File "/var/www/workspace/pydiplom/src/diploma/weibull.py", line 42, in
<module>
    max = fmin_bfgs(f, params)
  File "/usr/lib/python2.5/site-packages/scipy/optimize/optimize.py", line
723, in fmin_bfgs
    gfk = myfprime(x0)
  File "/usr/lib/python2.5/site-packages/scipy/optimize/optimize.py", line
95, in function_wrapper
    return function(x, *args)
  File "/usr/lib/python2.5/site-packages/scipy/optimize/optimize.py", line
617, in approx_fprime
    grad[k] = (f(*((xk+ei,)+args)) - f0)/epsilon
ValueError: setting an array element with a sequence.

What is weird to me, the first two function calls to fLoglik are correct,
that is the output [1] and [ 1.00000001] you see comes from the call func.

Does somebody maybe know thats going on?



More information about the SciPy-user mailing list