Structure of inputs to scipy minimize function
The short answer is that G
is maintained by the optimizer as part of the minimization process, while the (D_neg, D, and C)
arguments are passed in as-is from the args
tuple.
By default, scipy.optimize.minimize
takes a function fun(x)
that accepts one argument x
(which might be an array or the like) and returns a scalar. scipy.optimize.minimize
then finds an argument value xp
such that fun(xp)
is less than fun(x)
for other values of x
. The optimizer is responsible for creating values of x
and passing them to fun
for evaluation.
But what if you happen to have a function fun(x, y)
that has some additional parameter y
that needs to be passed in separately (but is considered a constant for the purposes of the optimization)? This is what the args
tuple is for. The documentation tries to explain how the args tuple is used, but it can be a little hard to parse:
args: tuple, optional
Extra arguments passed to the objective function and its derivatives (Jacobian, Hessian).
Effectively, scipy.optimize.minimize
will pass whatever is in args
as the remainder of the arguments to fun
, using the asterisk arguments notation: the function is then called as fun(x, *args)
during optimization. The x
portion is passed in by the optimizer, and the args
tuple is given as the remaining arguments.
So, in your code, the value of the G
element is maintained by the optimizer while evaluating possible values of G
, and the (D_neg, D, C)
tuple is passed in as-is.