首页 > 解决方案 > Hyperopt 更改 Trials() 对象的值;热启动 Hyperopt

问题描述

我正在寻找一种可能来启动 Hyperopt。一种方法是用超参数手动填充列表Trials.trials这实际上是可能的,但我想知道这是否真的影响优化,或者这个 Trials.trials 是否只是 Trials 对象和 Hyperopt 的可见部分。

标签: machine-learninghyperparametersautomlhyperopt

解决方案


trial.trials 列表不包含所有信息!由于baye.py 中的resfresh 函数,还必须更改试验。

一般来说,热启动应该是可能的。我通过在具有一些任意搜索空间和目标函数的新试验对象上调用 fmin,创建了一个与我的热启动状态大小相同的假试验对象。在此之后,可以通过迭代 trial.trials 的长度并设置如下值来更改试验对象:

list_of_coldstart_dict = [one_possible_and_evaluation,second_possible_and_evaluation,...]
fake_space = {
'test': 2-hp.loguniform('test_02',0.001, 0.1)
}
def Objective(params):
    return {"loss":0, 'status': STATUS_OK}
trials = Trials()
fmin(Objective,fake_space,
    algo=partial(tpe.suggest, n_startup_jobs=len(list_of_coldstart_dict)), max_evals=len(list_of_coldstart_dicts), 
        trials=new_trials,verbose=1)

for in in range(len(trials.trials):
    trials.trials[i] = list_of_coldstart_dict[i]
    trials._dynamic_trials[i] = list_of_coldstart_dict[i]
    trials.results[i] = trials.trials[i]['result']

注意在 trial.trials[i] 中维护 dict of dicts 的 neccecary 结构


推荐阅读