From 81fa08372eba05ee62467bf636018a9f50a2c85a Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Mon, 2 Dec 2024 15:06:29 +0100 Subject: [PATCH 1/2] Add seed option to SMAC --- package/samplers/smac_sampler/sampler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/samplers/smac_sampler/sampler.py b/package/samplers/smac_sampler/sampler.py index 964748d9..77584ac0 100644 --- a/package/samplers/smac_sampler/sampler.py +++ b/package/samplers/smac_sampler/sampler.py @@ -99,6 +99,7 @@ def __init__( self, search_space: dict[str, BaseDistribution], n_trials: int = 100, + seed: int = -1, *, surrogate_model_type: str = "rf", acq_func_type: str = "ei_log", @@ -113,7 +114,7 @@ def __init__( ) -> None: super().__init__(search_space) self._cs, self._hp_scale_value = self._convert_to_config_space_design_space(search_space) - scenario = Scenario(configspace=self._cs, deterministic=True, n_trials=n_trials) + scenario = Scenario(configspace=self._cs, deterministic=True, n_trials=n_trials, seed=seed) surrogate_model = self._get_surrogate_model( scenario, surrogate_model_type, From 2733097ff358b70c872008d9fac7c02756919106 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Tue, 3 Dec 2024 21:37:09 +0100 Subject: [PATCH 2/2] Add a description of seed --- package/samplers/smac_sampler/sampler.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/package/samplers/smac_sampler/sampler.py b/package/samplers/smac_sampler/sampler.py index 77584ac0..8c3f412a 100644 --- a/package/samplers/smac_sampler/sampler.py +++ b/package/samplers/smac_sampler/sampler.py @@ -55,6 +55,9 @@ class SMACSampler(optunahub.samplers.SimpleBaseSampler): initial design. This argument does not have to be precise, but it is better to be exact for better performance. + seed: + Seed for random number generator. + If ``None`` is given, seed is generated randomly. surrogate_model_type: What model to use for the probabilistic model. Either "gp" (Gaussian process), "gp_mcmc" (Gaussian process with MCMC), or "rf" @@ -99,7 +102,7 @@ def __init__( self, search_space: dict[str, BaseDistribution], n_trials: int = 100, - seed: int = -1, + seed: int | None = None, *, surrogate_model_type: str = "rf", acq_func_type: str = "ei_log", @@ -114,7 +117,9 @@ def __init__( ) -> None: super().__init__(search_space) self._cs, self._hp_scale_value = self._convert_to_config_space_design_space(search_space) - scenario = Scenario(configspace=self._cs, deterministic=True, n_trials=n_trials, seed=seed) + scenario = Scenario( + configspace=self._cs, deterministic=True, n_trials=n_trials, seed=seed or -1 + ) surrogate_model = self._get_surrogate_model( scenario, surrogate_model_type,