Пример #1
0
    def GetSuggestions(self, request, context):
        """
        Main function to provide suggestion.
        """
        algorithm_name, config = OptimizerConfiguration.convertAlgorithmSpec(
            request.experiment.spec.algorithm)
        if algorithm_name != "bayesianoptimization":
            raise Exception(
                "Failed to create the algorithm: {}".format(algorithm_name))

        if self.is_first_run:
            search_space = HyperParameterSearchSpace.convert(
                request.experiment)
            self.base_service = BaseSkoptService(
                base_estimator=config.base_estimator,
                n_initial_points=config.n_initial_points,
                acq_func=config.acq_func,
                acq_optimizer=config.acq_optimizer,
                random_state=config.random_state,
                search_space=search_space)
            self.is_first_run = False

        trials = Trial.convert(request.trials)
        new_trials = self.base_service.getSuggestions(trials,
                                                      request.request_number)
        return api_pb2.GetSuggestionsReply(
            parameter_assignments=Assignment.generate(new_trials))
Пример #2
0
 def ValidateAlgorithmSettings(self, request, context):
     algorithm_name = request.experiment.spec.algorithm.algorithm_name
     if algorithm_name == "grid":
         search_space = HyperParameterSearchSpace.convert(
             request.experiment)
         for param in search_space.params:
             if param.type == DOUBLE:
                 if param.step == "" or param.step is None:
                     return self._set_validate_context_error(
                         context, "param {} step is nil".format(param.name))
     return api_pb2.ValidateAlgorithmSettingsReply()
Пример #3
0
    def GetSuggestions(self, request, context):
        """
        Main function to provide suggestion.
        """
        with self.lock:
            if self.study is None:
                self.search_space = HyperParameterSearchSpace.convert(request.experiment)
                self.study = self._create_study(request.experiment.spec.algorithm, self.search_space)

            trials = Trial.convert(request.trials)

            if len(trials) != 0:
                self._tell(trials)
            list_of_assignments = self._ask(request.request_number)

            return api_pb2.GetSuggestionsReply(
                parameter_assignments=Assignment.generate(list_of_assignments)
            )
Пример #4
0
    def GetSuggestions(self, request, context):
        """
        Main function to provide suggestion.
        """

        if self.is_first_run:
            search_space = HyperParameterSearchSpace.convert(
                request.experiment)
            self.base_service = BaseChocolateService(
                algorithm_name=request.experiment.spec.algorithm.
                algorithm_name,
                search_space=search_space)
            self.is_first_run = False

        trials = Trial.convert(request.trials)
        new_assignments = self.base_service.getSuggestions(
            trials, request.request_number)
        return api_pb2.GetSuggestionsReply(
            parameter_assignments=Assignment.generate(new_assignments))
Пример #5
0
    def GetSuggestions(self, request, context):
        """
        Main function to provide suggestion.
        """
        name, config = OptimizerConfiguration.convert_algorithm_spec(
            request.experiment.spec.algorithm)

        if self.is_first_run:
            search_space = HyperParameterSearchSpace.convert(
                request.experiment)
            self.base_service = BaseHyperoptService(algorithm_name=name,
                                                    algorithm_conf=config,
                                                    search_space=search_space)
            self.is_first_run = False

        trials = Trial.convert(request.trials)
        new_assignments = self.base_service.getSuggestions(
            trials, request.current_request_number)
        return api_pb2.GetSuggestionsReply(
            parameter_assignments=Assignment.generate(new_assignments))
Пример #6
0
    def ValidateAlgorithmSettings(self, request, context):
        algorithm_name = request.experiment.spec.algorithm.algorithm_name
        if algorithm_name == "grid":
            search_space = HyperParameterSearchSpace.convert(
                request.experiment)
            available_space = {}
            for param in search_space.params:
                if param.type == INTEGER:
                    available_space[param.name] = range(
                        int(param.min),
                        int(param.max) + 1, int(param.step))

                elif param.type == DOUBLE:
                    if param.step == "" or param.step is None:
                        return self._set_validate_context_error(
                            context,
                            "Param: {} step is nil".format(param.name))
                    double_list = np.arange(
                        float(param.min),
                        float(param.max) + float(param.step),
                        float(param.step))
                    if double_list[-1] > float(param.max):
                        double_list = double_list[:-1]
                    available_space[param.name] = double_list

                elif param.type == CATEGORICAL or param.type == DISCRETE:
                    available_space[param.name] = param.list

            num_combinations = len(
                list(itertools.product(*available_space.values())))
            max_trial_count = request.experiment.spec.max_trial_count

            if max_trial_count > num_combinations:
                return self._set_validate_context_error(
                    context,
                    "Max Trial Count: {} > all possible search space combinations: {}"
                    .format(max_trial_count, num_combinations))

        return api_pb2.ValidateAlgorithmSettingsReply()