此查询将试用作为fmin中的一个论点。
trials = Trials()
best = fmin(objective, space=hp.uniform('x', -10, 10), algo=tpe.suggest,
max_evals=100, trials=trials)文档(https://github.com/hyperopt/hyperopt/wiki/FMin)指出,审判对象得到了诸如trials.trials、trials.results、trials.losses()和之类的列表
然而,我已经看到了像trials.best_trial和trials.trial_attachments这样的用法,这些用法在文档中没有提到。
现在,我想知道如何获得试用对象的所有内容的列表?对象类型为hyperopt.base.Trials.
发布于 2020-08-30 11:30:03
根据Hyperopt码:“尝试--至少包含子文档的文档列表”
['spec'] - the specification of hyper-parameters for a job
['result'] - the result of Domain.evaluate(). Typically includes:
['status'] - one of the STATUS_STRINGS
['loss'] - real-valued scalar that hyperopt is trying to minimize
['idxs'] - compressed representation of spec
['vals'] - compressed representation of spec
['tid'] - trial id (unique in Trials list)`发布于 2020-02-21 21:13:57
这只是我对Hyperopt代码的部分回答:
有一个._dynamic_trials存储用于优化的信息。
发布于 2020-03-06 19:41:22
如果您只想将所有内容转储到屏幕上,可以执行类似于这的操作。下面是如何在Trials对象上使用策略:
from hyperopt import Trials
def dump(obj):
for attr in dir(obj):
if hasattr( obj, attr ):
print( "obj.%s = %s" % (attr, getattr(obj, attr)))
tpe_trials = Trials()
dump(tpe_trials)这将打印Trials对象的所有属性和方法。我不会把它全部包括在这里,因为它很长,但是这里有几行:
obj.__class__ = <class 'hyperopt.base.Trials'>
obj.__delattr__ = <method-wrapper '__delattr__' of Trials object at 0x0000012880AA3108>
obj.__dict__ = {'_ids': set(), '_dynamic_trials': [], '_exp_key': None, 'attachments': {}, '_trials': []}
obj.__dir__ = <built-in method __dir__ of Trials object at 0x0000012880AA3108>
. . .
obj._ids = set()
obj._insert_trial_docs = <bound method Trials._insert_trial_docs of <hyperopt.base.Trials object at 0x0000012880AA3108>>
obj._trials = []
obj.aname = <bound method Trials.aname of <hyperopt.base.Trials object at 0x0000012880AA3108>>但是我发现看一下源代码会更有用。在__init__函数下声明了一些属性,然后有一组使用@property装饰符声明的属性。这些方法都是def的。
不确定您的环境是如何设置的,但该文件存储在..\env\Lib\site-packages\yperopt\base.py的conda环境中。class Trials(object)应该在第228行附近声明。
https://stackoverflow.com/questions/55044979
复制相似问题