Beispiel #1
0
def get_empirical_bayes_thompson(
    experiment: Experiment,
    data: Data,
    search_space: Optional[SearchSpace] = None,
    num_samples: int = 10000,
    min_weight: Optional[float] = None,
    uniform_weights: bool = False,
) -> DiscreteModelBridge:
    """Instantiates an empirical Bayes / Thompson sampling model."""
    if data.df.empty:  # pragma: no cover
        raise ValueError(
            "Empirical Bayes Thompson sampler requires non-empty data.")
    logger.info(
        "Factory functions (like `get_empirical_bayes_thompson`) will soon be "
        "deprecated). Use the model registry instead (`Models.EMPIRICAL_BAYES"
        "(...)`).")
    return checked_cast(
        DiscreteModelBridge,
        Models.EMPIRICAL_BAYES_THOMPSON(
            experiment=experiment,
            data=data,
            search_space=search_space or experiment.search_space,
            num_samples=num_samples,
            min_weight=min_weight,
            uniform_weights=uniform_weights,
        ),
    )
Beispiel #2
0
 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)
Beispiel #3
0
def get_empirical_bayes_thompson(
    experiment: Experiment,
    data: Data,
    search_space: Optional[SearchSpace] = None,
    num_samples: int = 10000,
    min_weight: Optional[float] = None,
    uniform_weights: bool = False,
) -> DiscreteModelBridge:
    """Instantiates an empirical Bayes / Thompson sampling model."""
    if data.df.empty:  # pragma: no cover
        raise ValueError("Empirical Bayes Thompson sampler requires non-empty data.")
    return checked_cast(
        DiscreteModelBridge,
        Models.EMPIRICAL_BAYES_THOMPSON(
            experiment=experiment,
            data=data,
            search_space=search_space or experiment.search_space,
            num_samples=num_samples,
            min_weight=min_weight,
            uniform_weights=uniform_weights,
        ),
    )