Пример #1
0
    def test_basic(self):
        space = {
            "x": ["hp_choice", "x", np.linspace(-10, 10, num=21)],
            "y": ["hp_choice", "y", np.linspace(-10, 10, num=21)],
        }

        hpo = Hyperopt(space=space, method="tpe")

        tape = []

        # does it do anything?
        tape = run_n_steps(hpo, 2, tape)
        start = best_loss(tape)
        tape = run_n_steps(hpo, 200, tape)
        end = best_loss(tape)
        self.assertGreater(start, end)

        # test repeatability
        tid, next_suggestion = hpo.suggest()

        hpo2 = Hyperopt(space=space, method="tpe")

        for entry in tape:
            if entry[0] == "suggest":
                tid, s = hpo2.suggest()
                self.assertEqual(tid, entry[1])
                self.assertEqual(s, entry[2])
            else:
                hpo2.submit(entry[1], loss=entry[2])

        tid, next_suggestion2 = hpo2.suggest()
        self.assertEqual(next_suggestion, next_suggestion2)
Пример #2
0
    def test_quadratic(self):
        # this is a somewhat redundant test, but it'll put the
        # pool through a slightly more realistic situation and hopefully
        # show us when and where it fails.

        space = {
            "x": ["hp_loggrid", "x", -2.0, 2.0, 161],
            "y": ["hp_loggrid", "y", -2.0, 2.0, 161],
            "z": ["hp_loggrid", "z", -2.0, 2.0, 161],
            "a": ["hp_loggrid", "a", -2.0, 2.0, 161],
            "b": ["hp_loggrid", "b", -2.0, 2.0, 161],
            "c": ["hp_loggrid", "c", -2.0, 2.0, 161],
            "wait": ["hp_choice", "wait", [0.0, 0.1]],
        }
        hpo = Hyperopt(space=space)

        pool = EvaluationPool(
            max_workers=40,
            evaluator_config={"mock_eval2": {}},
            trial_timeout=0.07,
        )

        search = Hyperopt(space=space)

        tasks = {}

        for i in range(10):
            t, s = hpo.suggest()
            tasks[t] = s

        futures = {pool.schedule(s): t for t, s in tasks.items()}

        for d in futures:
            pool.finish(d)
        pool.shutdown()

        self.assertEqual(len(pool.evals), 10)