Reputation: 534
I have a function with 2 variables and I try to minimize it using L-BFGS-B method.
def f(x,y):
z = exp(x + y)
return z
My arguments are numpy arrays, x0 is (0,0). I try something like:
res = minimize(f,x0,args=(x,y), method = "L-BFGS-B")
and get the error saying I give 3 arguments instead of 2. What is going wrong?
Upvotes: 0
Views: 462
Reputation: 20765
The args
parameter is for passing in extra data to your objective function. In your case, the objective function should take one argument: the point at which it should be evaluated as an array. For instance:
def f(x):
return np.exp(x.sum())
minimize(f, [0,0], bounds=[[-5,None], [-5,None]])
I imagine that you're optimizing a function other than the exponential, right? Because minimizing it is obviously trivial...
Upvotes: 1