Skip to content

Commit af32ac6

Browse files
committed
clean up removing bayes search
fix tests update docs cleanup
1 parent 800fd5b commit af32ac6

22 files changed

+139
-411
lines changed

autoemulate/compare.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ def setup(
7575
param_search : bool
7676
Whether to perform hyperparameter search over predifined parameter grids.
7777
param_search_type : str
78-
Type of hyperparameter search to perform. Currently only "random".
78+
Type of hyperparameter search to perform. Currently only "random", which picks random parameter settings
79+
from a grid param_search_iters times.
7980
param_search_iters : int
8081
Number of parameter settings that are sampled. Only used if
81-
param_search=True and param_search_type="random".
82+
param_search=True.
8283
scale : bool, default=True
8384
Whether to scale features/parameters in X before fitting the models using a scaler.
8485
scaler : sklearn.preprocessing.StandardScaler

autoemulate/emulators/conditional_neural_process.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -256,34 +256,23 @@ def predict(self, X, return_std=False):
256256
return mean
257257

258258
@staticmethod
259-
def get_grid_params(search_type: str = "random"):
260-
param_space = {
261-
"max_epochs": [100, 200, 300],
262-
"batch_size": [16, 32],
263-
"hidden_dim": [32, 64, 128],
264-
"latent_dim": [32, 64, 128],
265-
"max_context_points": [5, 10, 15],
266-
"hidden_layers_enc": [2, 3, 4],
267-
"hidden_layers_dec": [2, 3, 4],
268-
"activation": [
269-
nn.ReLU,
270-
nn.GELU,
271-
],
272-
"optimizer": [torch.optim.AdamW], #
273-
"lr": loguniform(5e-4, 1e-3, 5e-3, 1e-2),
274-
}
275-
# # match search_type:
276-
# case "random":
277-
# param_space |= {
278-
# "lr": loguniform(1e-4, 1e-2),
279-
# }
280-
# case "bayes":
281-
# param_space |= {
282-
# "lr": Real(1e-4, 1e-2, prior="log-uniform"),
283-
# }
284-
# case _:
285-
# raise ValueError(f"Invalid search type: {search_type}")
286-
259+
def get_grid_params(self, search_type="random"):
260+
if search_type == "random":
261+
param_space = {
262+
"max_epochs": [100, 200, 300],
263+
"batch_size": [16, 32],
264+
"hidden_dim": [32, 64, 128],
265+
"latent_dim": [32, 64, 128],
266+
"max_context_points": [5, 10, 15],
267+
"hidden_layers_enc": [2, 3, 4],
268+
"hidden_layers_dec": [2, 3, 4],
269+
"activation": [
270+
nn.ReLU,
271+
nn.GELU,
272+
],
273+
"optimizer": [torch.optim.AdamW], #
274+
"lr": loguniform(5e-4, 1e-3, 5e-3, 1e-2),
275+
}
287276
return param_space
288277

289278
@property

autoemulate/emulators/gaussian_process.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,8 @@ def poly_mean(n_features, n_outputs):
320320
],
321321
"optimizer": [torch.optim.AdamW, torch.optim.Adam],
322322
"lr": [5e-1, 1e-1, 5e-2, 1e-2],
323-
"max_epochs": [
324-
50,
325-
100,
326-
200,
327-
],
323+
"max_epochs": [50, 100, 200],
328324
}
329-
else:
330-
raise ValueError("search_type must be 'random'")
331-
332325
return param_space
333326

334327
@property

autoemulate/emulators/gaussian_process_mogp.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from sklearn.utils.validation import check_array
66
from sklearn.utils.validation import check_is_fitted
77
from sklearn.utils.validation import check_X_y
8-
from skopt.space import Categorical
9-
from skopt.space import Real
108

119

1210
class GaussianProcessMOGP(BaseEstimator, RegressorMixin):
@@ -67,19 +65,13 @@ def predict(self, X, return_std=False):
6765
return np.asarray(self.model_.predict(X).mean)
6866

6967
def get_grid_params(self, search_type="random"):
70-
"""Returns the grid parameters of the emulator."""
71-
param_space_random = {
72-
"nugget": ["fit", "adaptive", "pivot"],
73-
}
74-
param_space_bayes = {
75-
"nugget": Categorical(["fit", "adaptive", "pivot"]),
76-
}
77-
68+
"""
69+
Get the parameter space.
70+
"""
7871
if search_type == "random":
79-
param_space = param_space_random
80-
elif search_type == "bayes":
81-
param_space = param_space_bayes
82-
72+
param_space = {
73+
"nugget": ["fit", "adaptive", "pivot"],
74+
}
8375
return param_space
8476

8577
@property

autoemulate/emulators/gaussian_process_mt.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,8 @@ def poly_mean(n_features):
266266
],
267267
"optimizer": [torch.optim.AdamW, torch.optim.Adam],
268268
"lr": [5e-1, 1e-1, 5e-2, 1e-2],
269-
"max_epochs": [
270-
50,
271-
100,
272-
200,
273-
],
269+
"max_epochs": [50, 100, 200],
274270
}
275-
else:
276-
raise ValueError("search_type must be 'random'")
277-
278271
return param_space
279272

