Example #1
0
def get_factorial_experiment(
    has_optimization_config: bool = True,
    with_batch: bool = False,
    with_status_quo: bool = False,
) -> Experiment:
    exp = Experiment(
        name="factorial_test_experiment",
        search_space=get_factorial_search_space(),
        optimization_config=OptimizationConfig(
            objective=Objective(metric=get_factorial_metric())
        )
        if has_optimization_config
        else None,
        runner=SyntheticRunner(),
        is_test=True,
        tracking_metrics=[get_factorial_metric("secondary_metric")],
    )

    if with_status_quo:
        exp.status_quo = Arm(
            parameters={
                "factor1": "level11",
                "factor2": "level21",
                "factor3": "level31",
            }
        )

    if with_batch:
        factorial_generator = get_factorial(search_space=exp.search_space)
        factorial_run = factorial_generator.gen(n=-1)
        exp.new_batch_trial(optimize_for_power=with_status_quo).add_generator_run(
            factorial_run
        )

    return exp
Example #2
0
 def test_factorial(self):
     """Tests factorial instantiation."""
     exp = get_factorial_experiment()
     factorial = get_factorial(exp.search_space)
     self.assertIsInstance(factorial, DiscreteModelBridge)
     factorial_run = factorial.gen(n=-1)
     self.assertEqual(len(factorial_run.arms), 24)
Example #3
0
 def test_thompson(self):
     """Tests TS instantiation."""
     exp = get_factorial_experiment()
     factorial = get_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 = get_thompson(experiment=exp, data=data)
     self.assertIsInstance(thompson.model, ThompsonSampler)
Example #4
0
 def test_empirical_bayes_thompson(self):
     """Tests EB/TS instantiation."""
     exp = get_factorial_experiment()
     factorial = get_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 = get_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)