Skip to content

Commit 8195adf

Browse files
committed
switched to 3.10
1 parent f13066b commit 8195adf

26 files changed

Lines changed: 897 additions & 150 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Version 1.4.2
2+
3+
## Python 3.10
4+
- Upgraded python version to 3.10
5+
- Switched pyrfr with RandomForestRegressor from sklearn
6+
- Switched pyrfr with Optuna
7+
- Removed pyrfr all together
8+
- Optuna is now installed by default
9+
110
# Version 1.4.1
211

312
## Raytune

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ install-dev:
5555
install-examples:
5656
$(PIP) install -e ".[examples]"
5757

58-
install-optuna:
59-
$(PIP) install -e ".[optuna]"
60-
6158
install-bohb:
6259
$(PIP) install -e ".[bohb]"
6360

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ conda install -c anaconda swig
2525
pip install DeepCAVE
2626
```
2727

28-
To load runs created with Optuna, the BOHB optimizer or RayTune, you need to install the
28+
To load runs created with the BOHB optimizer or RayTune, you need to install the
2929
respective packages by running:
3030
```bash
31-
pip install deepcave[optuna]
3231
pip install deepcave[bohb]
3332
pip install deepcave[raytune]
3433
```

deepcave/evaluators/ablation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
from collections import OrderedDict
3434

3535
import numpy as np
36-
37-
# from deepcave.evaluators.epm.random_forest_surrogate import RandomForestSurrogate
3836
from sklearn.ensemble import RandomForestRegressor
3937

4038
from deepcave.runs import AbstractRun

deepcave/evaluators/epm/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
1919
## Modules
2020
----------
21-
fanova_forest
22-
The module provides utilities for creating a fANOVA forest.
2321
random_forest
2422
This module can be used for training and using a Random Forest Regression model.
2523
random_forest_surrogate

deepcave/evaluators/epm/random_forest.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
1919
This module can be used for training and using a Random Forest Regression model.
2020
21-
A pyrfr wrapper is used for simplification.
22-
2321
## Classes
24-
- RandomForest: A random forest wrapper for pyrfr.
22+
- RandomForest: For training and using a Random Forest Regression model.
2523
2624
## Constants
2725
VERY_SMALL_NUMBER : float
28-
PYRFR_MAPPING : Dict[str, str]
2926
"""
3027

3128
from typing import Any, Dict, Optional, Tuple, Union
@@ -36,13 +33,10 @@
3633
from ConfigSpace import ConfigurationSpace
3734
from ConfigSpace.hyperparameters import (
3835
CategoricalHyperparameter,
39-
Constant,
4036
UniformFloatHyperparameter,
4137
UniformIntegerHyperparameter,
4238
)
4339
from sklearn.decomposition import PCA
44-
45-
# import pyrfr.regression as regression
4640
from sklearn.ensemble import RandomForestRegressor
4741
from sklearn.exceptions import NotFittedError
4842
from sklearn.preprocessing import MinMaxScaler
@@ -62,14 +56,7 @@
6256

6357
class RandomForest:
6458
"""
65-
A random forest wrapper for pyrfr.
66-
67-
This is handy because only the configuration space needs to be passed.
68-
and have a working version without specifying e.g. types and bounds.
69-
70-
Note
71-
----
72-
This wrapper also supports instances.
59+
For training and using a Random Forest Regression model.
7360
7461
Properties
7562
----------
@@ -219,8 +206,7 @@ def _impute_inactive(self, X: np.ndarray) -> np.ndarray:
219206
impute_values[idx] = len(hp.choices)
220207
elif isinstance(hp, (UniformFloatHyperparameter, UniformIntegerHyperparameter)):
221208
impute_values[idx] = -1
222-
elif isinstance(hp, Constant):
223-
impute_values[idx] = 1
209+
224210
else:
225211
raise ValueError
226212

@@ -432,7 +418,7 @@ def predict_marginalized(self, X: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
432418
# Mean per tree across instances
433419
dat_ = np.array([tree.predict(X) for tree in self._model.estimators_]) # shape: (n_trees,)
434420

435-
# 3. compute statistics across trees
421+
# compute statistics across trees
436422
mean_ = dat_.mean(axis=1)
437423
var = dat_.var(axis=1)
438424

deepcave/evaluators/epm/random_forest_surrogate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ def predict(self, X: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
6363
Tuple[np.ndarray, np.ndarray]
6464
The means and standard deviation.
6565
"""
66-
# means, stds = self._model.predict(X)
67-
# return means[:, 0], stds[:, 0]
6866
means, vars_ = self._model.predict(X)
6967
# Convert variance to standard deviation
7068
stds = np.sqrt(vars_)

deepcave/evaluators/fanova.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class fANOVA:
3939
"""
4040
Calculate and provide midpoints and sizes.
4141
42-
They are generated from the forest's split values in order to get the marginals.
43-
4442
Properties
4543
----------
4644
run : AbstractRun
@@ -71,6 +69,7 @@ def calculate(
7169
budget: Optional[Union[int, float]] = None,
7270
n_trees: int = 16,
7371
seed: int = 0,
72+
y: Any = None,
7473
) -> Any:
7574
"""Create Optuna study from data and fit Fanova evaluator."""
7675
if objectives is None:
@@ -83,21 +82,16 @@ def calculate(
8382
df = self.run.get_encoded_data(
8483
objectives, budget, specific=True, include_combined_cost=True
8584
)
86-
8785
X = df[self.hp_names].to_numpy()
8886

8987
# Combined cost name includes the cost of all selected objectives
90-
Y = df[COMBINED_COST_NAME].to_numpy()
88+
if y is not None:
89+
Y = y
90+
else:
91+
Y = df[COMBINED_COST_NAME].to_numpy()
9192

92-
direction = ""
93+
self.study = optuna.create_study()
9394

94-
if isinstance(objectives, Objective):
95-
if objectives.optimize == "upper":
96-
direction = "maximize"
97-
else:
98-
direction = "minimize"
99-
100-
self.study = optuna.create_study(direction=direction)
10195
params: dict = {}
10296
distributions: dict = {}
10397

@@ -112,6 +106,7 @@ def calculate(
112106
if hp.__class__.__name__ == "CategoricalHyperparameter":
113107
# For categorical, val is assumed to be an index
114108
idx = int(val)
109+
115110
params[name] = hp.choices[idx] # type: ignore
116111
distributions[name] = optuna.distributions.CategoricalDistribution(
117112
hp.choices # type: ignore

deepcave/evaluators/lpi.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
)
3535
from ConfigSpace.types import Array, f64
3636
from ConfigSpace.util import impute_inactive_values
37-
38-
# from deepcave.evaluators.epm.fanova_forest import FanovaForest
3937
from sklearn.ensemble import RandomForestRegressor
4038

4139
from deepcave.constants import COMBINED_COST_NAME
@@ -130,7 +128,6 @@ def calculate(
130128
Y = df[COMBINED_COST_NAME].to_numpy()
131129

132130
# Get model and train it
133-
# Use same forest as for fanova
134131
self._model = RandomForestRegressor(n_estimators=n_trees, random_state=seed)
135132
self._model.fit(X, Y)
136133

@@ -180,7 +177,6 @@ def calculate(
180177
)
181178
new_config = impute_inactive_values(Configuration(self.cs, vector=new_array))
182179

183-
# x = np.array(new_config.get_array())
184180
mean, var = self._predict_mean_var(new_config)
185181
performances[hp_name].append(mean)
186182
variances[hp_name].append(var)

deepcave/evaluators/mo_fanova.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515
# noqa: D400
1616
"""
17-
# fANOVA
17+
# MOfANOVA
1818
1919
This module provides a tool for assessing the importance of an algorithms Hyperparameters.
2020
2121
Utilities provide calculation of the data wrt the budget and train the forest on the encoded data.
2222
2323
## Classes
24-
- fANOVA: Calculate and provide midpoints and sizes.
24+
- MOfANOVA: Calculate and provide midpoints and sizes.
2525
"""
2626

27-
from typing import List, Optional, Union
27+
from typing import Any, List, Optional, Union
2828

2929
import pandas as pd
3030

@@ -38,8 +38,6 @@ class MOfANOVA(fANOVA):
3838
"""
3939
Multi-Objective fANOVA.
4040
41-
Calculate and provide midpoints and sizes from the forest's split values in order to get
42-
the marginals.
4341
Override: to train the random forest with an arbitrary weighting of the objectives
4442
(multi-objective case).
4543
"""
@@ -58,6 +56,7 @@ def calculate(
5856
budget: Optional[Union[int, float]] = None,
5957
n_trees: int = 100,
6058
seed: int = 0,
59+
y: Any = None,
6160
) -> None:
6261
"""
6362
Get the data with respect to budget and train the forest on the encoded data.
@@ -103,19 +102,24 @@ def calculate(
103102
df[normed] = 1 - df[normed]
104103
objectives_normed.append(normed)
105104
df = df.dropna(subset=objectives_normed)
106-
# X = df[self.hp_names].to_numpy()
105+
107106
weightings = get_weightings(objectives_normed, df)
107+
108108
df_all = pd.DataFrame([])
109109

110110
# calculate importance for each weighting generated from the pareto efficient points
111111
for w in weightings:
112-
# Y = sum(df[obj] *weighting for obj, weighting in zip(objectives_normed, w)).to_numpy()
112+
Y = sum(df[obj] * weighting for obj, weighting in zip(objectives_normed, w)).to_numpy()
113+
114+
super().calculate(
115+
objectives=objectives, budget=budget, seed=seed, n_trees=self.n_trees, y=Y
116+
)
117+
self.importances = super().get_importances()
113118

114-
self.importances = super().calculate(objectives, budget, seed)
115-
print(self.importances)
116119
df_res = pd.DataFrame.from_dict(self.importances).loc[0:1].T.reset_index()
117120
df_res["weight"] = w[0]
118121
df_all = pd.concat([df_all, df_res])
122+
119123
self.importances_ = df_all.rename(
120124
columns={0: "importance", 1: "variance", "index": "hp_name"}
121125
).reset_index(drop=True)

0 commit comments

Comments
 (0)