示例#1
0
    def update_search_space(self, search_space):
        """
        Update search space definition in tuner by search_space in parameters.

        Will called when first setup experiemnt or update search space in WebUI.

        Parameters
        ----------
        search_space : dict
        """
        self.json = search_space
        randint_to_quniform(self.json)

        search_space_instance = json2space(self.json)
        rstate = np.random.RandomState()
        trials = hp.Trials()
        domain = hp.Domain(None,
                           search_space_instance,
                           pass_expr_memo_ctrl=None)
        algorithm = self._choose_tuner(self.algorithm_name)
        self.rval = hp.FMinIter(algorithm,
                                domain,
                                trials,
                                max_evals=-1,
                                rstate=rstate,
                                verbose=0)
        self.rval.catch_eval_exceptions = False
示例#2
0
    def update_search_space(self, search_space):
        """TODO: this is urgly, we put all the initialization work in this method, because initialization relies
        on search space, also because update_search_space is called at the beginning.
        NOTE: updating search space is not supported.

        Parameters
        ----------
        search_space:
            search space
        """
        randint_to_quniform(search_space)
        if not self.update_ss_done:
            self.categorical_dict = generate_scenario(search_space)
            if self.categorical_dict is None:
                raise RuntimeError(
                    'categorical dict is not correctly returned after parsing search space.'
                )
            self.optimizer = self._main_cli()
            self.smbo_solver = self.optimizer.solver
            self.loguniform_key = {
                key
                for key in search_space.keys()
                if search_space[key]['_type'] == 'loguniform'
            }
            self.update_ss_done = True
        else:
            self.logger.warning('update search space is not supported.')
    def handle_update_search_space(self, data):
        """data: JSON object, which is search space

        Parameters
        ----------
        data: int
            number of trial jobs
        """
        self.searchspace_json = data
        randint_to_quniform(self.searchspace_json)
        self.random_state = np.random.RandomState()
示例#4
0
    def update_search_space(self, search_space):
        """Update search space.
        Search_space contains the information that user pre-defined.

        Parameters
        ----------
        search_space : dict
        """
        self.searchspace_json = search_space
        randint_to_quniform(self.searchspace_json)
        self.space = json2space(self.searchspace_json)

        self.random_state = np.random.RandomState()
        self.population = []
        is_rand = dict()
        for item in self.space:
            is_rand[item] = True
        for _ in range(self.population_size):
            config = json2parameter(self.searchspace_json, is_rand,
                                    self.random_state)
            self.population.append(Individual(config=config))
示例#5
0
    def handle_update_search_space(self, data):
        """change json format to ConfigSpace format dict<dict> -> configspace

        Parameters
        ----------
        data: JSON object
            search space of this experiment
        """
        search_space = data
        randint_to_quniform(search_space)
        cs = CS.ConfigurationSpace()
        for var in search_space:
            _type = str(search_space[var]["_type"])
            if _type == 'choice':
                cs.add_hyperparameter(
                    CSH.CategoricalHyperparameter(
                        var, choices=search_space[var]["_value"]))
            elif _type == 'randint':
                cs.add_hyperparameter(
                    CSH.UniformIntegerHyperparameter(
                        var, lower=0, upper=search_space[var]["_value"][0]))
            elif _type == 'uniform':
                cs.add_hyperparameter(
                    CSH.UniformFloatHyperparameter(
                        var,
                        lower=search_space[var]["_value"][0],
                        upper=search_space[var]["_value"][1]))
            elif _type == 'quniform':
                cs.add_hyperparameter(
                    CSH.UniformFloatHyperparameter(
                        var,
                        lower=search_space[var]["_value"][0],
                        upper=search_space[var]["_value"][1],
                        q=search_space[var]["_value"][2]))
            elif _type == 'loguniform':
                cs.add_hyperparameter(
                    CSH.UniformFloatHyperparameter(
                        var,
                        lower=search_space[var]["_value"][0],
                        upper=search_space[var]["_value"][1],
                        log=True))
            elif _type == 'qloguniform':
                cs.add_hyperparameter(
                    CSH.UniformFloatHyperparameter(
                        var,
                        lower=search_space[var]["_value"][0],
                        upper=search_space[var]["_value"][1],
                        q=search_space[var]["_value"][2],
                        log=True))
            elif _type == 'normal':
                cs.add_hyperparameter(
                    CSH.NormalFloatHyperparameter(
                        var,
                        mu=search_space[var]["_value"][1],
                        sigma=search_space[var]["_value"][2]))
            elif _type == 'qnormal':
                cs.add_hyperparameter(
                    CSH.NormalFloatHyperparameter(
                        var,
                        mu=search_space[var]["_value"][1],
                        sigma=search_space[var]["_value"][2],
                        q=search_space[var]["_value"][3]))
            elif _type == 'lognormal':
                cs.add_hyperparameter(
                    CSH.NormalFloatHyperparameter(
                        var,
                        mu=search_space[var]["_value"][1],
                        sigma=search_space[var]["_value"][2],
                        log=True))
            elif _type == 'qlognormal':
                cs.add_hyperparameter(
                    CSH.NormalFloatHyperparameter(
                        var,
                        mu=search_space[var]["_value"][1],
                        sigma=search_space[var]["_value"][2],
                        q=search_space[var]["_value"][3],
                        log=True))
            else:
                raise ValueError(
                    'unrecognized type in search_space, type is {}'.format(
                        _type))

        self.search_space = cs