MCPcopy
hub / github.com/hyperopt/hyperopt / test_distributions

Function test_distributions

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

Source from the content-addressed store, hash-verified

200
201
202def test_distributions():
203 # test that the distributions come out right
204
205 # XXX: test more distributions
206 space = {
207 "loss": (
208 hp_loguniform("lu", -2, 2)
209 + hp_qloguniform("qlu", np.log(1 + 0.01), np.log(20), 2)
210 + hp_quniform("qu", -4.999, 5, 1)
211 + hp_uniform("u", 0, 10)
212 ),
213 "status": "ok",
214 }
215 trials = base.Trials()
216 N = 1000
217 fmin(
218 lambda x: x,
219 space=space,
220 algo=rand.suggest,
221 trials=trials,
222 max_evals=N,
223 rstate=np.random.default_rng(124),
224 catch_eval_exceptions=False,
225 )
226 assert len(trials) == N
227 idxs, vals = base.miscs_to_idxs_vals(trials.miscs)
228 print(list(idxs.keys()))
229
230 COUNTMAX = 130
231 COUNTMIN = 70
232
233 # -- loguniform
234 log_lu = np.log(vals["lu"])
235 assert len(log_lu) == N
236 assert -2 < np.min(log_lu)
237 assert np.max(log_lu) < 2
238 h = np.histogram(log_lu)[0]
239 print(h)
240 assert np.all(COUNTMIN < h)
241 assert np.all(h < COUNTMAX)
242
243 # -- quantized log uniform
244 qlu = vals["qlu"]
245 assert np.all(np.fmod(qlu, 2) == 0)
246 assert np.min(qlu) == 2
247 assert np.max(qlu) == 20
248 bc_qlu = np.bincount(qlu)
249 assert bc_qlu[2] > bc_qlu[4] > bc_qlu[6] > bc_qlu[8]
250
251 # -- quantized uniform
252 qu = vals["qu"]
253 assert np.min(qu) == -5
254 assert np.max(qu) == 5
255 assert np.all(np.fmod(qu, 1) == 0)
256 bc_qu = np.bincount(np.asarray(qu).astype("int") + 5)
257 assert np.all(40 < bc_qu), bc_qu # XXX: how to get the distribution flat
258 # with new rounding rule?
259 assert np.all(bc_qu < 125), bc_qu

Callers

nothing calls this directly

Calls 8

hp_loguniformFunction · 0.90
hp_qloguniformFunction · 0.90
hp_quniformFunction · 0.90
hp_uniformFunction · 0.90
fminFunction · 0.90
keysMethod · 0.80
minMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected