def test_opt_qn_normal(f=hp_normal): bandit = Bandit( {'loss': -scope.sum([f('v%i' % ii, 0, 1) for ii in range(25)]) ** 2}, loss_target=0) algo = TreeParzenEstimator(bandit, prior_weight=.5, n_startup_jobs=0, n_EI_candidates=1, gamma=0.15) trials = Trials() experiment = Experiment(trials, algo, async=False) experiment.max_queue_len = 1 experiment.run(40) print list(sorted(trials.losses())) idxs, vals = miscs_to_idxs_vals(trials.miscs) if 1: import hyperopt.plotting hyperopt.plotting.main_plot_vars(trials, bandit, do_show=1) else: import matplotlib.pyplot as plt begin = [v[:10] for k, v in vals.items()] end = [v[-10:] for k, v in vals.items()] plt.subplot(2, 1, 1) plt.title('before') plt.hist(np.asarray(begin).flatten()) plt.subplot(2, 1, 2) plt.title('after') plt.hist(np.asarray(end).flatten()) plt.show()
def test_opt_qn_normal(f=hp_normal): bandit = Bandit( {'loss': -scope.sum([f('v%i' % ii, 0, 1) for ii in range(25)])**2}, loss_target=0) algo = TreeParzenEstimator(bandit, prior_weight=.5, n_startup_jobs=0, n_EI_candidates=1, gamma=0.15) trials = Trials() experiment = Experiment(trials, algo, async=False) experiment.max_queue_len = 1 experiment.run(40) print list(sorted(trials.losses())) idxs, vals = miscs_to_idxs_vals(trials.miscs) if 1: import hyperopt.plotting hyperopt.plotting.main_plot_vars(trials, bandit, do_show=1) else: import matplotlib.pyplot as plt begin = [v[:10] for k, v in vals.items()] end = [v[-10:] for k, v in vals.items()] plt.subplot(2, 1, 1) plt.title('before') plt.hist(np.asarray(begin).flatten()) plt.subplot(2, 1, 2) plt.title('after') plt.hist(np.asarray(end).flatten()) plt.show()
def ap_categorical_sampler(obs, prior_weight, upper, size=(), rng=None, LF=DEFAULT_LF): weights = scope.linear_forgetting_weights(scope.len(obs), LF=LF) counts = scope.bincount(obs, minlength=upper, weights=weights) # -- add in some prior pseudocounts pseudocounts = counts + prior_weight return scope.categorical(pseudocounts / scope.sum(pseudocounts), upper=upper, size=size, rng=rng)
def ap_categorical_sampler(obs, prior_weight, upper, size=(), rng=None): counts = scope.bincount(obs, minlength=upper) # -- add in some prior pseudocounts pseudocounts = counts + prior_weight return scope.categorical(pseudocounts / scope.sum(pseudocounts), size=size, rng=rng)