为 scipy 最小化选择参数位置

Choose Argument position for scipy minimise

我有一个函数定义如下

def function(a, b, c, d):
    ### some calculation
    return output

我要使用 scipy.minimise 来最小化关于单独变量 a 的输出。有没有办法告诉它只求解第一个变量(同时保持 bcd 不变)。

谢谢。

来自 docs:

The objective function to be minimized: fun(x, *args) -> float

argstuple, optional: Extra arguments passed to the objective function and its derivatives (fun, jac and hess functions).

所以只需使用包装器(或重写函数中的定义和第一行):

def functionWrapper(x, args):
    a = x
    b,c,d = args
    return function(a,b,c,d)

和最小化调用

minimize(functionWrapper,initialGuess,(bValue,cValue,dValue,));

其中 bValuecValuedValue 是系数的常数值。