我在寻找Hyperopt热启动的可能性。一种方法是手动填充Trials.trials
列表中的超参数。这实际上是可行的,但我怀疑这是否真的会影响优化,或者Trials.trials
只是Trials对象的可见部分,而Hyperopt则不同。
回答:
trials.trials
列表并不包含所有信息!还需要更改trials._dynamic_trials
,因为baye.py
中的刷新函数会用trials._dynamic_trials
的数据更新trials.trials
的数据。
总的来说,热启动应该是可能的。我通过在一个新的trials对象上调用fmin
,使用一些任意搜索空间和目标函数,创建了一个与我的热启动状态大小相同的假trials对象。之后,可以通过遍历trials.trials
的长度来更改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 i 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']
请注意保持trials.trials[i]
内部字典的必要结构。