Beispiel #1
0
    def setup_bo_basics(self):
        """
        Prepare the basic BO components.
        Returns
        -------
        An optimizer object.
        """
        if self.num_objs == 1 or self.acq_type == 'parego':
            self.surrogate_model = build_surrogate(
                func_str=self.surrogate_type,
                config_space=self.config_space,
                rng=self.rng,
                history_hpo_data=self.history_bo_data)
        else:  # multi-objectives
            self.surrogate_model = [
                build_surrogate(func_str=self.surrogate_type,
                                config_space=self.config_space,
                                rng=self.rng,
                                history_hpo_data=self.history_bo_data)
                for _ in range(self.num_objs)
            ]

        if self.num_constraints > 0:
            self.constraint_models = [
                build_surrogate(func_str=self.constraint_surrogate_type,
                                config_space=self.config_space,
                                rng=self.rng)
                for _ in range(self.num_constraints)
            ]

        if self.acq_type in ['mesmo', 'mesmoc', 'mesmoc2', 'usemo']:
            types, bounds = get_types(self.config_space)
            self.acquisition_function = build_acq_func(
                func_str=self.acq_type,
                model=self.surrogate_model,
                constraint_models=self.constraint_models,
                types=types,
                bounds=bounds)
        else:
            self.acquisition_function = build_acq_func(
                func_str=self.acq_type,
                model=self.surrogate_model,
                constraint_models=self.constraint_models,
                ref_point=self.ref_point)
        if self.acq_type == 'usemo':
            self.acq_optimizer_type = 'usemo_optimizer'
        elif self.acq_type.startswith('mesmo'):
            self.acq_optimizer_type = 'mesmo_optimizer'
        self.optimizer = build_optimizer(func_str=self.acq_optimizer_type,
                                         acq_func=self.acquisition_function,
                                         config_space=self.config_space,
                                         rng=self.rng)
Beispiel #2
0
    def setup_bo_basics(self):
        if self.num_objs == 1:
            self.surrogate_model = build_surrogate(func_str=self.surrogate_type,
                                                   config_space=self.config_space,
                                                   rng=self.rng,
                                                   history_hpo_data=self.history_bo_data)
        else:  # multi-objectives
            self.surrogate_model = [build_surrogate(func_str=self.surrogate_type,
                                                    config_space=self.config_space,
                                                    rng=self.rng,
                                                    history_hpo_data=self.history_bo_data)
                                    for _ in range(self.num_objs)]

        if self.num_constraints > 0:
            self.constraint_models = [build_surrogate(func_str=self.constraint_surrogate_type,
                                                      config_space=self.config_space,
                                                      rng=self.rng) for _ in range(self.num_constraints)]

        self.acquisition_function = build_acq_func(func_str=self.acq_type, model=self.surrogate_model,
                                                   constraint_models=self.constraint_models,
                                                   mc_times=self.mc_times, ref_point=self.ref_point)

        self.optimizer = build_optimizer(func_str=self.acq_optimizer_type,
                                         acq_func=self.acquisition_function,
                                         config_space=self.config_space,
                                         rng=self.rng)

        if self.use_trust_region:
            types, bounds = get_types(self.config_space)
            cont_dim = np.sum(types == 0)
            self.turbo_state = TurboState(cont_dim)
Beispiel #3
0
    def setup_bo_basics(self, acq_type='ei', acq_optimizer_type='local_random'):
        self.surrogate_model = build_surrogate(func_str=self.surrogate_type,
                                               config_space=self.config_space,
                                               rng=self.rng,
                                               history_hpo_data=self.history_bo_data)

        self.acquisition_function = build_acq_func(func_str=acq_type, model=self.surrogate_model)

        self.optimizer = build_optimizer(func_str=acq_optimizer_type,
                                         acq_func=self.acquisition_function,
                                         config_space=self.config_space,
                                         rng=self.rng)
Beispiel #4
0
    def __init__(self,
                 model: List[AbstractModel],
                 types: List[int],
                 bounds: List[Tuple[float, float]],
                 acq_type='ei',
                 **kwargs):
        """Constructor

        Parameters
        ----------
        model : List[AbstractEPM]
            A list of surrogate that implements at least
                 - predict_marginalized_over_instances(X)
        types : List[int]
            Specifies the number of categorical values of an input dimension where
            the i-th entry corresponds to the i-th input dimension. Let's say we
            have 2 dimension where the first dimension consists of 3 different
            categorical choices and the second dimension is continuous than we
            have to pass [3, 0]. Note that we count starting from 0.
        bounds : List[Tuple[float, float]]
            Bounds of input dimensions: (lower, upper) for continuous dims; (n_cat, np.nan) for categorical dims
            # todo cat dims
        acq_type:
            todo
        """

        super(USeMO, self).__init__(model)
        self.long_name = 'Uncertainty-Aware Search'
        self.types = np.asarray(types)
        self.bounds = np.asarray(bounds)
        from openbox.core.base import build_acq_func
        self.single_acq = [
            build_acq_func(func_str=acq_type, model=m) for m in model
        ]
        self.uncertainty_acq = [Uncertainty(model=m) for m in model]
        self.X = None
        self.Y = None
        self.X_dim = None
        self.Y_dim = None
        self.eta = None
        self.num_data = None
        self.uncertainties = None
        self.candidates = None
        self.check_types_bounds()
Beispiel #5
0
    def __init__(self,
                 model: List[AbstractModel],
                 config_space,
                 random_state=1,
                 acq_type='ei',
                 **kwargs):
        """Constructor

        Parameters
        ----------
        model : List[AbstractEPM]
            A list of surrogate that implements at least
                 - predict_marginalized_over_instances(X)
        config_space : openbox.space.Space
            Configuration space
        random_state : int
            Random seed for RNG.
        acq_type:
            Type of base acquisition function.
        """

        super(USeMO, self).__init__(model)
        self.long_name = 'Uncertainty-Aware Search'
        self.rng = np.random.RandomState(random_state)
        random.seed(self.rng.randint(MAXINT))
        self.config_space = config_space
        from openbox.core.base import build_acq_func
        self.single_acq = [
            build_acq_func(func_str=acq_type, model=m) for m in model
        ]
        self.uncertainty_acq = [Uncertainty(model=m) for m in model]
        self.X = None
        self.Y = None
        self.X_dim = None
        self.Y_dim = None
        self.eta = None
        self.num_data = None
        self.uncertainties = None
        self.candidates = None