280273
@property

autoemulate/emulators/gaussian_process_sklearn.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from sklearn.utils.validation import check_array
1010
from sklearn.utils.validation import check_is_fitted
1111
from sklearn.utils.validation import check_X_y
12-
from skopt.space import Categorical
13-
from skopt.space import Real
1412

1513
from autoemulate.utils import _suppress_convergence_warnings
1614

@@ -95,29 +93,18 @@ def predict(self, X, return_std=False):
9593

9694
def get_grid_params(self, search_type="random"):
9795
"""Returns the grid parameters of the emulator."""
98-
param_space_random = {
99-
"kernel": [
100-
RBF(),
101-
Matern(),
102-
RationalQuadratic(),
103-
# DotProduct(),
104-
],
105-
"optimizer": ["fmin_l_bfgs_b"],
106-
"alpha": loguniform(1e-10, 1e-2),
107-
"normalize_y": [True],
108-
}
109-
param_space_bayes = {
110-
# "kernel": Categorical([RBF(), Matern()]), # unhashable type
111-
"optimizer": Categorical(["fmin_l_bfgs_b"]),
112-
"alpha": Real(1e-10, 1e-2, prior="log-uniform"),
113-
"normalize_y": Categorical([True]),
114-
}
115-
11696
if search_type == "random":
117-
param_space = param_space_random
118-
elif search_type == "bayes":
119-
param_space = param_space_bayes
120-
97+
param_space = {
98+
"kernel": [
99+
RBF(),
100+
Matern(),
101+
RationalQuadratic(),
102+
# DotProduct(),
103+
],
104+
"optimizer": ["fmin_l_bfgs_b"],
105+
"alpha": loguniform(1e-10, 1e-2),
106+
"normalize_y": [True],
107+
}
121108
return param_space
122109

123110
@property

autoemulate/emulators/gradient_boosting.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from sklearn.utils.validation import check_array
88
from sklearn.utils.validation import check_is_fitted
99
from sklearn.utils.validation import check_X_y
10-
from skopt.space import Categorical
11-
from skopt.space import Integer
12-
from skopt.space import Real
1310

1411

1512
class GradientBoosting(BaseEstimator, RegressorMixin):
@@ -101,33 +98,17 @@ def predict(self, X):
10198

10299
def get_grid_params(self, search_type="random"):
103100
"""Returns the grid parameters of the emulator."""
104-
param_space_random = {
105-
"learning_rate": loguniform(0.01, 0.2),
106-
"n_estimators": randint(100, 500),
107-
"max_depth": randint(3, 8),
108-
"min_samples_split": randint(2, 20),
109-
"min_samples_leaf": randint(1, 6),
110-
"subsample": uniform(0.6, 0.4), # 0.4 is the range width (1.0 - 0.6)
111-
"max_features": ["sqrt", "log2", None],
112-
"ccp_alpha": loguniform(0.001, 0.1),
113-
}
114-
115-
param_space_bayes = {
116-
"learning_rate": Real(0.01, 0.2, prior="log-uniform"),
117-
"n_estimators": Integer(100, 500),
118-
"max_depth": Integer(3, 8),
119-
"min_samples_split": Integer(2, 20),
120-
"min_samples_leaf": Integer(1, 6),
121-
"subsample": Real(0.6, 1.0),
122-
"max_features": Categorical(["sqrt", "log2", None]),
123-
"ccp_alpha": Real(0.01, 0.1, prior="log-uniform"),
124-
}
125-
126101
if search_type == "random":
127-
param_space = param_space_random
128-
elif search_type == "bayes":
129-
param_space = param_space_bayes
130-
102+
param_space = {
103+
"learning_rate": loguniform(0.01, 0.2),
104+
"n_estimators": randint(100, 500),
105+
"max_depth": randint(3, 8),
106+
"min_samples_split": randint(2, 20),
107+
"min_samples_leaf": randint(1, 6),
108+
"subsample": uniform(0.6, 0.4), # 0.4 is the range width (1.0 - 0.6)
109+
"max_features": ["sqrt", "log2", None],
110+
"ccp_alpha": loguniform(0.001, 0.1),
111+
}
131112
return param_space
132113

133114
@property

autoemulate/emulators/light_gbm.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
from sklearn.utils.validation import check_array
99
from sklearn.utils.validation import check_is_fitted
1010
from sklearn.utils.validation import check_X_y
11-
from skopt.space import Categorical
12-
from skopt.space import Integer
13-
from skopt.space import Real
1411

1512

1613
class LightGBM(BaseEstimator, RegressorMixin):
@@ -107,33 +104,17 @@ def predict(self, X):
107104

