Exemple #1
0
    def _build(self):
        self.params        = {}
        self.latent_values = None

        # Build the transformer
        beta_warp                 = BetaWarp(self.num_dims)
        beta_alpha, beta_beta    = beta_warp.hypers
        self.params['beta_alpha'] = beta_alpha
        self.params['beta_beta']  = beta_beta

        transformer = Transformer(self.num_dims)
        transformer.add_layer(beta_warp)

        # Build the component kernels
        input_kernel      = Matern52(self.num_dims)
        ls                = input_kernel.hypers
        self.params['ls'] = ls

        # Now apply the transformation.
        transform_kernel = TransformKernel(input_kernel, transformer)

        # Add some perturbation for stability
        stability_noise = Noise(self.num_dims)

        # Finally make a noisy version if necessary
        # In a classifier GP the notion of "noise" is really just the scale.
        if self.noiseless:
            self._kernel = SumKernel(transform_kernel, stability_noise)
        else:
            scaled_kernel       = Scale(transform_kernel)
            self._kernel        = SumKernel(scaled_kernel, stability_noise)
            amp2                = scaled_kernel.hypers
            self.params['amp2'] = amp2

        # Build the mean function (just a constant mean for now)
        self.mean = Hyperparameter(
            initial_value = 0.0,
            prior         = priors.Gaussian(0.0,1.0),
            name          = 'mean'
        )
        self.params['mean'] = self.mean

        # Buld the latent values. Empty for now until the GP gets data.
        self.latent_values = Hyperparameter(
            initial_value  = np.array([]),
            name           = 'latent values'
        )

        # Build the samplers
        to_sample = [self.mean] if self.noiseless else [self.mean, amp2]
        self._samplers.append(SliceSampler(*to_sample, compwise=False, thinning=self.thinning))
        self._samplers.append(WhitenedPriorSliceSampler(ls, beta_alpha, beta_beta, compwise=True, thinning=self.thinning))
        self.latent_values_sampler = EllipticalSliceSampler(self.latent_values, thinning=self.ess_thinning)
Exemple #2
0
    def _build(self):
        # Build the transformer
        beta_warp   = BetaWarp(self.num_dims)
        transformer = Transformer(self.num_dims)
        transformer.add_layer(beta_warp)

        # Build the component kernels
        input_kernel           = Matern52(self.num_dims)
        stability_noise_kernel = Noise(self.num_dims) # Even if noiseless we use some noise for stability
        scaled_input_kernel    = Scale(input_kernel)
        sum_kernel             = SumKernel(scaled_input_kernel, stability_noise_kernel)
        noise_kernel           = Noise(self.num_dims)

        # The final kernel applies the transformation.
        self._kernel = TransformKernel(sum_kernel, transformer)

        # Finally make a noisy version if necessary
        if not self.noiseless:
            self._kernel_with_noise = SumKernel(self._kernel, noise_kernel)

        # Build the mean function (just a constant mean for now)
        self.mean = Hyperparameter(
            initial_value = 0.0,
            prior         = priors.Gaussian(0.0,1.0),
            name          = 'mean'
        )

        # Get the hyperparameters to sample
        ls                      = input_kernel.hypers
        amp2                    = scaled_input_kernel.hypers
        beta_alpha, beta_beta = beta_warp.hypers

        self.params = {
            'mean'       : self.mean,
            'amp2'       : amp2,
            'ls'         : ls,
            'beta_alpha' : beta_alpha,
            'beta_beta'  : beta_beta
        }

        # Build the samplers
        if self.noiseless:
            self._samplers.append(SliceSampler(self.mean, amp2, compwise=False, thinning=self.thinning))
        else:
            noise = noise_kernel.hypers
            self.params.update({'noise' : noise})
            self._samplers.append(SliceSampler(self.mean, amp2, noise, compwise=False, thinning=self.thinning))

        self._samplers.append(SliceSampler(ls, beta_alpha, beta_beta, compwise=True, thinning=self.thinning))