Skip to content

Commit 4653868

Browse files
authored
set the seed when sampling initial guess for doe (#758)
1 parent ac8f7bf commit 4653868

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

bofire/strategies/doe/design.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def find_local_max_ipopt(
3030
partially_fixed_experiments: Optional[pd.DataFrame] = None,
3131
use_hessian: bool = False,
3232
use_cyipopt: Optional[bool] = None,
33+
seed: Optional[int] = None,
3334
) -> pd.DataFrame:
3435
"""Function computing an optimal design for a given domain and model.
3536
@@ -47,6 +48,7 @@ def find_local_max_ipopt(
4748
use_hessian: If True, the hessian of the objective function is used. Default is False.
4849
use_cyipopt: If True, cyipopt is used, otherwise scipy.minimize(). Default is None.
4950
If None, cyipopt is used if available.
51+
seed: Random seed for sampling. Defaults to None, in this case no seed is given to the
5052
5153
Returns:
5254
A pd.DataFrame object containing the best found input for the experiments. In general, this is only a
@@ -101,7 +103,9 @@ def find_local_max_ipopt(
101103
sampling.sort_index(axis=1, inplace=True)
102104
x0 = sampling.values.flatten()
103105
try:
104-
sampler = RandomStrategy(data_model=RandomStrategyDataModel(domain=domain))
106+
sampler = RandomStrategy(
107+
data_model=RandomStrategyDataModel(domain=domain, seed=seed)
108+
)
105109
x0 = (
106110
sampler.ask(n_experiments, raise_validation_error=False)
107111
.to_numpy()
@@ -115,7 +119,9 @@ def find_local_max_ipopt(
115119
possibly improve performance.",
116120
)
117121
x0 = (
118-
domain.inputs.sample(n=n_experiments, method=SamplingMethodEnum.UNIFORM)
122+
domain.inputs.sample(
123+
n=n_experiments, method=SamplingMethodEnum.UNIFORM, seed=seed
124+
)
119125
.to_numpy()
120126
.flatten()
121127
)

bofire/strategies/doe_strategy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def _ask(
118118
partially_fixed_experiments=relaxed_candidates, # technically fixed experiments are also partially_fixed, so we only use this
119119
ipopt_options=self._data_model.ipopt_options,
120120
objective_function=objective_function,
121+
seed=self.seed,
121122
)
122123

123124
# if cats or discrete var present, need to filture out all the aux vars and project back into original domain

0 commit comments

Comments
 (0)