108105
def get_grid_params(self, search_type="random"):
109106
"""Returns the grid parameters of the emulator."""
110-
param_space_random = {
111-
"boosting_type": ["gbdt"],
112-
"num_leaves": randint(10, 100),
113-
"max_depth": randint(-1, 12),
114-
"learning_rate": loguniform(0.001, 0.1),
115-
"n_estimators": randint(50, 1000),
116-
# "colsample_bytree": uniform(0.5, 1.0),
117-
"reg_alpha": loguniform(0.001, 1),
118-
"reg_lambda": loguniform(0.001, 1),
119-
}
120-
121-
param_space_bayes = {
122-
"boosting_type": Categorical(["gbdt"]),
123-
"num_leaves": Integer(10, 100),
124-
"max_depth": Integer(-1, 12),
125-
"learning_rate": Real(0.001, 0.1, prior="log-uniform"),
126-
"n_estimators": Integer(50, 1000),
127-
# "colsample_bytree": Real(0.5, 1.0),
128-
"reg_alpha": Real(0.001, 1, prior="log-uniform"),
129-
"reg_lambda": Real(0.001, 1, prior="log-uniform"),
130-
}
131-
132107
if search_type == "random":
133-
param_space = param_space_random
134-
elif search_type == "bayes":
135-
param_space = param_space_bayes
136-
108+
param_space = {
109+
"boosting_type": ["gbdt"],
110+
"num_leaves": randint(10, 100),
111+
"max_depth": randint(-1, 12),
112+
"learning_rate": loguniform(0.001, 0.1),
113+
"n_estimators": randint(50, 1000),
114+
# "colsample_bytree": uniform(0.5, 1.0),
115+
"reg_alpha": loguniform(0.001, 1),
116+
"reg_lambda": loguniform(0.001, 1),
117+
}
137118
return param_space
138119

139120
@property

autoemulate/emulators/neural_net_sk.py

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from sklearn.utils.validation import check_array
77
from sklearn.utils.validation import check_is_fitted
88
from sklearn.utils.validation import check_X_y
9-
from skopt.space import Categorical
10-
from skopt.space import Real
119

1210
from autoemulate.utils import _suppress_convergence_warnings
1311

@@ -98,40 +96,20 @@ def predict(self, X):
9896

9997
def get_grid_params(self, search_type="random"):
10098
"""Returns the grid parameters of the emulator."""
101-
param_space_random = {
102-
"hidden_layer_sizes": [
103-
(50,),
104-
(100,),
105-
(100, 50),
106-
(100, 100),
107-
(100, 100, 100),
108-
],
109-
"activation": ["relu"], # "tanh", "logistic"
110-
"solver": ["adam", "lbfgs"], # "sgd",
111-
"alpha": loguniform(1e-5, 1e-1),
112-
"learning_rate_init": loguniform(1e-4, 1e-2),
113-
}
114-
115-
param_space_bayes = {
116-
# doesn't work with bayes
117-
# "hidden_layer_sizes": Categorical([
118-
# (50,),
119-
# (100,),
120-
# (100, 50),
121-
# (100, 100),
122-
# (100, 100, 100),
123-
# ]),
124-
"activation": Categorical(["relu"]), # Add "tanh", "logistic" if needed
125-
"solver": Categorical(["adam", "lbfgs"]), # Add "sgd" if needed
126-
"alpha": Real(1e-5, 1e-1, prior="log-uniform"),
127-
"learning_rate_init": Real(1e-4, 1e-2, prior="log-uniform"),
128-
}
129-
13099
if search_type == "random":
131-
param_space = param_space_random
132-
elif search_type == "bayes":
133-
param_space = param_space_bayes
134-
100+
param_space = {
101+
"hidden_layer_sizes": [
102+
(50,),
103+
(100,),
104+
(100, 50),
105+
(100, 100),
106+
(100, 100, 100),
107+
],
108+
"activation": ["relu"],
109+
"solver": ["adam", "lbfgs"],
110+
"alpha": loguniform(1e-5, 1e-1),
111+
"learning_rate_init": loguniform(1e-4, 1e-2),
112+
}
135113
return param_space
136114

137115
@property
@@ -140,24 +118,3 @@ def model_name(self):
140118

141119
def _more_tags(self):
142120
return {"multioutput": True}
143-
144-
# def score(self, X, y, metric):
145-
# """Returns the score of the emulator.
146-
147-
# Parameters
148-
# ----------
149-
# X : array-like, shape (n_samples, n_features)
150-
# Simulation input.
151-
# y : array-like, shape (n_samples, n_outputs)
152-
# Simulation output.
153-
# metric : str
154-
# Name of the metric to use, currently either rsme or r2.
155-
156-
# Returns
157-
# -------
158-
# metric : float
159-
# Metric of the emulator.
160-
# """
161-
162-
# predictions = self.predict(X)
163-
# return metric(y, predictions)

autoemulate/emulators/neural_networks/cnp_module.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import torch.nn as nn
44
import torch.nn.functional as F
55
from scipy.stats import loguniform
6-
from skopt.space import Categorical
7-
from skopt.space import Real
86

97

108
class Encoder(nn.Module):

0 commit comments

Comments
 (0)