【发布时间】:2018-07-30 14:19:14
【问题描述】:
我目前正在尝试使用 GPyOpt 模块通过高斯优化找到某些函数 f(arg1, arg2, arg3, ...) 的最小值。虽然f(...) 需要许多输入参数,但我只想优化其中一个。你是怎么做到的?
我目前的“解决方案”是将f(...) 放在一个虚拟类中,并在初始化时指定不可优化的参数。虽然这可以说是解决这个问题的最蟒蛇式的方法,但它也比它有任何权利要复杂得多。
在优化 x 时,具有固定 y(数字)和 method(字符串)的函数 f(x, y, method) 的简短工作示例:
import GPyOpt
import numpy as np
# dummy class
class TarFun(object):
# fix y while initializing the object
def __init__(self, y, method):
self.y = y
self.method = method
# actual function to be minimized
def f(self, x):
if self.method == 'sin':
return np.sin(x-self.y)
elif self.method == 'cos':
return np.cos(x-self.y)
# create TarFun object with y fixed to 2 and use 'sin' method
tarFunObj = TarFun(y=2, method='sin')
# describe properties of x
space = [{'name':'x', 'type': 'continuous', 'domain': (-5,5)}]
# create GPyOpt object that will only optimize x
optObj = GPyOpt.methods.BayesianOptimization(tarFunObj.f, space)
肯定有一个更简单的方法。但是我发现的所有示例都优化了所有参数,我无法通过阅读 github 上的代码来弄清楚(我虽然可以在 GPyOpt.core.task.space 中找到信息,但没有运气)。
【问题讨论】:
标签: python machine-learning optimization hyperparameters gpyopt