Esempio n. 1
0
    def get_suggestions(self, params: Dict = None) -> List[Dict]:
        if not self.config.num_runs:
            raise ValueError("This search strategy requires `num_runs`.")
        suggestions = []
        params = params or {}
        rand_generator = get_random_generator(seed=self.config.seed)
        # Validate number of suggestions and total space
        all_discrete = True
        for v in self.config.params.values():
            if v.is_continuous:
                all_discrete = False
                break
        num_runs = self.config.num_runs
        if all_discrete:
            space = reduce(
                mul, [get_length(v) for v in self.config.params.values()])
            num_runs = self.config.num_runs if self.config.num_runs <= space else space

        while num_runs > 0:
            suggestion_params = copy.deepcopy(params)
            suggestion_params.update({
                k: sample(v, rand_generator=rand_generator)
                for k, v in self.config.params.items()
            })
            suggestion = SuggestionSpec(params=suggestion_params)
            if suggestion not in suggestions:
                suggestions.append(suggestion)
                num_runs -= 1
        return [suggestion.params for suggestion in suggestions]
Esempio n. 2
0
    def __init__(self, config, seed=None):
        if not isinstance(config, UtilityFunctionConfig):
            raise ValueError("Received a non valid configuration.")

        self.config = config
        self.eps = config.eps
        self.kappa = config.kappa
        self.acquisition_function = config.acquisition_function
        self.random_generator = get_random_generator(seed=seed)
        self.gaussian_process = self.get_gaussian_process(
            config=config.gaussian_process,
            random_generator=self.random_generator)
Esempio n. 3
0
    def get_suggestions(self,
                        configs: Dict = None,
                        metrics: Dict = None) -> List[Dict]:
        if not self.config.num_runs:
            raise ValueError("This search strategy requires `num_runs`.")
        suggestions = []
        rand_generator = get_random_generator(seed=self.config.seed)
        hyperopt_domain = hyperopt.Domain(None,
                                          self._search_space,
                                          pass_expr_memo_ctrl=None)

        hyperopt_trials = self._get_previous_observations(
            hyperopt_domain=hyperopt_domain, configs=configs, metrics=metrics)

        minimize = hyperopt.FMinIter(
            self.config.algorithm,
            hyperopt_domain,
            hyperopt_trials,
            max_evals=-1,
            rstate=rand_generator,
            verbose=0,
        )

        minimize.catch_eval_exceptions = False
        new_ids = minimize.trials.new_trial_ids(self.config.num_runs)
        minimize.trials.refresh()
        random_state = minimize.rstate.randint(2**31 - 1)
        new_trials = self.algorithm(new_ids, minimize.domain, hyperopt_trials,
                                    random_state)
        minimize.trials.refresh()

        for tid in range(self.config.num_runs):
            vals = new_trials[tid]["misc"]["vals"]
            suggestion = {}
            for param in vals:
                observation_value = vals[param][0]
                if param in self._param_to_value:
                    value = self._param_to_value[param][observation_value]
                    suggestion[param] = value
                else:
                    suggestion[param] = observation_value

            suggestions.append(suggestion)

        return suggestions