用于使功能最小化的输入的结构 [英] Structure of inputs to scipy minimize function

查看:78
本文介绍了用于使功能最小化的输入的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一些尝试使用scipy.optimize.minimize最小化功能的代码.我在理解funjac参数

I have inherited some code that is trying to minimize a function using scipy.optimize.minimize. I am having trouble understanding some of the inputs to the fun and jac arguments

最小化的调用看起来像这样:

The call to minimize looks something like this:

result = minimize(func, jac=jac_func, args=(D_neg, D, C), method = 'TNC' ...other arguments)

func如下所示:

def func(G, D_neg, D, C):
#do stuff

jac_func具有以下结构:

def jac_func(G, D_neg, D, C):
#do stuff

我不明白的是funcjac_func的G输入来自何处.是在minimize函数中以某种方式指定的,还是以method被指定为TNC的事实?我已经尝试对该优化函数的结构进行一些研究,但是在寻找所需答案时遇到了麻烦.任何帮助将不胜感激

What I don't understand is where the G input to func and jac_func is coming from. Is that somehow specified in the minimize function, or by the fact that the method is specified as TNC? I've tried to do some research into the structure of this optimization function but I'm having trouble finding the answer I need. Any help is greatly appreciated

推荐答案

简短的答案是G是优化程序维护的,它是最小化过程的一部分,而(D_neg, D, and C)参数是按原样从args元组.

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.

默认情况下,scipy.optimize.minimize接受一个函数fun(x),该函数接受一个参数x(可能是数组等)并返回标量.然后scipy.optimize.minimize找到一个参数值xp,对于x的其他值,fun(xp)小于fun(x).优化程序负责创建x的值,并将其传递给fun进行评估.

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.

但是,如果您碰巧有一个函数fun(x, y),该函数具有一些需要另外传递的附加参数y(但是出于优化目的,它被认为是常量)?这就是args元组的用途. 文档尝试解释args元组的用法,但解析起来可能有些困难:

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:

参数:元组,可选

传递给目标函数及其派生函数的额外参数(雅各布,黑森州).

Extra arguments passed to the objective function and its derivatives (Jacobian, Hessian).

有效地,scipy.optimize.minimize将使用星号参数表示法将args中的所有内容作为其余参数传递给fun:在优化过程中,该函数称为fun(x, *args).优化器会传递x部分,并给出args元组作为其余参数.

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.

因此,在您的代码中,G元素的值由优化程序维护,同时评估G的可能值,并且(D_neg, D, C)元组按原样传递.

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.

这篇关于用于使功能最小化的输入的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