Structure of inputs to scipy minimize function

前提是你 提交于 2019-11-27 11:49:31

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!