def set_samplers(self, gp_model):
        """
        Defines the samplers of the parameters of the model.
        We assume that we only have one set of length scale parameters.
        """
        gp_model.slice_samplers = []
        gp_model.samples_parameters = []
        gp_model.start_point_sampler = []

        ignore_index = None

        if not self.parametric_mean:
            slice_parameters = {
                'max_steps_out': gp_model.max_steps_out,
                'component_wise': True,
            }
        else:
            slice_parameters = {
                'max_steps_out': gp_model.max_steps_out,
                'component_wise': False,
            }

        dimension_sampler = gp_model.dimension_parameters

        if self.parametric_mean:
            dimension_sampler += self.parametrics.n_weights + self.parametrics.n_parameters
        gp_model.slice_samplers.append(SliceSampling(
            self.log_prob, range(dimension_sampler), ignore_index=ignore_index,
            **slice_parameters))

        if gp_model.start_point_sampler is not None and len(gp_model.start_point_sampler) > 0:
            if len(gp_model.samples_parameters) == 0:
                gp_model.samples_parameters.append(np.array(gp_model.start_point_sampler))
        else:
            gp_model.samples_parameters = []
            z = gp_model.get_value_parameters_model
            z = z[2:]

            if self.parametric_mean:
                if gp_model.mean_params is None or len(gp_model.mean_params) == 0:
                    gp_model.mean_params = self.fit_parametric_functions(gp_model.data['evaluations'])
                mean_params = gp_model.mean_params

                gp_model.samples_parameters.append(np.concatenate((z, mean_params)))
            else:
                gp_model.samples_parameters.append(z)

            if gp_model.n_burning > 0:
                parameters = self.sample_parameters(
                    gp_model, float(gp_model.n_burning) / (gp_model.thinning + 1))
                gp_model.samples_parameters = []
                gp_model.samples_parameters.append(parameters[-1])
                gp_model.start_point_sampler = parameters[-1]
            else:
                gp_model.start_point_sampler = gp_model.samples_parameters[-1]
Esempio n. 2
0
    def set_samplers(self):
        gp_model = self.gp_model
        gp_model.slice_samplers = []
        gp_model.samples_parameters = []
        gp_model.start_point_sampler = []

        ignore_index = None

        slice_parameters = {
            'max_steps_out': gp_model.max_steps_out,
            'component_wise': True,
        }

        dimension_sampler = gp_model.dimension_parameters


        gp_model.slice_samplers.append(SliceSampling(
            self.log_prob, range(dimension_sampler), ignore_index=ignore_index,
            **slice_parameters))

        if gp_model.start_point_sampler is not None and len(gp_model.start_point_sampler) > 0:
            if len(gp_model.samples_parameters) == 0:
                gp_model.samples_parameters.append(np.array(gp_model.start_point_sampler))
        else:
            gp_model.samples_parameters = []
            self.samples_parameters = []
            z = gp_model.get_value_parameters_model
            z = z[2:]

            gp_model.samples_parameters.append(z)
            self.samples_parameters.append(z)

            if gp_model.n_burning > 0 and self.burning:
                parameters = self.sample_parameters(
                    gp_model, float(gp_model.n_burning) / (gp_model.thinning + 1))
                self.samples_parameters = []
                self.samples_parameters.append(parameters[-1])
                self.start_point_sampler = parameters[-1]

                gp_model.samples_parameters = []
                gp_model.samples_parameters.append(parameters[-1])
                gp_model.start_point_sampler = parameters[-1]
            else:
                gp_model.start_point_sampler = gp_model.samples_parameters[-1]
                self.start_point_sampler = gp_model.samples_parameters[-1]
    def set_samplers(self):

        self.slice_samplers = []
        self.samples_parameters = []
        self.start_point_sampler = []

        slice_parameters = {
            'max_steps_out': 1000,
            'component_wise': False,
        }

        n_params = self.parametrics.n_parameters + self.parametrics.n_weights + 1
        sampler = SliceSampling(self.log_prob, range(0, len(n_params)),
                                **slice_parameters)
        self.slice_samplers.append(sampler)

        if self.start_point_sampler is not None and len(
                self.start_point_sampler) > 0:
            if len(self.samples_parameters) == 0:
                self.samples_parameters.append(
                    np.array(self.start_point_sampler))
        else:
            self.samples_parameters = []
            start_point = self.fit_parametric_functions(
                self.training_data['evaluations'])
            self.samples_parameters.append(start_point)

            if self.n_burning > 0:
                parameters = self.sample_parameters(
                    self.slice_samplers[0],
                    float(self.n_burning) / (self.thinning + 1))
                self.samples_parameters = []
                self.samples_parameters.append(parameters[-1])
                self.start_point_sampler = parameters[-1]
            else:
                self.start_point_sampler = self.samples_parameters[-1]
Esempio n. 4
0
    def set_samplers(self):
        slice_parameters = {
            'max_steps_out': 1000,
            'component_wise': False,
        }
        n_params = self.parametrics.n_weights + self.parametrics.n_parameters + 1

        sampler = SliceSampling(self.log_prob_slice, range(0, n_params),
                                **slice_parameters)

        self.sampler = sampler

        start = self.parametrics.get_starting_values_mle(self.training_data)

        samples_parameters = []
        samples_parameters.append(start)
        if self.n_burning > 0:
            parameters = self.sample_parameters(
                float(self.n_burning) / (self.n_thinning + 1), start, sampler,
                self.training_data)
            samples_parameters = []
            samples_parameters.append(parameters[-1])

        self.samples_parameters = samples_parameters