MCPcopy
hub / github.com/hyperopt/hyperopt / test_vectorize_multipath

Function test_vectorize_multipath

hyperopt/tests/unit/test_vectorize.py:96–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94
95
96def test_vectorize_multipath():
97 N = as_apply(15)
98
99 p0 = hp_uniform("p0", 0, 1)
100 loss = hp_choice("p1", [1, p0, -p0]) ** 2
101 expr_idxs = scope.range(N)
102 vh = VectorizeHelper(loss, expr_idxs, build=True)
103
104 vloss = vh.v_expr
105 print(vloss)
106
107 full_output = as_apply([vloss, vh.idxs_by_label(), vh.vals_by_label()])
108
109 new_vc = recursive_set_rng_kwarg(full_output, as_apply(np.random.default_rng(1)))
110
111 losses, idxs, vals = rec_eval(new_vc)
112 print("losses", losses)
113 print("idxs p0", idxs["p0"])
114 print("vals p0", vals["p0"])
115 print("idxs p1", idxs["p1"])
116 print("vals p1", vals["p1"])
117 p0dct = dict(list(zip(idxs["p0"], vals["p0"])))
118 p1dct = dict(list(zip(idxs["p1"], vals["p1"])))
119 for ii, li in enumerate(losses):
120 print(ii, li)
121 if p1dct[ii] != 0:
122 assert li == p0dct[ii] ** 2
123 else:
124 assert li == 1
125
126
127def test_vectorize_config0():

Callers

nothing calls this directly

Calls 9

idxs_by_labelMethod · 0.95
vals_by_labelMethod · 0.95
as_applyFunction · 0.90
hp_uniformFunction · 0.90
hp_choiceFunction · 0.90
VectorizeHelperClass · 0.90
recursive_set_rng_kwargFunction · 0.90
rec_evalFunction · 0.90
rangeMethod · 0.80

Tested by

no test coverage detected