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.

Regi Mathew
  • 2,603
  • 3
  • 24
  • 38

3 Answers3

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)`
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.

Alexander Vocaet
  • 188
  • 1
  • 10
  • 1
    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](https://stackoverflow.com/help/how-to-answer) for more. – DCTID Feb 21 '20 at 22:22
  • marked it as a partial answer; is this better, or should this be a comment? – Alexander Vocaet Feb 22 '20 at 14:09
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.

Tony B
  • 376
  • 1
  • 3
  • 12