[SciPy-User] optimize.fmin_l_bfgs_b wrong number of arguments
ilan barak
ibarak2000 at yahoo.com
Sun Jul 22 12:22:47 EDT 2012
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)
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
More information about the SciPy-User
mailing list