Reputation: 21353
I am trying to use hyperopt for the first time. I copied and pasted the tutorial example:
from hyperopt import fmin, tpe, hp
best = fmin(fn=lambda x: x ** 2,
space=hp.uniform('x', -10, 10),
algo=tpe.suggest,
max_evals=100)
print best
But this gives me:
TypeError Traceback (most recent call last)
<ipython-input-1-c6ddf657bb46> in <module>()
3 space=hp.uniform('x', -10, 10),
4 algo=tpe.suggest,
----> 5 max_evals=100)
6 print best
/home/user/.local/lib/python2.7/site-packages/hyperopt/fmin.pyc in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
312
313 domain = base.Domain(fn, space,
--> 314 pass_expr_memo_ctrl=pass_expr_memo_ctrl)
315
316 rval = FMinIter(algo, domain, trials, max_evals=max_evals,
/home/user/.local/lib/python2.7/site-packages/hyperopt/base.pyc in __init__(self, fn, expr, workdir, pass_expr_memo_ctrl, name, loss_target)
784 before = pyll.dfs(self.expr)
785 # -- raises exception if expr contains cycles
--> 786 pyll.toposort(self.expr)
787 vh = self.vh = VectorizeHelper(self.expr, self.s_new_ids)
788 # -- raises exception if v_expr contains cycles
/home/user/.local/lib/python2.7/site-packages/hyperopt/pyll/base.pyc in toposort(expr)
713 G.add_edges_from([(n_in, node) for n_in in node.inputs()])
714 order = nx.topological_sort(G)
--> 715 assert order[-1] == expr
716 return order
717
TypeError: 'generator' object has no attribute '__getitem__'
I am not really sure what this error message means.
What am I doing wrong?
Upvotes: 0
Views: 561
Reputation: 281948
hyperopt
isn't currently compatible with NetworkX 2.x. The master branch should have the fix, but there hasn't been a fixed hyperopt
release.
For now, you'll either have to install hyperopt
from the master branch, or downgrade to a 1.x version of NetworkX.
Upvotes: 1