5

This query is referring to usage of trials as an argument in fmin.

trials = Trials()
best = fmin(objective, space=hp.uniform('x', -10, 10), algo=tpe.suggest,
    max_evals=100, trials=trials)

The documentation (https://github.com/hyperopt/hyperopt/wiki/FMin) state that trials object got lists like trials.trials, trials.results, trials.losses() and trials.statuses().

However, I have seen usages like trials.best_trial and trials.trial_attachments that were not mentioned in the document.

Now I wonder how to get a list of all the contents of the trials object? The object type is hyperopt.base.Trials.

4

3 回答 3

4

根据Hyperopt 代码:`Trials - 至少包括子文档的文档列表

['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-08-30T11:30:03.967 回答
2

这只是我对 Hyperopt 代码的调查的部分答案:

有一个 ._dynamic_trials 存储优化中使用的信息。

于 2020-02-21T21:13:57.510 回答
2

如果您只想将所有内容转储到屏幕上,您可以执行以下操作。以下是在对象上使用该策略的方法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装饰器声明的属性。方法都是defs。

不确定您的环境是如何设置的,但该文件存储在我的 conda 环境中..\env\Lib\site-packages\yperopt\base.pyclass Trials(object)应该在第 228 行左右声明。

于 2020-03-06T19:41:22.027 回答