示例#1
0
    def _create_posterior(self, flat_hyperparameter_space: HyperparameterSpace,
                          trials: Trials) -> HyperparameterSpace:
        # Create a list of all hyperparams and their trials.

        # Loop through all hyperparams
        posterior_distributions: HyperparameterSpace = HyperparameterSpace()
        for (hyperparam_key,
             hyperparam_distribution) in flat_hyperparameter_space.items():

            # Get trial hyperparams
            trial_hyperparams: List[HyperparameterSamples] = [
                trial.hyperparams.to_flat_as_dict_primitive()[hyperparam_key]
                for trial in trials
            ]

            if hyperparam_distribution.is_discrete():
                posterior_distribution = self._reweights_categorical(
                    discrete_distribution=hyperparam_distribution,
                    trial_hyperparameters=trial_hyperparams)
            else:
                posterior_distribution = self._create_gaussian_mixture(
                    continuous_distribution=hyperparam_distribution,
                    trial_hyperparameters=trial_hyperparams)

            posterior_distributions.update(
                {hyperparam_key: posterior_distribution})

        return posterior_distributions
示例#2
0
def plot_distribution_space(hyperparameter_space: HyperparameterSpace,
                            num_bins=50):
    for title, distribution in hyperparameter_space.items():
        print(title + ":")
        plot_histogram(title, distribution, num_bins=num_bins)
        plot_pdf_cdf(title, distribution)