Пример #1
0
    def test_init(self):
        #test default parameters
        exp = Experiment("test", {"x": MinMaxNumericParamDef(0, 1)})

        opt = BayesianOptimizer(exp)
        assert_equal(opt.initial_random_runs, 10)
        assert_is_none(opt.acquisition_hyperparams)
        assert_equal(opt.num_gp_restarts, 10)
        assert_true(isinstance(opt.acquisition_function, ExpectedImprovement))
        assert_dict_equal(opt.kernel_params, {})
        assert_equal(opt.kernel, "matern52")

        #test correct initialization
        opt_arguments = {
            "initial_random_runs": 5,
            "acquisition_hyperparams": {},
            "num_gp_restarts": 5,
            "acquisition": ProbabilityOfImprovement,
            "kernel_params": {},
            "kernel": "matern52",
            "mcmc": True,
        }
        opt = BayesianOptimizer(exp, opt_arguments)

        assert_equal(opt.initial_random_runs, 5)
        assert_dict_equal(opt.acquisition_hyperparams, {})
        assert_equal(opt.num_gp_restarts, 5)
        assert_true(
            isinstance(opt.acquisition_function, ProbabilityOfImprovement))
        assert_dict_equal(opt.kernel_params, {})
        assert_equal(opt.kernel, "matern52")
Пример #2
0
 def test_get_next_candidate(self):
     exp = Experiment("test", {"x": MinMaxNumericParamDef(0, 1),
                               "y": NominalParamDef(["A", "B", "C"])})
     opt = BayesianOptimizer(exp, {"initial_random_runs": 3})
     for i in range(5):
         cand = opt.get_next_candidates()[0]
         assert_true(isinstance(cand, Candidate))
         cand.result = 2
         exp.add_finished(cand)
         opt.update(exp)
     cands = opt.get_next_candidates(num_candidates=3)
     assert_less_equal(len(cands), 3)
Пример #3
0
    def test_EI(self):
        exp = Experiment("test", {"x": MinMaxNumericParamDef(0, 1)})
        opt = BayesianOptimizer(exp, {
            "initial_random_runs": 3,
            "max_searcher": "LBFGSB"
        })

        for i in range(3):
            cands = opt.get_next_candidates(2)
            cand_one = cands[0]
            cand_two = cands[1]
            assert_true(isinstance(cand_one, Candidate))
            cand_one.result = 2
            exp.add_finished(cand_one)
            opt.update(exp)
            assert_true(isinstance(cand_two, Candidate))
            cand_two.result = 2
            exp.add_finished(cand_two)
            opt.update(exp)
        cands = opt.get_next_candidates(num_candidates=5)
        assert_equal(len(cands), 5)

        opt.acquisition_function.params["multi_searcher"] = "random_best"
        cands = opt.get_next_candidates(2)
Пример #4
0
    def test_EI(self):
        exp = Experiment("test", {"x": MinMaxNumericParamDef(0, 1)})
        opt = BayesianOptimizer(exp, {"initial_random_runs": 3, "max_searcher": "LBFGSB"})

        for i in range(3):
            cands = opt.get_next_candidates(2)
            cand_one = cands[0]
            cand_two = cands[1]
            assert_true(isinstance(cand_one, Candidate))
            cand_one.result = 2
            exp.add_finished(cand_one)
            opt.update(exp)
            assert_true(isinstance(cand_two, Candidate))
            cand_two.result = 2
            exp.add_finished(cand_two)
            opt.update(exp)
        cands = opt.get_next_candidates(num_candidates=5)
        assert_equal(len(cands), 5)

        opt.acquisition_function.params["multi_searcher"] = "random_best"
        cands = opt.get_next_candidates(2)
Пример #5
0
 def test_get_next_candidate(self):
     exp = Experiment(
         "test", {
             "x": MinMaxNumericParamDef(0, 1),
             "y": NominalParamDef(["A", "B", "C"])
         })
     opt = BayesianOptimizer(exp, {"initial_random_runs": 3})
     for i in range(5):
         cand = opt.get_next_candidates()[0]
         assert_true(isinstance(cand, Candidate))
         cand.result = 2
         exp.add_finished(cand)
         opt.update(exp)
     cands = opt.get_next_candidates(num_candidates=3)
     assert_less_equal(len(cands), 3)
Пример #6
0
    def test_PoI(self):
        exp = Experiment("test", {"x": MinMaxNumericParamDef(0, 1)})
        opt = BayesianOptimizer(exp, {"initial_random_runs": 3, "acquisition": ProbabilityOfImprovement})
        assert_true(isinstance(opt.acquisition_function, ProbabilityOfImprovement))

        for i in range(3):
            cands = opt.get_next_candidates(2)
            cand_one = cands[0]
            cand_two = cands[1]
            assert_true(isinstance(cand_one, Candidate))
            cand_one.result = 2
            exp.add_finished(cand_one)
            opt.update(exp)
            assert_true(isinstance(cand_two, Candidate))
            cand_two.result = 2
            exp.add_finished(cand_two)
            opt.update(exp)
        cands = opt.get_next_candidates(num_candidates=3)
        assert_equal(len(cands), 3)
Пример #7
0
    def test_PoI(self):
        exp = Experiment("test", {"x": MinMaxNumericParamDef(0, 1)})
        opt = BayesianOptimizer(exp, {
            "initial_random_runs": 3,
            "acquisition": ProbabilityOfImprovement
        })
        assert_true(
            isinstance(opt.acquisition_function, ProbabilityOfImprovement))

        for i in range(3):
            cands = opt.get_next_candidates(2)
            cand_one = cands[0]
            cand_two = cands[1]
            assert_true(isinstance(cand_one, Candidate))
            cand_one.result = 2
            exp.add_finished(cand_one)
            opt.update(exp)
            assert_true(isinstance(cand_two, Candidate))
            cand_two.result = 2
            exp.add_finished(cand_two)
            opt.update(exp)
        cands = opt.get_next_candidates(num_candidates=3)
        assert_equal(len(cands), 3)