Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

非优化参数的传入 #220

Open
cumttc opened this issue Oct 23, 2023 · 2 comments
Open

非优化参数的传入 #220

cumttc opened this issue Oct 23, 2023 · 2 comments

Comments

@cumttc
Copy link

cumttc commented Oct 23, 2023

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

@aak1247
Copy link
Contributor

aak1247 commented Jan 5, 2024

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

@DFX184
Copy link

DFX184 commented Jan 21, 2024

你可以选择 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 就可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants