我有一个函数f(x1,x2),并希望使用skopt为x的两个维度设置gp_minimization的界。
对于一个变量(x1),它工作得很好:
def func(x1):
return x1[0]
bounds = [(1.0, 10.0)]
gp_res = gp_minimize(func, dimensions=bounds, acq_func="EI", n_calls=100, random_state=0)但是,使用具有多个变量(如f(x1,x2) )的函数,我需要添加第二个变量的边界。我试过这样做:
def func(x1, x2):
return x1[0][0]*x2[0][1]
bounds = [[(1.0, 10.0),(10.1, 9.9)]]
bounds[0][0] #(1.0,10.0) To set the bounds for x1
bounds[0][1] #(10.1,9.9) To set the bounds for x2
gp_res = gp_minimize(func=func, dimensions=bounds, acq_func="EI", n_calls=100, random_state=0)我得到了错误消息: ValueError:无效维度(1.0,4.0),(1.1,3.9)。阅读支持类型的文档。
通过将边界更改为:
def func(x1, x2):
return x1[0][0]*x2[0][1]
bounds = [(1.0, 10.0),(10.1, 9.9)]
gp_res = gp_minimize(func=func, dimensions=bounds, acq_func="EI", n_calls=100, random_state=0)我收到以下错误消息: TypeError: func()缺少一个必需的位置参数:'x2‘
你能帮我解决这个问题吗?如何为两个变量设置界限?
参考这个例子(Tim Head,2016年7月)。由Holger 2020重新格式化):https://scikit-optimize.github.io/stable/auto_examples/strategy-comparison.html#sphx-glr-download-auto-examples-strategy-comparison-py
发布于 2021-01-18 16:11:03
解决了。
解决方案:
dim1 = Real(name='x1', low=1.0, high=100.0)
dim2 = Real(name='x2', low=1.0, high=100.0)
bounds = [dim1, dim2]
@use_named_args(dimensions=bounds)
def func(x1, x2):
return x1*x2https://stackoverflow.com/questions/65760085
复制相似问题