Hyperopt 中 Trials() 对象的内容
contents of Trials() object in hyperopt
此查询指的是在 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.statuses()。
但是,我看到了像 trials.best_trial 和 [= 这样的用法49=] 文档中没有提到。
现在我想知道如何获取trials对象的所有内容的列表?对象类型为hyperopt.base.Trials.
这只是我对 Hyperopt 代码调查的部分答案:
有一个 ._dynamic_trials 存储优化中使用的信息。
如果您只想将所有内容转储到屏幕上,您可以执行类似 this 的操作。以下是如何在 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
s.
不确定您的环境是如何设置的,但该文件存储在我的 conda 环境中 ..\env\Lib\site-packages\yperopt\base.py
。 class Trials(object)
应在第 228 行左右声明。
根据Hyperopt code:
`Trials - 文件列表至少包括 sub-documents
['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)`
此查询指的是在 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.statuses()。
但是,我看到了像 trials.best_trial 和 [= 这样的用法49=] 文档中没有提到。
现在我想知道如何获取trials对象的所有内容的列表?对象类型为hyperopt.base.Trials.
这只是我对 Hyperopt 代码调查的部分答案:
有一个 ._dynamic_trials 存储优化中使用的信息。
如果您只想将所有内容转储到屏幕上,您可以执行类似 this 的操作。以下是如何在 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
s.
不确定您的环境是如何设置的,但该文件存储在我的 conda 环境中 ..\env\Lib\site-packages\yperopt\base.py
。 class Trials(object)
应在第 228 行左右声明。
根据Hyperopt code: `Trials - 文件列表至少包括 sub-documents
['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)`