Skip to content

Commit 72fa354

Browse files
authored
Merge pull request #85 from automl/enhancement/random_seeds
Enhancement/random seeds
2 parents fea1a2a + dee1631 commit 72fa354

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Bug-Fixes
44
- Fix seaborn style name (#82).
5+
- Remove potential sources of nondeterminism in evaluators by not setting seeds randomly (#75).
56

67
# Version 1.1.2
78

deepcave/evaluators/epm/fanova_forest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(
3030
instance_features: Optional[np.ndarray] = None,
3131
pca_components: Optional[int] = 2,
3232
cutoffs: Tuple[float, float] = (-np.inf, np.inf),
33-
seed: Optional[int] = None,
33+
seed: int = 0,
3434
):
3535
super().__init__(
3636
configspace=configspace,

deepcave/evaluators/epm/random_forest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
instance_features: Optional[np.ndarray] = None,
5757
pca_components: Optional[int] = 2,
5858
log_y: bool = False,
59-
seed: Optional[int] = None,
59+
seed: int = 0,
6060
):
6161
self.cs = configspace
6262
self.log_y = log_y
@@ -295,8 +295,6 @@ def _train(self, X: np.ndarray, Y: np.ndarray) -> None:
295295
# Now we can start to prepare the data for the pyrfr
296296
data = self._get_data_container(X, Y.flatten())
297297
seed = self.seed
298-
if seed is None:
299-
seed = int(random() * 9999)
300298

301299
rng = regression.default_random_engine(seed)
302300

deepcave/evaluators/fanova.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def calculate(
3030
objectives: Optional[Union[Objective, List[Objective]]] = None,
3131
budget: Optional[Union[int, float]] = None,
3232
n_trees: int = 16,
33-
seed: Optional[int] = None,
33+
seed: int = 0,
3434
) -> None:
3535
"""
3636
Get the data wrt budget and trains the forest on the encoded data.
@@ -47,8 +47,8 @@ def calculate(
4747
Considered budget. By default None. If None, the highest budget is chosen.
4848
n_trees : int, optional
4949
How many trees should be used. By default 16.
50-
seed : Optional[int], optional
51-
Random seed. By default None.
50+
seed : int
51+
Random seed. By default 0.
5252
"""
5353
if objectives is None:
5454
objectives = self.run.get_objectives()

deepcave/evaluators/lpi.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def calculate(
3030
budget: Optional[Union[int, float]] = None,
3131
continous_neighbors: int = 500,
3232
n_trees: int = 10,
33-
seed: Optional[int] = None,
33+
seed: int = 0,
3434
) -> None:
3535
"""
3636
Prepares the data and trains a RandomForest model.
@@ -56,9 +56,6 @@ def calculate(
5656
self.default = self.cs.get_default_configuration()
5757
self.incumbent_array = self.incumbent.get_array()
5858

59-
# Set the seed
60-
if seed is None:
61-
seed = int(random() * 9999)
6259
self.seed = seed
6360
self.rs = np.random.RandomState(seed)
6461

tests/test_evaluators/test_fanova.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def test(self):
2121
objective = self.run.get_objective(0)
2222

2323
# Calculate
24-
self.evaluator.calculate(objective, budget)
24+
self.evaluator.calculate(objective, budget, seed=0)
2525
importances = self.evaluator.get_importances(self.hp_names)
2626

27-
self.evaluator.calculate(objective, budget)
27+
self.evaluator.calculate(objective, budget, seed=42)
2828
importances2 = self.evaluator.get_importances(self.hp_names)
2929

30-
# No seed: Different results
30+
# Different seed: Different results
3131
assert importances["n_neurons"][1] != importances2["n_neurons"][1]
3232

3333
def test_seed(self):

0 commit comments

Comments
 (0)