Esempio n. 1
0
    def _convert_photon_to_smac_param(hyperparam: object, name: str):
        """
        Helper function: Convert PHOTON hyperparameter to SMAC hyperparameter.

        Parameters
        ----------
        * `hyperparam` [object]:
             One of photonai.optimization.hyperparameters.
        * `name` [str]
            Name of hyperparameter.
        """
        if not hyperparam:
            return None
        if isinstance(hyperparam, PhotonCategorical):
            return CategoricalHyperparameter(name, hyperparam.values)
        elif isinstance(hyperparam, list):
            return CategoricalHyperparameter(name, hyperparam)
        elif isinstance(hyperparam, FloatRange):
            if hyperparam.range_type == 'linspace':
                return UniformFloatHyperparameter(name, hyperparam.start, hyperparam.stop)
            elif hyperparam.range_type == 'logspace':
                raise NotImplementedError("Logspace in your float hyperparameter is not implemented in SMAC.")
            else:
                return UniformFloatHyperparameter(name, hyperparam.start, hyperparam.stop)
        elif isinstance(hyperparam, IntegerRange):
            return UniformIntegerHyperparameter(name, hyperparam.start, hyperparam.stop)
Esempio n. 2
0
 def _get_acm_cs(self):
     """
         returns a configuration space 
         designed for querying ~smac.optimizer.smbo._component_builder
         
         Returns
         ------- 
             ConfigurationSpace
     """
     
     cs = ConfigurationSpace()
     cs.seed(self.rng.randint(0,2**20))
     
     model = CategoricalHyperparameter("model", choices=("RF", "GP"))
     
     num_trees = Constant("num_trees", value=10)
     bootstrap = CategoricalHyperparameter("do_bootstrapping", choices=(True, False), default_value=True)
     ratio_features = CategoricalHyperparameter("ratio_features", choices=(3 / 6, 4 / 6, 5 / 6, 1), default_value=1)
     min_split = UniformIntegerHyperparameter("min_samples_to_split", lower=1, upper=10, default_value=2)
     min_leaves = UniformIntegerHyperparameter("min_samples_in_leaf", lower=1, upper=10, default_value=1)
     
     cs.add_hyperparameters([model, num_trees, bootstrap, ratio_features, min_split, min_leaves])
     
     inc_num_trees = InCondition(num_trees, model, ["RF"])
     inc_bootstrap = InCondition(bootstrap, model, ["RF"])
     inc_ratio_features = InCondition(ratio_features, model, ["RF"])
     inc_min_split = InCondition(min_split, model, ["RF"])
     inc_min_leavs = InCondition(min_leaves, model, ["RF"])
     
     cs.add_conditions([inc_num_trees, inc_bootstrap, inc_ratio_features, inc_min_split, inc_min_leavs])
     
     acq  = CategoricalHyperparameter("acq_func", choices=("EI", "LCB", "PI", "LogEI"))
     par_ei = UniformFloatHyperparameter("par_ei", lower=-10, upper=10)
     par_pi = UniformFloatHyperparameter("par_pi", lower=-10, upper=10)
     par_logei = UniformFloatHyperparameter("par_logei", lower=0.001, upper=100, log=True)
     par_lcb = UniformFloatHyperparameter("par_lcb", lower=0.0001, upper=0.9999)
     
     cs.add_hyperparameters([acq, par_ei, par_pi, par_logei, par_lcb])
     
     inc_par_ei = InCondition(par_ei, acq, ["EI"])
     inc_par_pi = InCondition(par_pi, acq, ["PI"])
     inc_par_logei = InCondition(par_logei, acq, ["LogEI"])
     inc_par_lcb = InCondition(par_lcb, acq, ["LCB"])
     
     cs.add_conditions([inc_par_ei, inc_par_pi, inc_par_logei, inc_par_lcb])
     
     return cs
Esempio n. 3
0
 def setUp(self):
     logging.basicConfig()
     self.logger = logging.getLogger(self.__module__ + "." + self.__class__.__name__)
     self.logger.setLevel(logging.DEBUG)
     self.value = 0
     self.cs = ConfigurationSpace()
     self.cs.add_hyperparameters([
         UniformFloatHyperparameter('param_a', -0.2, 1.77, 1.1),
         UniformIntegerHyperparameter('param_b', -3, 10, 1),
         Constant('param_c', 'value'),
         CategoricalHyperparameter('ambigous_categorical', choices=['True', True, 5]),  # True is ambigous here
     ])
     self.test_config = Configuration(self.cs, {'param_a': 0.5,
                                                'param_b': 1,
                                                'param_c': 'value',
                                                'ambigous_categorical': 5})
Esempio n. 4
0
 def _convert_PHOTON_to_smac_space(self, hyperparam: object, name: str):
     if not hyperparam:
         return None
     self.hyperparameter_list.append(name)
     if isinstance(hyperparam, PhotonCategorical):
         return CategoricalHyperparameter(choices=hyperparam.values, name=name)
     elif isinstance(hyperparam, list):
         return CategoricalHyperparameter(choices=hyperparam, name=name)
     elif isinstance(hyperparam, FloatRange):
         return UniformFloatHyperparameter(
             lower=hyperparam.start, upper=hyperparam.stop, name=name
         )
     elif isinstance(hyperparam, IntegerRange):
         return UniformIntegerHyperparameter(
             lower=hyperparam.start, upper=hyperparam.stop, name=name
         )
     elif isinstance(hyperparam, BooleanSwitch):
         return CategoricalHyperparameter(choices=["true", "false"], name=name)
Esempio n. 5
0
 def _convert_photon_to_smac_space(hyperparam: object, name: str):
     """
     Helper function: Convert PHOTON hyperparams to smac params.
     """
     if not hyperparam:
         return None
     if isinstance(hyperparam, PhotonCategorical):
         return CategoricalHyperparameter(name, hyperparam.values)
     elif isinstance(hyperparam, list):
         return CategoricalHyperparameter(name, hyperparam)
     elif isinstance(hyperparam, FloatRange):
         if hyperparam.range_type == 'linspace':
             return UniformFloatHyperparameter(name, hyperparam.start,
                                               hyperparam.stop)
         elif hyperparam.range_type == 'logspace':
             raise NotImplementedError(
                 "Logspace in your float hyperparameter is not implemented in SMAC."
             )
         else:
             return UniformFloatHyperparameter(name, hyperparam.start,
                                               hyperparam.stop)
     elif isinstance(hyperparam, IntegerRange):
         return UniformIntegerHyperparameter(name, hyperparam.start,
                                             hyperparam.stop)