GPyTorch Documentation

repository·main·Indexed 26 days ago

https://github.com/cornellius-gp/gpytorch

A Gaussian process library implemented in PyTorch for creating scalable, flexible, and modular GP models. It features numerical linear algebra techniques like preconditioned conjugate gradients, a wide variety of kernels (Standard, Composition, Specialty, and Scalable), mean functions, and likelihoods for scalar and vector-valued functions. The library includes support for exact and approximate inference via marginal log likelihoods (MLLs), KeOps integration for scalable exact GPs, and custom MultivariateNormal distributions.

Tokens
46.7K
Snippets
100
Records
179
Agent score
82%

What's inside GPyTorch

  1. Available kernels in gpytorch.kernels

    main

    GPyTorch provides a wide variety of kernels categorized into Standard, Composition/Decoration, Specialty, and Scalable GP Regression kernels.

    Standard Kernels

    • ConstantKernel
    • CosineKernel
    • CylindricalKernel
    • GibbsKernel
    • LinearKernel
    • MaternKernel
    • PeriodicKernel
    • PiecewisePolynomialKernel
    • PolynomialKernel
    • PolynomialKernelGrad
    • RBFKernel
    • RQKernel
    • SpectralDeltaKernel
    • SpectralMixtureKernel

    Composition/Decoration Kernels

    Used to combine or modify other kernels.

    • AdditiveKernel
    • MultiDeviceKernel
    • AdditiveStructureKernel
    • ProductKernel
    • ProductStructureKernel
    • ScaleKernel

    Specialty Kernels

    • ArcKernel
    • HammingIMQKernel
    • IndexKernel
    • LCMKernel
    • MultitaskKernel
    • RBFKernelGrad
    • RBFKernelGradGrad
    • Matern52KernelGrad
    • SphericalLinearKernel

    Kernels for Scalable GP Regression Methods

    • GridKernel
    • GridInterpolationKernel
    • InducingPointKernel
    • RFFKernel
  2. Use gpytorch.metrics for model evaluation

    main

    The gpytorch.metrics module provides functions to evaluate the performance of Gaussian Process models. Available metrics include:

    • mean_absolute_error: Calculates the Mean Absolute Error (MAE).
    • mean_squared_error: Calculates the Mean Squared Error (MSE).
    • mean_standardized_log_loss: Calculates the Mean Standardized Log Loss.
    • negative_log_predictive_density: Calculates the Negative Log Predictive Density (NLPD).
    • quantile_coverage_error: Calculates the quantile coverage error.

    For detailed usage instructions, refer to the metrics tutorial in the examples directory.

  3. Compute Marginal Log Likelihoods with gpytorch.mlls

    main
    The gpytorch.mlls module provides modules to compute, approximate, or bound the marginal log likelihood (MLL) of a Gaussian Process (GP) model given data $\mathbf X, \mathbf y$. These modules are typically used as loss functions for optimization, but note that the output must be negated for standard minimization-based optimization routines.
  4. Use Likelihoods in GPyTorch

    main

    Likelihoods in GPyTorch define the relationship between the Gaussian Process (GP) latent function and the observed data. They are used to model the noise and the distribution of the observations.

    There are two main categories of likelihoods:

    1. One-Dimensional Likelihoods: Used for GPs that are distributions of scalar functions ($f(\mathbf x) \in \mathbb{R}$). To improve performance, these should extend gpytorch.likelihoods._OneDimensionalLikelihood, which uses 1D Gauss-Hermite quadrature for variance reduction instead of Monte Carlo integration.
    2. Multi-Dimensional Likelihoods: Used for GPs that are distributions of vector-valued functions ($f(\mathbf x) \in \mathbb{R}^t$).
  5. Use Scalable Kernel Approximations

    main

    When exact computations are too costly, GPyTorch offers several approximate kernel methods to reduce asymptotic complexity:

    • Sparse Gaussian Process Regression (SGPR): Approximates kernels using a set of inducing points. This is a general-purpose approximation.
    • Structured Kernel Interpolation (SKI/KISS-GP): Interpolates inducing points on a regularly spaced grid. Best suited for low-dimensional data and stationary kernels.
    • Structured Kernel Interpolation for Products (SKIP): An extension of SKI designed for higher-dimensional data.

    Implementation examples are available in:

    • SGPR_Regression_CUDA.ipynb
    • KISSGP_Regression.ipynb
    • Scalable_Kernel_Interpolation_for_Products_CUDA.ipynb
  6. Scale Exact GP Inference with BBMM and LOVE

    main

    For large regression datasets (over 1,000,000 data points), GPyTorch supports exact GP inference by combining two key techniques:

    1. BlackBox Matrix-Matrix Inference (BBMM): Computes the GP marginal log likelihood using only matrix multiplication. This stochastic approach allows scaling exact GPs to millions of points.
    2. LanczOs Variance Estimates (LOVE): A technique used to rapidly speed up predictive variances and posterior sampling.

    To implement these, refer to the Simple_GP_Regression_With_LOVE_Fast_Variances_and_Sampling.ipynb notebook.

  7. Use KeOps-integrated kernels for scalable exact GPs

    main

    GPyTorch provides specialized kernel implementations in gpytorch.kernels.keops that are compatible with the KeOps integration. These kernels allow for scalable exact Gaussian Processes by leveraging KeOps' symbolic autoregression and efficient kernel computations.

    Supported kernels include:

    • RBFKernel
    • MaternKernel
    • PeriodicKernel

    Note that only specific standard kernels have KeOps implementations. If a required kernel is missing, you may consider contributing it via a pull request.

  8. Implement Approximate GPs using Variational components

    main

    To implement Gaussian Process approximations in GPyTorch, you must use three composable objects in conjunction with a gpytorch.models.ApproximateGP model:

    1. VariationalDistribution: Defines the form of the approximate inducing value posterior $q(\mathbf{u})$.
    2. VariationalStrategy: Defines how to compute the variational distribution over function values $q(\mathbf{f}(\mathbf{X}))$ from the inducing point distribution $q(\mathbf{u})$.
    3. gpytorch.mlls._ApproximateMarginalLogLikelihood: Defines the objective function (e.g., variational ELBO) used to learn the approximate posterior.
  9. Use standard mean functions in gpytorch.means

    main

    GPyTorch provides several standard mean functions for Gaussian Process modeling. These are located in the gpytorch.means module.

    ZeroMean

    ZeroMean is a mean function that assumes the mean of the process is zero.

    ConstantMean

    ConstantMean represents a mean function that is constant across the input space.

    LinearMean

    LinearMean represents a mean function that is a linear function of the input.