Currently I have the following code that defines the function f
.
a = #something b = #something c = #something def f(x): """Evaluates some function that depends on parameters a, b, and c""" someNumber = #some calculation return someNumber
Ideally I would do def f(x, a, b, c)
, BUT I am minimizing f
with respect to x
and SciPy's optimization toolbox doesn't allow for one to minimize functions with parameters in the arguments. That said I would like to run my minimization code for multiple values of a, b
and c
. Is there a way I can do this?
To minimize the function we can use "scipy. optimize. minimize" function and further there are some methods we can use to minimize the function. Build a Chatbot in Python from Scratch!
One of these linear functions is the objective function. The objective function is a means to maximize (or minimize) something.
jac : bool or callable, optional Jacobian (gradient) of objective function. Only for CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg. If jac is a Boolean and is True, fun is assumed to return the gradient along with the objective function.
SLSQP optimizer is a sequential least squares programming algorithm which uses the Han–Powell quasi–Newton method with a BFGS update of the B–matrix and an L1–test function in the step–length algorithm.
You can specify additional arguments in args
from scipy.optimize import minimize minimize(f, x0, args=(a, b, c))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With