MCPcopy
hub / github.com/hyperopt/hyperopt / work

Method work

hyperopt/tests/unit/test_tpe.py:681–774  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

679 LEN = 25
680
681 def work(self, **kwargs):
682 self.__dict__.update(kwargs)
683 bandit = opt_q_uniform(self.target)
684 prior_weight = 2.5
685 gamma = 0.20
686 algo = partial(
687 tpe.suggest,
688 prior_weight=prior_weight,
689 n_startup_jobs=2,
690 n_EI_candidates=128,
691 gamma=gamma,
692 )
693
694 trials = Trials()
695 fmin(
696 passthrough, space=bandit.expr, algo=algo, trials=trials, max_evals=self.LEN
697 )
698 if self.show_vars:
699 import hyperopt.plotting
700
701 hyperopt.plotting.main_plot_vars(trials, bandit, do_show=1)
702
703 idxs, vals = miscs_to_idxs_vals(trials.miscs)
704 idxs = idxs["x"]
705 vals = vals["x"]
706
707 losses = trials.losses()
708
709 from hyperopt.tpe import ap_split_trials
710 from hyperopt.tpe import adaptive_parzen_samplers
711
712 qu = scope.quniform(1.01, 10, 1)
713 fn = adaptive_parzen_samplers["quniform"]
714 fn_kwargs = dict(size=(4,), rng=np.random)
715 s_below = pyll.Literal()
716 s_above = pyll.Literal()
717 b_args = [s_below, prior_weight] + qu.pos_args
718 b_post = fn(*b_args, **fn_kwargs)
719 a_args = [s_above, prior_weight] + qu.pos_args
720 a_post = fn(*a_args, **fn_kwargs)
721
722 # print b_post
723 # print a_post
724 fn_lpdf = getattr(scope, a_post.name + "_lpdf")
725 print(fn_lpdf)
726 # calculate the llik of b_post under both distributions
727 a_kwargs = {n: a for n, a in a_post.named_args if n not in ("rng", "size")}
728 b_kwargs = {n: a for n, a in b_post.named_args if n not in ("rng", "size")}
729 below_llik = fn_lpdf(*([b_post] + b_post.pos_args), **b_kwargs)
730 above_llik = fn_lpdf(*([b_post] + a_post.pos_args), **a_kwargs)
731 new_node = scope.broadcast_best(b_post, below_llik, above_llik)
732
733 print("=" * 80)
734
735 do_show = self.show_steps
736
737 for ii in range(2, 9):
738 if ii > len(idxs):

Callers 4

test4Method · 0.95
test2Method · 0.95
test6Method · 0.95
test10Method · 0.95

Calls 9

lossesMethod · 0.95
TrialsClass · 0.90
fminFunction · 0.90
miscs_to_idxs_valsFunction · 0.90
ap_split_trialsFunction · 0.90
opt_q_uniformFunction · 0.85
fnFunction · 0.85
partialFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected