geometric_kernels.sampling

Helper functions for efficiently sampling functions from Gaussian processes with Matérn geometric kernels.

Submodules

Package Contents

geometric_kernels.sampling.sample_at(feature_map, s, X, params, key=None, normalize=None)[source]

Given a feature_map \(\phi_{\nu, \kappa}: X \to \mathbb{R}^n\), where \(\nu, \kappa\) are determined by params[“nu”] and params[“lengthscale”], respectively, compute s samples of the Gaussian process with kernel

\[k_{\nu, \kappa}(x, y) = \langle \phi_{\nu, \kappa}(x), \phi_{\nu, \kappa}(y) \rangle_{\mathbb{R}^n}\]

at input locations X and using the random state key.

Generating a sample from \(GP(0, k_{\nu, \kappa})\) is as simple as computing

\[\sum_{j=1}^n w_j \cdot (\phi_{\nu, \kappa}(x))_j \qquad w_j \stackrel{IID}{\sim} N(0, 1).\]

Note

Fixing \(w_j\), and treating \(x \to (\phi_{\nu, \kappa}(x))_j\) as basis functions, while letting \(x\) vary, you get an actual function as a sample, meaning something that can be evaluated at any \(x \in X\). The way to fix \(w_j\) in code is to apply make_deterministic() utility function.

Parameters:
  • feature_map (geometric_kernels.feature_maps.FeatureMap) – The feature map \(\phi_{\nu, \kappa}\) that defines the Gaussian process \(GP(0, k_{\nu, \kappa})\) to sample from.

  • s (int) – The number of samples to generate.

  • X (lab.Numeric) – An [N, <axis>]-shaped array containing N elements of the space feature_map is defined on. <axis> is the shape of these elements. These are the points to evaluate the samples at.

  • params (beartype.typing.Dict[str, lab.Numeric]) – Parameters of the kernel (length scale and smoothness).

  • key (lab.RandomState) – random state, either np.random.RandomState, tf.random.Generator, torch.Generator or jax.tensor (which represents a random state).

  • normalize (bool) –

    Passed down to feature_map directly. Controls whether to force the average variance of the Gaussian process to be around 1 or not. If None, follows the standard behavior, typically same as normalize=True.

    Defaults to None.

Returns:

[N, s]-shaped array containing s samples of the \(GP(0, k_{\nu, \kappa})\) evaluated at X.

Return type:

beartype.typing.Tuple[lab.RandomState, lab.Numeric]

geometric_kernels.sampling.sampler(feature_map, s=1, **kwargs)[source]

A helper wrapper around sample_at that fixes feature_map, s and the keyword arguments in **kwargs but leaves X, params and the other keyword arguments vary.

Parameters:
  • feature_map (geometric_kernels.feature_maps.FeatureMap) – The feature map to fix.

  • s (beartype.typing.Optional[int]) –

    The number of samples parameter to fix.

    Defaults to 1.

  • **kwargs – Keyword arguments to fix.

Returns:

The version of sample_at() with parameters feature_map and s fixed, together with the keyword arguments in **kwargs.

Return type:

beartype.typing.Callable[[beartype.typing.Any], beartype.typing.Any]