From bc75560e19b51b3205616860daa619c825a0a1ff Mon Sep 17 00:00:00 2001 From: Behrang Shafei <50267830+bertiqwerty@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:33:14 +0200 Subject: [PATCH] Readme example (#419) * sample correctly and make readme example mo * review requests --- README.md | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 219be44f1..26fb672b8 100644 --- a/README.md +++ b/README.md @@ -75,30 +75,35 @@ domain = Domain( ``` You can also use one of the many benchmarks available in BoFire. -Here, we use the Himmelblau benchmark to demonstrate the ask/tell interface for -proposing new experiments. +Here, we use the Detergent benchmark to demonstrate the ask/tell interface for +proposing new experiments with multi-objective Bayesian optimization. ```python -from bofire.benchmarks.single import Himmelblau - -benchmark = Himmelblau() -samples = benchmark.domain.inputs.sample(10) -experiments = benchmark.f(samples, return_complete=True) - -from bofire.data_models.strategies.api import SoboStrategy -from bofire.data_models.acquisition_functions.api import qNEI import bofire.strategies.api as strategies -sobo_strategy_data_model = SoboStrategy(domain=benchmark.domain, acquisition_function=qNEI()) - -sobo_strategy = strategies.map(sobo_strategy_data_model) - -sobo_strategy.tell(experiments=experiments) -sobo_strategy.ask(candidate_count=1) +from bofire.benchmarks.detergent import Detergent +from bofire.data_models.strategies.api import QnehviStrategy, RandomStrategy + +# create benchmark +detergent = Detergent() +domain = detergent.domain + +# create initial data with the random strategy while satisfying constraints +sampler = strategies.map(RandomStrategy(domain=domain)) +initial_samples = sampler.ask(2) +experiments = detergent.f(initial_samples, return_complete=True) + +# Bayesian optimization +mobo_strategy = strategies.map(QnehviStrategy(domain=domain)) +n_experiments = 4 +for _ in range(n_experiments): + mobo_strategy.tell(experiments=experiments) + candidates = mobo_strategy.ask(candidate_count=1) + experiments = detergent.f(candidates, return_complete=True) + +# Print all told experiments +print(mobo_strategy.experiments) ``` -This gives one step in the optimization loop. We can repeat this many times to -perform Bayesian optimization, exploring the space using intelligent strategies. - ## Documentation Documentation including a section on how to get started can be found under https://experimental-design.github.io/bofire/.