0

I'm trying to work with SciPy optimize.minimize usign several variables and I found a great explanation in: Structure of inputs to scipy minimize function in the case when the obective function is of the kind f(x,y) and the parameter to be optimizated is "x". But a question arises: What if my objective function is of the kind f(x,y,z,u,v) and I want to optimze with respect to "y" and "u" (provided that f returns a scalar).

Community
  • 1
  • 1
Lejos Gane
  • 49
  • 1
  • 5

1 Answers1

1

Just create a new function with target variables going first in the list of parameters:

def g(y, u, x, z, v):
    return f(x, y, z, u, v)

(or use an analogous lambda).

fjarri
  • 9,546
  • 39
  • 49
  • can you tell me more about of the lambda function? – Lejos Gane Apr 07 '16 at 03:19
  • There's not much to say, it may be a bit more readable if your function is very short and you only need it once. See [python docs on it](https://docs.python.org/3.5/tutorial/controlflow.html#lambda-expressions). In your case it would be something like `minimize(lambda y, u, x, z, v: f(x, y, z, u, v), args=(x0, z0, v0))` – fjarri Apr 07 '16 at 03:28