From 84d449e69f4963e7af02c6ca7636e9851ef320e3 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Mon, 12 Jul 2021 16:01:55 -0500 Subject: [PATCH 01/16] Tentative CCS support. --- skopt/optimizer/optimizer.py | 24 ++++++++++--- skopt/space/space.py | 69 +++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 5ca806a8..2bbca9cc 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -4,6 +4,7 @@ from numbers import Number import ConfigSpace as CS +import cconfigspace as CCS import numpy as np import pandas as pd @@ -294,6 +295,11 @@ def __init__( if isinstance(self.base_estimator_, GaussianProcessRegressor): raise RuntimeError("GP estimator is not available with ConfigSpace!") + elif type(dimensions) is CCS.ConfigurationSpace: + self.ccs = dimensions + + if isinstance(self.base_estimator_, GaussianProcessRegressor): + raise RuntimeError("GP estimator is not available with CCS!") else: # normalize space if GP regressor @@ -352,10 +358,16 @@ def copy(self, random_state=None): Set the random state of the copy. """ + dimens = None + if hasattr(self, "config_space"): + dimens = self.config_space + elif hasattr(self, "ccs"): + dimens = self.ccs + else: + dimens = self.space.dimensions + optimizer = Optimizer( - dimensions=self.config_space - if hasattr(self, "config_space") - else self.space.dimensions, + dimensions=dimens, base_estimator=self.base_estimator_, n_initial_points=self.n_initial_points_, initial_point_generator=self._initial_point_generator, @@ -524,7 +536,7 @@ def _ask(self): next_x = self._next_x if next_x is not None: - if not self.space.is_config_space: + if not self.space.is_config_space and not self.space.is_ccs: min_delta_x = min([self.space.distance(next_x, xi) for xi in self.Xi]) if abs(min_delta_x) <= 1e-8: warnings.warn( @@ -563,6 +575,8 @@ def tell(self, x, y, fit=True): """ if self.space.is_config_space: pass + elif self.space.is_ccs: + pass else: check_x_in_space(x, self.space) @@ -686,7 +700,7 @@ def _tell(self, x, y, fit=True): # lbfgs should handle this but just in case there are # precision errors. if not self.space.is_categorical: - if not self.space.is_config_space: + if not self.space.is_config_space and not self.space.is_ccs: next_x = np.clip( next_x, transformed_bounds[:, 0], transformed_bounds[:, 1] ) diff --git a/skopt/space/space.py b/skopt/space/space.py index 4c7dba4e..ed35ac90 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -28,6 +28,7 @@ import ConfigSpace as CS +import cconfigspace as CCS from sklearn.impute import SimpleImputer @@ -888,8 +889,11 @@ class Space(object): def __init__(self, dimensions): self.is_config_space = False + self.is_ccs = False self.config_space_samples = None + self.ccs_samples = None self.config_space_explored = False + self.ccs_explored = False self.imp_const = SimpleImputer( missing_values=np.nan, strategy="constant", fill_value=-1000 ) @@ -957,6 +961,52 @@ def __init__(self, dimensions): else: raise ValueError("Unknown Hyperparameter type.") dimensions = space + elif isinstance(dimensions, CCS.ConfigurationSpace): + self.is_ccs = True + self.ccs = dimensions + self.hps_type = {} + + hps = self.ccs.hyperparameters + cond_hps = [x.name for x in self.ccs.conditional_hyperparameters] + + space = [] + for x in hps: + self.hps_names.append(x.name) + distrib = self.ccs.get_hyperparameter_distribution(x)[0] + if (isinstance(x, CCS.CategoricalHyperparameter) or + isinstance(x, CCS.OrdinalHyperparameter) or + isinstance(x, CCS.DiscreteHyperparameter)): + vals = list(x.values) + if x.name in cond_hps: + vals.append("NA") + if isinstance(distrib, CCS.RouletteDistribution): + param = Categorical(vals, prior=distrib.areas, name=x.name) + elif sinstance(distrib, CCS.UniformDistribution): + param = Categorical(vals, name=x.name) + else: + raise ValueError("Unsupported distribution") + space.append(param) + self.hps_type[x.name] = "Categorical" + elif isinstance(x, CCS.NumericalHyperparameter): + prior = "uniform" + lower = x.lower + upper = x.upper + t = x.data_type + if isinstance(distrib, CCS.UniformDistribution): + if distrib.scale_type == CCS.ccs_scale_type.LOGARITHMIC: + prior = "log-uniform" + else: + raise ValueError("Unsupported distribution") + if CCS.ccs_numeric_type.NUM_INTEGER: + param = Integer(lower, upper, prior=prior, name=x.name) + self.hps_type[x.name] = "Integer" + else: + param = Real(lower, upper, prior=prior, name=x.name) + self.hps_type[x.name] = "Real" + space.append(param) + else: + raise ValueError("Unknown Hyperparameter type") + dimensions = space self.dimensions = [check_dimension(dim) for dim in dimensions] def __eq__(self, other): @@ -1099,6 +1149,23 @@ def rvs(self, n_samples=1, random_state=None): req_points.append(point) return req_points + elif self.is_ccs: + confs = self.ccs.samples(n_samples) + hps = self.ccs.hyperparameters + points = [] + for conf in confs: + point = [] + for hp in hps: + val = conf.value(hp) + if ccs.ccs_inactive == val: + if self.hps_type[hp.name] == "Categorical": + val = "NA" + else: + val = np.nan + point.append(val) + points.append(point) + + return points else: # Draw columns = [] @@ -1178,7 +1245,7 @@ def transform(self, X): # Repack as an array Xt = np.hstack([np.asarray(c).reshape((len(X), -1)) for c in columns]) - if False and self.is_config_space: + if False and (self.is_config_space or self.is_ccs): self.imp_const.fit(Xt) Xtt = self.imp_const.transform(Xt) Xt = Xtt From 745417f94180a5bb1462030d4264e6345cbeb63d Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 20 Aug 2021 11:36:06 -0500 Subject: [PATCH 02/16] Updated to support normal prior. --- skopt/space/space.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/skopt/space/space.py b/skopt/space/space.py index ed35ac90..0c832577 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -995,6 +995,10 @@ def __init__(self, dimensions): if isinstance(distrib, CCS.UniformDistribution): if distrib.scale_type == CCS.ccs_scale_type.LOGARITHMIC: prior = "log-uniform" + elif isinstance(distrib, CCS.NormalDistribution): + prior = "normal" + if distrib.scale_type == CCS.ccs_scale_type.LOGARITHMIC: + raise ValueError("Unsupported 'log' transformation for CCS.NumericalHyperparameter with normal prior.") else: raise ValueError("Unsupported distribution") if CCS.ccs_numeric_type.NUM_INTEGER: From ddd4f0c1a8a0669272ee7434fbe6050ef5a6f0d5 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 3 Sep 2021 15:21:17 -0500 Subject: [PATCH 03/16] Fix typos. --- skopt/space/space.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skopt/space/space.py b/skopt/space/space.py index 0c832577..d715d3f0 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -981,7 +981,7 @@ def __init__(self, dimensions): vals.append("NA") if isinstance(distrib, CCS.RouletteDistribution): param = Categorical(vals, prior=distrib.areas, name=x.name) - elif sinstance(distrib, CCS.UniformDistribution): + elif isinstance(distrib, CCS.UniformDistribution): param = Categorical(vals, name=x.name) else: raise ValueError("Unsupported distribution") @@ -1161,7 +1161,7 @@ def rvs(self, n_samples=1, random_state=None): point = [] for hp in hps: val = conf.value(hp) - if ccs.ccs_inactive == val: + if CCS.ccs_inactive == val: if self.hps_type[hp.name] == "Categorical": val = "NA" else: From a423057ab6b10cd707f63d6e1c4c881073fab0bb Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Tue, 23 Nov 2021 10:44:57 -0600 Subject: [PATCH 04/16] Made CCS support optional. --- skopt/optimizer/optimizer.py | 10 ++++++++-- skopt/space/space.py | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 2bbca9cc..ad3a9223 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -4,7 +4,13 @@ from numbers import Number import ConfigSpace as CS -import cconfigspace as CCS +ccs_active = False +try: + import cconfigspace as CCS + ccs_active = True +except ImportError as a: + warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) + import numpy as np import pandas as pd @@ -295,7 +301,7 @@ def __init__( if isinstance(self.base_estimator_, GaussianProcessRegressor): raise RuntimeError("GP estimator is not available with ConfigSpace!") - elif type(dimensions) is CCS.ConfigurationSpace: + elif ccs_active and isinstance(dimensions, CCS.ConfigurationSpace): self.ccs = dimensions if isinstance(self.base_estimator_, GaussianProcessRegressor): diff --git a/skopt/space/space.py b/skopt/space/space.py index d715d3f0..5a9de456 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -28,7 +28,12 @@ import ConfigSpace as CS -import cconfigspace as CCS +ccs_active = False +try: + import cconfigspace as CCS + ccs_active = True +except ImportError as a: + warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) from sklearn.impute import SimpleImputer @@ -961,7 +966,7 @@ def __init__(self, dimensions): else: raise ValueError("Unknown Hyperparameter type.") dimensions = space - elif isinstance(dimensions, CCS.ConfigurationSpace): + elif ccs_active && isinstance(dimensions, CCS.ConfigurationSpace): self.is_ccs = True self.ccs = dimensions self.hps_type = {} From 066924c8319d72b57afae15e528b1b97c5d2d3db Mon Sep 17 00:00:00 2001 From: Jaehoon Koo Date: Tue, 23 Nov 2021 15:02:35 -0600 Subject: [PATCH 05/16] fix CCS support optional --- skopt/space/space.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skopt/space/space.py b/skopt/space/space.py index 5a9de456..a1860330 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -966,7 +966,7 @@ def __init__(self, dimensions): else: raise ValueError("Unknown Hyperparameter type.") dimensions = space - elif ccs_active && isinstance(dimensions, CCS.ConfigurationSpace): + elif ccs_active & isinstance(dimensions, CCS.ConfigurationSpace): self.is_ccs = True self.ccs = dimensions self.hps_type = {} From 0cb055e3607731c1b80bfc35e408cbd064b8c37c Mon Sep 17 00:00:00 2001 From: Jaehoon Koo Date: Tue, 23 Nov 2021 15:16:22 -0600 Subject: [PATCH 06/16] fix CCS support optional --- skopt/optimizer/optimizer.py | 3 ++- skopt/space/space.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index ad3a9223..2de8266d 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -9,7 +9,8 @@ import cconfigspace as CCS ccs_active = True except ImportError as a: - warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) + import warnings + warnings.warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) import numpy as np import pandas as pd diff --git a/skopt/space/space.py b/skopt/space/space.py index a1860330..dcbc130e 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -33,7 +33,8 @@ import cconfigspace as CCS ccs_active = True except ImportError as a: - warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) + import warnings + warnings.warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) from sklearn.impute import SimpleImputer From 81982b8d731daf141ad914849efd85b1bfe58d64 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Tue, 23 Nov 2021 15:55:40 -0600 Subject: [PATCH 07/16] Minor fixes and improvement to CCS support. --- skopt/optimizer/optimizer.py | 1 - skopt/space/space.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 2de8266d..1a481c9c 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -9,7 +9,6 @@ import cconfigspace as CCS ccs_active = True except ImportError as a: - import warnings warnings.warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) import numpy as np diff --git a/skopt/space/space.py b/skopt/space/space.py index dcbc130e..4ccd4fc4 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -967,7 +967,7 @@ def __init__(self, dimensions): else: raise ValueError("Unknown Hyperparameter type.") dimensions = space - elif ccs_active & isinstance(dimensions, CCS.ConfigurationSpace): + elif ccs_active and isinstance(dimensions, CCS.ConfigurationSpace): self.is_ccs = True self.ccs = dimensions self.hps_type = {} From 1697e3ab2f6613d75b1f0f36520b70aae5667e8b Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Tue, 23 Nov 2021 16:38:11 -0600 Subject: [PATCH 08/16] Check for the space type to get hyperparameters' names. --- skopt/optimizer/optimizer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 1a481c9c..396c9979 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -495,6 +495,8 @@ def _filter_duplicated(self, samples): if hasattr(self, "config_space"): hps_names = self.config_space.get_hyperparameter_names() + elif hasattr(self, "ccs"): + hps_names = [x.name for x in self.ccs.hyperparameters] else: hps_names = self.space.dimension_names From 9a5a87c382d3496815b2ebf5a89815576d2e659c Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Tue, 23 Nov 2021 16:48:14 -0600 Subject: [PATCH 09/16] Handle the CCS library not being found on the system. --- skopt/optimizer/optimizer.py | 2 +- skopt/space/space.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 396c9979..397bf282 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -8,7 +8,7 @@ try: import cconfigspace as CCS ccs_active = True -except ImportError as a: +except (ImportError, OSError) as a: warnings.warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) import numpy as np diff --git a/skopt/space/space.py b/skopt/space/space.py index 4ccd4fc4..1f32a043 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -32,7 +32,7 @@ try: import cconfigspace as CCS ccs_active = True -except ImportError as a: +except (ImportError, OSError) as a: import warnings warnings.warn("CCS could not be loaded and is deactivated: " + str(a), category=ImportWarning) From 203649b465fa5dd95672240d42727a70377f446f Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Thu, 2 Jun 2022 14:38:31 -0500 Subject: [PATCH 10/16] Optimize CCS code path. --- skopt/space/space.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/skopt/space/space.py b/skopt/space/space.py index 1f32a043..fbc5d108 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -1165,8 +1165,9 @@ def rvs(self, n_samples=1, random_state=None): points = [] for conf in confs: point = [] - for hp in hps: - val = conf.value(hp) + values = conf.values + for i, hp in enumerate(hps): + val = values[i] if CCS.ccs_inactive == val: if self.hps_type[hp.name] == "Categorical": val = "NA" From 98f82efb1fff0d461d58491823c14e312664a318 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 22 Jul 2022 11:34:55 -0500 Subject: [PATCH 11/16] Fix normalization of log integer (Thanks @Deathn0t). --- skopt/space/space.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/skopt/space/space.py b/skopt/space/space.py index fbc5d108..4faff46e 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -673,9 +673,12 @@ def __contains__(self, point): @property def transformed_bounds(self): if self.transform_ == "normalize": - return 0., 1. + return 0.0, 1.0 else: - return (self.low, self.high) + if self.prior == "uniform": + return self.low, self.high + else: + return np.log10(self.low), np.log10(self.high) def distance(self, a, b): """Compute distance between point `a` and `b`. From 545c6f56c8fdac3e77685fb16522e46c7d1ac236 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 22 Jul 2022 14:04:06 -0500 Subject: [PATCH 12/16] Add support for returning default configurations of CCS and ConfigSpace. --- skopt/optimizer/optimizer.py | 50 +++++++++++++++---------- skopt/space/space.py | 71 ++++++++++++++++++++++-------------- 2 files changed, 74 insertions(+), 47 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 397bf282..854ef21a 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -394,6 +394,35 @@ def copy(self, random_state=None): return optimizer + def _lie_to_optimizer(self, opt, strategy, x): + ti_available = "ps" in self.acq_func and len(opt.yi) > 0 + ti = [t for (_, t) in opt.yi] if ti_available else None + if strategy == "cl_min": + y_lie = np.min(opt.yi) if opt.yi else 0.0 # CL-min lie + t_lie = np.min(ti) if ti is not None else log(sys.float_info.max) + elif strategy == "cl_mean": + y_lie = np.mean(opt.yi) if opt.yi else 0.0 # CL-mean lie + t_lie = np.mean(ti) if ti is not None else log(sys.float_info.max) + else: + y_lie = np.max(opt.yi) if opt.yi else 0.0 # CL-max lie + t_lie = np.max(ti) if ti is not None else log(sys.float_info.max) + + # Lie to the optimizer. + if "ps" in self.acq_func: + # Use `_tell()` instead of `tell()` to prevent repeated + # log transformations of the computation times. + opt._tell(x, (y_lie, t_lie)) + else: + opt._tell(x, y_lie) + + def ask_default(self, strategy="cl_min"): + x = self.space.default() + if x is not None: + self.sampled.append(x) + opt = self.copy(random_state=self.rng.randint(0, np.iinfo(np.int32).max)) + self._lie_to_optimizer(opt, strategy, x) + return x + def ask(self, n_points=None, strategy="cl_min"): """Query point or multiple points at which objective should be evaluated. @@ -463,26 +492,7 @@ def ask(self, n_points=None, strategy="cl_min"): if i == n_points - 1: break - ti_available = "ps" in self.acq_func and len(opt.yi) > 0 - ti = [t for (_, t) in opt.yi] if ti_available else None - - if strategy == "cl_min": - y_lie = np.min(opt.yi) if opt.yi else 0.0 # CL-min lie - t_lie = np.min(ti) if ti is not None else log(sys.float_info.max) - elif strategy == "cl_mean": - y_lie = np.mean(opt.yi) if opt.yi else 0.0 # CL-mean lie - t_lie = np.mean(ti) if ti is not None else log(sys.float_info.max) - else: - y_lie = np.max(opt.yi) if opt.yi else 0.0 # CL-max lie - t_lie = np.max(ti) if ti is not None else log(sys.float_info.max) - - # Lie to the optimizer. - if "ps" in self.acq_func: - # Use `_tell()` instead of `tell()` to prevent repeated - # log transformations of the computation times. - opt._tell(x, (y_lie, t_lie)) - else: - opt._tell(x, y_lie) + self._lie_to_optimizer(opt, strategy, x) self.cache_ = {(n_points, strategy): X} # cache_ the result diff --git a/skopt/space/space.py b/skopt/space/space.py index 4faff46e..e28e03d7 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -1121,6 +1121,43 @@ def from_yaml(cls, yml_path, namespace=None): return space + def _cs_post_process_conf(self, hps_names, conf): + point = [] + for hp_name in hps_names: + val = np.nan + if self.hps_type[hp_name] == "Categorical": + val = "NA" + if hp_name in conf.keys(): + val = conf[hp_name] + point.append(val) + return point + + + def _ccs_post_process_conf(self, hps_names, conf): + point = [] + values = conf.values + for i, hp_name in enumerate(hps_names): + val = values[i] + if CCS.ccs_inactive == val: + if self.hps_type[hp_name] == "Categorical": + val = "NA" + else: + val = np.nan + point.append(val) + return point + + def default(self): + if self.is_config_space: + conf = self.config_space.get_default_configuration() + hps_names = self.config_space.get_hyperparameter_names() + return self._cs_post_process_conf(hps_names, conf) + elif self.is_ccs: + conf = self.ccs.default_configuration + hps_names = [x.name for x in self.ccs.hyperparameters] + return self._ccs_post_process_conf(hps_names, conf) + else: + return None + def rvs(self, n_samples=1, random_state=None): """Draw random samples. @@ -1143,42 +1180,22 @@ def rvs(self, n_samples=1, random_state=None): """ rng = check_random_state(random_state) if self.is_config_space: - req_points = [] - + points = [] confs = self.config_space.sample_configuration(n_samples) if n_samples == 1: confs = [confs] - hps_names = self.config_space.get_hyperparameter_names() for conf in confs: - point = [] - for hps_name in hps_names: - val = np.nan - if self.hps_type[hps_name] == "Categorical": - val = "NA" - if hps_name in conf.keys(): - val = conf[hps_name] - point.append(val) - req_points.append(point) - - return req_points + point = self._cs_post_process_conf(hps_names, conf) + points.append(point) + return points elif self.is_ccs: - confs = self.ccs.samples(n_samples) - hps = self.ccs.hyperparameters points = [] + confs = self.ccs.samples(n_samples) + hps_names = [x.name for x in self.ccs.hyperparameters] for conf in confs: - point = [] - values = conf.values - for i, hp in enumerate(hps): - val = values[i] - if CCS.ccs_inactive == val: - if self.hps_type[hp.name] == "Categorical": - val = "NA" - else: - val = np.nan - point.append(val) + point = self._ccs_post_process_conf(hps_names, conf) points.append(point) - return points else: # Draw From cd0eb432ab259bc878e9ce5e376849e72206dd32 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Thu, 6 Apr 2023 19:10:44 -0500 Subject: [PATCH 13/16] CCS renamed hyperparameter to parameter. --- skopt/optimizer/optimizer.py | 2 +- skopt/space/space.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 854ef21a..3ef8492b 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -506,7 +506,7 @@ def _filter_duplicated(self, samples): if hasattr(self, "config_space"): hps_names = self.config_space.get_hyperparameter_names() elif hasattr(self, "ccs"): - hps_names = [x.name for x in self.ccs.hyperparameters] + hps_names = [x.name for x in self.ccs.parameters] else: hps_names = self.space.dimension_names diff --git a/skopt/space/space.py b/skopt/space/space.py index e28e03d7..27d77442 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -975,16 +975,16 @@ def __init__(self, dimensions): self.ccs = dimensions self.hps_type = {} - hps = self.ccs.hyperparameters - cond_hps = [x.name for x in self.ccs.conditional_hyperparameters] + hps = self.ccs.parameters + cond_hps = [x.name for x in self.ccs.conditional_parameters] space = [] for x in hps: self.hps_names.append(x.name) - distrib = self.ccs.get_hyperparameter_distribution(x)[0] - if (isinstance(x, CCS.CategoricalHyperparameter) or - isinstance(x, CCS.OrdinalHyperparameter) or - isinstance(x, CCS.DiscreteHyperparameter)): + distrib = self.ccs.get_parameter_distribution(x)[0] + if (isinstance(x, CCS.CategoricalParameter) or + isinstance(x, CCS.OrdinalParameter) or + isinstance(x, CCS.DiscreteParameter)): vals = list(x.values) if x.name in cond_hps: vals.append("NA") @@ -996,7 +996,7 @@ def __init__(self, dimensions): raise ValueError("Unsupported distribution") space.append(param) self.hps_type[x.name] = "Categorical" - elif isinstance(x, CCS.NumericalHyperparameter): + elif isinstance(x, CCS.NumericalParameter): prior = "uniform" lower = x.lower upper = x.upper @@ -1007,7 +1007,7 @@ def __init__(self, dimensions): elif isinstance(distrib, CCS.NormalDistribution): prior = "normal" if distrib.scale_type == CCS.ccs_scale_type.LOGARITHMIC: - raise ValueError("Unsupported 'log' transformation for CCS.NumericalHyperparameter with normal prior.") + raise ValueError("Unsupported 'log' transformation for CCS.NumericalParameter with normal prior.") else: raise ValueError("Unsupported distribution") if CCS.ccs_numeric_type.NUM_INTEGER: @@ -1018,7 +1018,7 @@ def __init__(self, dimensions): self.hps_type[x.name] = "Real" space.append(param) else: - raise ValueError("Unknown Hyperparameter type") + raise ValueError("Unknown Parameter type") dimensions = space self.dimensions = [check_dimension(dim) for dim in dimensions] @@ -1153,7 +1153,7 @@ def default(self): return self._cs_post_process_conf(hps_names, conf) elif self.is_ccs: conf = self.ccs.default_configuration - hps_names = [x.name for x in self.ccs.hyperparameters] + hps_names = [x.name for x in self.ccs.parameters] return self._ccs_post_process_conf(hps_names, conf) else: return None @@ -1192,7 +1192,7 @@ def rvs(self, n_samples=1, random_state=None): elif self.is_ccs: points = [] confs = self.ccs.samples(n_samples) - hps_names = [x.name for x in self.ccs.hyperparameters] + hps_names = [x.name for x in self.ccs.parameters] for conf in confs: point = self._ccs_post_process_conf(hps_names, conf) points.append(point) From c0bad9b36b90d8fe61e21c24a4f133403a63269d Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Thu, 20 Apr 2023 09:58:04 -0500 Subject: [PATCH 14/16] Update to reflect constant renaming. --- skopt/space/space.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skopt/space/space.py b/skopt/space/space.py index 27d77442..7b8aa332 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -1010,7 +1010,7 @@ def __init__(self, dimensions): raise ValueError("Unsupported 'log' transformation for CCS.NumericalParameter with normal prior.") else: raise ValueError("Unsupported distribution") - if CCS.ccs_numeric_type.NUM_INTEGER: + if CCS.ccs_numeric_type.INT: param = Integer(lower, upper, prior=prior, name=x.name) self.hps_type[x.name] = "Integer" else: From d4ff571c4d349bdefa7d6b41fa76c05f096594bc Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Mon, 24 Apr 2023 12:52:36 -0500 Subject: [PATCH 15/16] Reflect name changes in CCS. --- skopt/space/space.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/skopt/space/space.py b/skopt/space/space.py index 7b8aa332..f4fe68d3 100644 --- a/skopt/space/space.py +++ b/skopt/space/space.py @@ -1002,15 +1002,15 @@ def __init__(self, dimensions): upper = x.upper t = x.data_type if isinstance(distrib, CCS.UniformDistribution): - if distrib.scale_type == CCS.ccs_scale_type.LOGARITHMIC: + if distrib.scale_type == CCS.ScaleType.LOGARITHMIC: prior = "log-uniform" elif isinstance(distrib, CCS.NormalDistribution): prior = "normal" - if distrib.scale_type == CCS.ccs_scale_type.LOGARITHMIC: + if distrib.scale_type == CCS.ScaleType.LOGARITHMIC: raise ValueError("Unsupported 'log' transformation for CCS.NumericalParameter with normal prior.") else: raise ValueError("Unsupported distribution") - if CCS.ccs_numeric_type.INT: + if CCS.NumericType.INT: param = Integer(lower, upper, prior=prior, name=x.name) self.hps_type[x.name] = "Integer" else: @@ -1138,7 +1138,7 @@ def _ccs_post_process_conf(self, hps_names, conf): values = conf.values for i, hp_name in enumerate(hps_names): val = values[i] - if CCS.ccs_inactive == val: + if CCS.inactive == val: if self.hps_type[hp_name] == "Categorical": val = "NA" else: From eb0c753e5460947492f55fc33b7a8792acdb5266 Mon Sep 17 00:00:00 2001 From: Xingfu <38541094+wuxf99@users.noreply.github.com> Date: Tue, 30 May 2023 17:22:25 -0500 Subject: [PATCH 16/16] Update optimizer.py use pd.concat to replace .append for pandas --- skopt/optimizer/optimizer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skopt/optimizer/optimizer.py b/skopt/optimizer/optimizer.py index 3ef8492b..539fb940 100644 --- a/skopt/optimizer/optimizer.py +++ b/skopt/optimizer/optimizer.py @@ -516,7 +516,8 @@ def _filter_duplicated(self, samples): if len(self.sampled) > 0: df_history = pd.DataFrame(data=self.sampled, columns=hps_names) df_merge = pd.merge(df_samples, df_history, on=None, how="inner") - df_samples = df_samples.append(df_merge) + #df_samples = df_samples.append(df_merge) + df_samples = pd.concat([df_samples, df_merge]) df_samples = df_samples[~df_samples.duplicated(keep=False)] if len(df_samples) > 0: