Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimize function with parameters

Tags:

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?

like image 708
Nate Stemen Avatar asked Mar 25 '17 14:03

Nate Stemen


People also ask

How do you minimize a function in Python?

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!

Which function do we use to maximize or minimize an object write it along with the parameters?

One of these linear functions is the objective function. The objective function is a means to maximize (or minimize) something.

What is JAC in Scipy minimize?

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.

What is Slsqp?

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.


1 Answers

You can specify additional arguments in args

from scipy.optimize import minimize  minimize(f, x0, args=(a, b, c)) 
like image 177
Liteye Avatar answered Nov 14 '22 12:11

Liteye