Skip to content
Advertisement

SciPy Minimize doesn’t pass all guesses on?

I am trying to minimize a function of two variables using SciPy. The function itself is a chain of multiple lambda functions (makes it complicated but unfortunately it is the easiest way to write the expressions I need).

However, when using SciPy’s minimize routine, I get the error “TypeError: () missing 1 required positional argument: ‘labour'”

Strangely enough, if I pass the arguments to the function directly, there is no error, so I assume that my chaining was correct.

Here is a minimum reproducible example:

JavaScript

For those knowledgeable of Dynamic Programming, I am trying to derive the value function of a growth model using Value Function iteration, but I didn’t get so far yet. The period payoff is given by utility_f_multi. The Value function guess is given by optimization_f, which takes in four arguments including the previous value function guess.

In my example, I generate an interpolation that is closer to the true value function, but for all intents and purposes the constant 0 function also suffices. I then go on to create the optimization problem given our state variable

JavaScript

Finally, I pass on the problem to the minimize function, from which the error results:

JavaScript

The message, as mentioned previously, is “() missing 1 required positional argument: ‘labour'”

However, if I just pass on the two arguments to the function by hand, I receive no issue

JavaScript

which returns a value without problems.

Any help on this issue would be appreciated!

Advertisement

Answer

The function that you pass to scipy.minimize must use a singular argument for all the numerical inputs.

Imaging you wrote your function like:

JavaScript

scipy will call:

JavaScript

rather than

JavaScript

You can use an additional lambda to unpack the arguments:

JavaScript

And also, unrelated to your question, you should look at CasADI to solve these types of questions

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement