scikit-opt icon indicating copy to clipboard operation
scikit-opt copied to clipboard

非优化参数的传入

Open cumttc opened this issue 1 year ago • 2 comments

当使用目标函数时,有一些参数需要传入但不需要优化,例如:y=x[0]*b+x[1]**c+d x是需要优化的,但bcd是三个不需要优化的变量(需要传入目标函数)。在scipy库中用的是args{...},在sko中是如何实现的呢?

cumttc avatar Oct 23 '23 11:10 cumttc

我寻思这个不是目标函数内部实现吗

aak1247 avatar Jan 05 '24 16:01 aak1247

你可以选择 curry 化把你的目标函数修改一下,比如你的目标函数image,你可以用lambda把参数 b,c,d都固定住:

b = 1
c = 2
d = 3
y  = lambda x : x[0] * b + x[1] ** c + d

或者你使用下面的方法:

>> def curry1(b):
   ...:     def curry2(c):
   ...:         def curry3(d):
   ...:             def f(x):
   ...:                 return x[0] * b + x[1] ** c + d
   ...:             return f
   ...:         return curry3
   ...:     return curry2
>> f = curry1(1)(2)(3)

无论哪种,你把 b ,c,d 都固定住之后就可以直接传到 sko 就可以

DFX184 avatar Jan 21 '24 08:01 DFX184