Scipy Minimize: How To Pass Args To Both The Objective And The Constraint
My MWE is as follows def obj(e, p): S = f(e) + g(p) return S I would like to minimize this function over only e and pass p as an argument to the function. However, I also
Solution 1:
Okay, I figured that it's a mix of syntax errors on my part and how arguments should be passed. For those who may have the same question, I will post an answer here.
The objective function is obj(e, p)
. We only want to minimize e
so we create a tuple of the other arguments arguments = (0.5,)
. That is, a specific value of p=0.5
is set. Next define the constraint function
defprob_bound(e, p):
return -e - p + 1
Now one writes the constraints dictionary to be
cons = ({'type': 'ineq',
'fun': prob_bound,
'args': arguments
})
And finally, one calls the minimizer
result = minimize(obj, initial_guess, method = 'SLSQP', args = arguments, constraints = cons)
Post a Comment for "Scipy Minimize: How To Pass Args To Both The Objective And The Constraint"