contents of Trials() object in hyperopt
Asked Answered
P

3

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.

Paquette answered 7/3, 2019 at 13:28 Comment(0)
C
4

As per Hyperopt code: `Trials - a list of documents including at least 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)`
Coenurus answered 30/8, 2020 at 11:30 Comment(1)
Thanks. I didn't think of examining the code. It is quite clear in the code.Paquette
R
2

This is only a partial answer from my investigation into the Hyperopt Code:

there is a ._dynamic_trials which stores the information used in optimization.

Ryle answered 21/2, 2020 at 21:13 Comment(2)
Thanks for answering however, I don't believe you have answered the question. If you believe you have could you edit your answer to make it clearer? See how to answer for more.Ichthyoid
marked it as a partial answer; is this better, or should this be a comment?Ryle
E
2

If you want to just dump all contents to the screen you can do something like this. Here is how you would use the strategy on a Trials object:

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)

This will print all properties and methods of the Trials object. I will not include it all here because it's long, but here are a few lines of it:

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>>

But I find it more usefull to look at the source code. There are a few properties declared under the __init__ function, then there are a set of properties declared using the @property decorator. The methods are all defs.

Not sure how your environment is setup, but the file is stored in my conda environment at ..\env\Lib\site-packages\yperopt\base.py. class Trials(object) should be declared around line 228.

Eigenvalue answered 6/3, 2020 at 19:41 Comment(1)
I am getting 'AllTrialsFailed:' error. Not sure why.Paquette

© 2022 - 2024 — McMap. All rights reserved.