[SciPy-User] optimize.fmin_l_bfgs_b wrong number of arguments

ilan barak ibarak2000@yahoo....
Mon Jul 30 10:09:04 CDT 2012

```Thanks Josef, you are correct

ilan

On 7/22/2012 7:30 PM, josef.pktd@gmail.com wrote:
> On Sun, Jul 22, 2012 at 12:22 PM, ilan barak <ibarak2000@yahoo.com> wrote:
>> Hello,
>> I apologize for the long description, this is the best I can do...
>>
>> I have two functions defined as:
>>
>> def hypothesis(params):
>>      # build a series of length params[0], with starting gap
>>      params[1] , repitition params[2] with sclae params[3]
>>      # using tt as the basic shape
>>      result=np.zeros(params[0])
>>      for index in
>>      np.arange(params[1],params[0]-tt.shape[0],params[2]):
>>          result[int(round(index)):int(round(index))+tt.shape[0]]=tt
>>      return params[3]*result
>>
>> def Cost(params,sig): #  starting gap params[0] , repitition
>>      params[1] with sclae params[2]
>>      # sig is signa;s to compare to
>>      # calculate error cost
>>      result=np.linalg.norm(sig-hypothesis([sig.shape[0]]+params))
>>      return result
>>
>> The Cost function requires a 3 parameter list and a signal that is a
>>      800 long ndarray
>> Running the Cost with:
>> params=([start,gap,0.04])
>> Cost(params,mysig5) , where mysig 5 is length 800 ndarray works
>>      fine.
>> However:
>> p0 = np.array([10.,20.,0.01]) # Initial guess for the parameters
>>      start,gap,scale
>> mybounds = [(0,20), (10,25), (0.001,0.1)]
>> x, f, d= optimize.fmin_l_bfgs_b(Cost, p0[:],fprime=None,
>>      args=mysig5, bounds=mybounds, approx_grad=True)
>
> args=(mysig5,)
>
> args should be a tuple
>
> I think
>
> Josef
>>
>> complains:
>>
>> Traceback
>>      <module>
>>      C:\Users\ilan\Documents\python\opt_detection_danny1.py    130
>>      fmin_l_bfgs_b
>>      C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py    199
>>      func_and_grad
>>      C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py    145
>> TypeError: Cost() takes exactly 2 arguments (801 given)
>>
>>
>> Where am I wrong
>>
>> thanks
>>
>> Ilan
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user

```

More information about the SciPy-User mailing list