在 Nevergrad 包中建议值

Suggesting Values in Nevergrad Package

重现步骤

import nevergrad as ng
import numpy as np

loc = ng.p.Scalar(lower=-5,upper=5)
scale = ng.p.Scalar(lower=0, upper=5)
s = ng.p.Scalar(lower=0, upper=10)
k = ng.p.Choice(list(range(2,6)))
w = ng.p.Array(shape=(self.times.shape[0],)).set_bounds(-10,10)
instru = ng.p.Instrumentation(loc=loc,
                          scale = scale,
                          s=s,
                          k=k,
                          w = w)
optimizer = ng.optimizers.DE(parametrization=instru,
                                      budget=budget)
optimizer.suggest((),{'k':3,'loc':-2,'s':2,'scale':2,'w':np.ones(self.times.shape[0])})

观测结果

ValueError: Tuple value must be a tuple of size 0, got: ((), {'k': 3, 'loc': -2, 's': 2, 'scale': 2, 'w': array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1.])}).
Current value: ()

预期结果

对于要在优化器中设置的初始值运行

有没有人在 Nevergrad 成功使用 suggest method

如果是这样,您介意 copying/pasting 工作代码吗?我一直在尝试不同形式的 example in the documentation,但似乎无法正常工作。

问题已在相关 Github thread 中得到回答:

Basically, suggest should be called the same way as the function to optimize, in your case, given you are using an Instrumentation, I guess it should be:

optimizer.suggest(k=3, loc=-2, s=2, scale=2, w=mp.ones(self.times.shape[0]))

Another option, which can work for all but the Choice parameter would be to use the init option of Array and Scalar (eg: loc = ng.p.Scalar(init=-2, lower=-5, upper=5))