gp_api.kernels package

Submodules

gp_api.kernels.compact_kernel_evaluate module

Compact kernel evaluation function

gp_api.kernels.compact_kernel_evaluate.compact_kernel_evaluate(x, x_prime, scale, q=1, train_err=None, xpy=None)

Evaluates the compact kernel \(K(x, x')\)

gp_api.kernels.kernels module

Classes representing kernels

class gp_api.kernels.kernels.AddKernel(parent1, parent2)

Bases: gp_api.kernels.kernels.Kernel

Result of adding two kernels

Note that this kernel cannot be fit directly, and must be constructed from two existing kernels.

equiv(other)
classmethod from_attrs(attrs)
to_dict()

Serialize as dict

class gp_api.kernels.kernels.CompactKernel(scale, order=1, sparse=True, use_cython=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>)

Bases: gp_api.kernels.kernels.Kernel

This is the kernel, which operates with the sparse basis functions outlined on page 88 of R&W’s Gaussian Processes and Machine Learning.

equiv(other)

Compares to other, returning True if they are equivalent. Unlike ==, this does not consider differences in backend choices.

classmethod fit(x_train, method='scott', **method_kwargs)

Construct a kernel by optimizing its parameters from training data. Each Kernel subclass may implement this differently.

classmethod fit_scott(x_train, order=1, sparse=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>, use_cython=True, **kwargs)

Compute the scale factor as if for a KDE using Scott’s rule

Normally this would be multiplied by the covariance of the data, but we’ll use the limits instead

This would generate a bandwidth slightly wider than a kde, but wider is less sparse and therefore safer

classmethod fit_simple(x_train, coeffs, order=1, sparse=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>, use_cython=True)

Give coefficients to scale sparsity by

classmethod from_attrs(attrs)
to_dict()

Serialize as dict

class gp_api.kernels.kernels.Kernel(ndim, sparse=False, use_cython=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>)

Bases: object

equiv(other)
classmethod fit(x_train, method=None, **method_kwargs)

Construct a kernel by optimizing its parameters from training data. Each Kernel subclass may implement this differently.

classmethod from_attrs()
static from_dict(dct)

Deserialize from a dict

static from_json(json_str)

Deserialize from a JSON string

to_dict()

Serialize as dict

to_json()
class gp_api.kernels.kernels.MaternKernel(ndim, nu, length_scale=1.0, use_cython=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>)

Bases: gp_api.kernels.kernels.Kernel

This is the kernel, which operates with the sparse basis functions outlined on page 88 of R&W’s Gaussian Processes and Machine Learning.

Parameters
  • ndim (int) – Kernel’s dimensionality

  • nu (float) – \(\nu\) parameter to Matern kernel

  • length_scale (float, optional) – length scale parameter to Matern kernel

  • use_cython (bool, optional) – Whether to use Cython compiled kernel functions.

  • xpy (ModuleType, optional) – A module, either numpy or cupy. cupy is not yet supported.

equiv(other)

Compares to other, returning True if they are equivalent. Unlike ==, this does not consider differences in backend choices.

classmethod fit(x_train, method='sample_covariance', **method_kwargs)

Construct a kernel by optimizing its parameters from training data. Each Kernel subclass may implement this differently.

classmethod fit_sample_covariance(x_train, nu=0.5, full=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>, use_cython=True)
classmethod from_attrs(attrs)
to_dict()

Serialize as dict

class gp_api.kernels.kernels.WhiteNoiseKernel(ndim, scale, sparse=True, use_cython=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>)

Bases: gp_api.kernels.kernels.Kernel

A simple white noise kernel

Parameters
  • ndim (int) – Kernel’s dimensionality

  • scale (float) – Amplitude of the white noise. This value is added to the kernel diagonal.

  • sparse (bool, optional) – Whether to use sparse matrix operations to perform regression.

  • use_cython (bool, optional) – Whether to use Cython compiled kernel functions.

  • xpy (ModuleType, optional) – A module, either numpy or cupy. cupy is not yet supported.

equiv(other)

Compares to other, returning True if they are equivalent. Unlike ==, this does not consider differences in backend choices.

classmethod fit(x_train, method='simple', **method_kwargs)

Construct a kernel by optimizing its parameters from training data. Each Kernel subclass may implement this differently.

classmethod fit_simple(x_train, scale=0.1, sparse=True, xpy=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/gaussian-process-api/envs/dev/lib/python3.9/site-packages/numpy/__init__.py'>, use_cython=True)
classmethod from_attrs(attrs)

Load kernel from attributes

to_dict()

Serialize as dict

gp_api.kernels.kernels.from_json(json_str)

Deserialize from a JSON string

gp_api.kernels.matern_kernel_evaluate module

Matern kernel evaluation function

Code adapted from `sklearn.gaussian_process.kernels.Matern <https://scikit-learn.org/stable/modules/generated/sklearn.gaussian_process.kernels.Matern.html>`_

gp_api.kernels.matern_kernel_evaluate.matern_kernel_evaluate(x, x_prime, length_scale_dim, length_scale_inv, nu, train_err=None, xpy=None)

Evaluates the Matern kernel \(K(x, x')\)

Module contents