def test_enum_factorial(self): """Tests factorial instantiation through the Models enum.""" exp = get_factorial_experiment() factorial = Models.FACTORIAL(exp.search_space) self.assertIsInstance(factorial, DiscreteModelBridge) factorial_run = factorial.gen(n=-1) self.assertEqual(len(factorial_run.arms), 24)
def get_factorial(search_space: SearchSpace) -> DiscreteModelBridge: """Instantiates a factorial generator.""" logger.info( "Factory functions (like `get_factorial`) will soon be deprecated). Use " "the model registry instead (`Models.FACTORIAL(...)`).") return checked_cast(DiscreteModelBridge, Models.FACTORIAL(search_space=search_space))
def test_enum_thompson(self): """Tests TS instantiation through the Models enum.""" exp = get_factorial_experiment() factorial = Models.FACTORIAL(exp.search_space) self.assertIsInstance(factorial, DiscreteModelBridge) factorial_run = factorial.gen(n=-1) exp.new_batch_trial().add_generator_run(factorial_run).run().mark_completed() data = exp.fetch_data() thompson = Models.THOMPSON(experiment=exp, data=data) self.assertIsInstance(thompson.model, ThompsonSampler)
def test_enum_empirical_bayes_thompson(self): """Tests EB/TS instantiation through the Models enum.""" exp = get_factorial_experiment() factorial = Models.FACTORIAL(exp.search_space) self.assertIsInstance(factorial, DiscreteModelBridge) factorial_run = factorial.gen(n=-1) exp.new_batch_trial().add_generator_run(factorial_run).run().mark_completed() data = exp.fetch_data() eb_thompson = Models.EMPIRICAL_BAYES_THOMPSON( experiment=exp, data=data, min_weight=0.0 ) self.assertIsInstance(eb_thompson, DiscreteModelBridge) self.assertIsInstance(eb_thompson.model, EmpiricalBayesThompsonSampler) thompson_run = eb_thompson.gen(n=5) self.assertEqual(len(thompson_run.arms), 5)
def get_factorial(search_space: SearchSpace) -> DiscreteModelBridge: """Instantiates a factorial generator.""" return checked_cast( DiscreteModelBridge, Models.FACTORIAL(search_space=search_space, fit_out_of_design=True), )