base#
These kernels are compatible with smolgp.solvers.StateSpaceSolver,
which uses Bayesian filtering and smoothing algorithms to perform scalable GP
inference. (see smolgp.solvers for more technical details).
On GPU, a performance boost may be observed for large datasets by using the
smolgp.solvers.parallel.ParallelStateSpaceSolver class.
Like the quasisep kernels, these methods are experimental, so you may find the documentation patchy in places. You are encouraged to open issues or pull requests as you find gaps.
Classes#
The base class for an instantaneous linear Gaussian state space model. |
|
The sum of two |
|
The product of two |
|
A base class for wrapping kernels with some custom implementations |
|
The product of a scalar and a state space kernel. |
|
A constant kernel |
|
The damped, driven stochastic harmonic oscillator kernel |
|
A state space implementation of |
|
A state space implementation of |
|
A state space implementation of |
|
A state space implementation of |
|
The exponential sine squared or "periodic" kernel |
|
A state space implementation of the generic half-integer Matérn kernel |
Functions#
|
Recursively extract leaf kernels from a sum or product of kernels |
Module Contents#
- smolgp.kernels.base.extract_leaf_kernels(kernel, all=False)[source]#
Recursively extract leaf kernels from a sum or product of kernels
- If all==True, extract from both Sum and Product nodes
(useful for returning all kernel elements).
- Default is False, which only extracts from Sum nodes.
(as used in decomposing multi-component models, only valid for sums)
- class smolgp.kernels.base.StateSpaceModel[source]#
Bases:
tinygp.kernels.base.KernelThe base class for an instantaneous linear Gaussian state space model.
- name#
Unique identifier used in multi-component models to select individual components from a sum or product kernel.
- Type:
str
- dimension#
Dimensionality \(d\) of the state space model.
- Type:
int
A state space model is defined by the following components:
design_matrix()— The feedback matrix \(F\)stationary_covariance()— The stationary covariance \(\mathbf{P}_\infty\)observation_matrix()— The observation matrix \(H\)noise()— The spectral density \(Q_c\) of the driving white noisenoise_effect_matrix()— The noise effect matrix \(L\)transition_matrix()— The transition matrix \(A_k\) (optional; default usesjax.scipy.linalg.expm())process_noise()— The process noise \(Q_k\) (optional; default uses \(\mathbf{P}_\infty - A_k \mathbf{P}_\infty A_k^\top\) or the Van Loan matrix exponential)
As a subclass of
tinygp.kernels.Kernel, this class supports addition and multiplication with other kernels viaSumandProduct, as well as direct kernel evaluation.- name: str#
- coord_to_sortable(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
A helper function used to convert coordinates to sortable 1-D values
By default, this is the identity, but in cases where
Xis structured (e.g. multivariate inputs), this can be used to appropriately unwrap that structure.
- property dimension: int#
The dimension of the state space model, d
- abstractmethod design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the process, \(F\)
- abstractmethod stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the process, \(\mathbf{P}_\infty\)
- observation_model(X: tinygp.helpers.JAXArray, component: str | None = None) tinygp.helpers.JAXArray[source]#
The observation model for the process, \(H\)
- abstractmethod observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation matrix for the process, \(H\)
- abstractmethod noise() tinygp.helpers.JAXArray[source]#
The spectral density of the white noise process, \(Q_c\)
- abstractmethod noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix, \(L\)
- transition_matrix(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The transition matrix \(A_k\) between two states at coordinates X1 and X2.
Default behavior uses jax.scipy.linalg.expm(self.design_matrix() * (X2 - X1)), which is appropriate for stationary kernels defined by a linear Gaussian SSM.
Overload this method if you have a more general model or simply wish to define the transition matrix analytically.
- process_noise(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray, use_van_loan=False) tinygp.helpers.JAXArray[source]#
The process noise matrix \(Q_k\)
Default behavior computes \(Q_k = \mathbf{P}_\infty - A_k \mathbf{P}_\infty A_k^T\) (see Eq. 7 in Solin & Särkka (2014)). Pass
use_van_loan=Trueto instead compute \(Q_k\) via the Van Loan (1978) matrix exponential method using \(F\), \(L\), and \(Q_c\).Overload this method if you have a more general model or wish to define the process noise analytically.
- reset_matrix(instid: int = 0) tinygp.helpers.JAXArray[source]#
The reset matrix for an instantaneous state space model is trivially the identity matrix.
- __add__(other: tinygp.kernels.base.Kernel | tinygp.helpers.JAXArray) tinygp.kernels.base.Kernel[source]#
- __mul__(other: tinygp.kernels.base.Kernel | tinygp.helpers.JAXArray) tinygp.kernels.base.Kernel[source]#
- evaluate(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The kernel evaluated via the state space representation.
- evaluate_diag(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
For state space kernels, the variance is simple to compute
- class smolgp.kernels.base.Sum(kernel1, kernel2)[source]#
Bases:
StateSpaceModelThe sum of two
StateSpaceModelkernels.The joint state dimension is \(d = d_1 + d_2\), and all matrices are assembled as block-diagonal combinations of the two component kernels.
- kernel1: StateSpaceModel#
- kernel2: StateSpaceModel#
- name#
- property dimension: int#
The dimension of the summed state space model
- coord_to_sortable(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
We assume that both kernels use the same coordinates
- stationary_covariance() tinygp.helpers.JAXArray[source]#
\(\mathbf{P}_\infty = \mathrm{BlockDiag}(\mathbf{P}_{\infty,1},\, \mathbf{P}_{\infty,2})\)
- transition_matrix(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
\(A_k = \mathrm{BlockDiag}(A_{k,1},\, A_{k,2})\)
- process_noise(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
\(Q_k = \mathrm{BlockDiag}(Q_{k,1},\, Q_{k,2})\)
- observation_model(X: tinygp.helpers.JAXArray, component=None) tinygp.helpers.JAXArray[source]#
\(H = [H_1 \;\; H_2]\), with optional component masking.
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
\(H = [H_1 \;\; H_2]\)
- class smolgp.kernels.base.Product(kernel1, kernel2)[source]#
Bases:
StateSpaceModelThe product of two
StateSpaceModelkernels.The joint state dimension is \(d = d_1 \cdot d_2\), and all matrices are assembled using Kronecker products of the two component kernels.
- kernel1: StateSpaceModel#
- kernel2: StateSpaceModel#
- name#
- property dimension: int#
The dimension of the product state space model
- coord_to_sortable(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
We assume that both kernels use the same coordinates
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
\(L\) for products is not uniquely defined, only the combination \(L Q_c L^T\) is. A convenient choice then for \(L\) is the identity matrix, which we return here. Then, \(Q_c\) is chosen so that \(L Q_c L^T\) gives the correct process noise.
- stationary_covariance() tinygp.helpers.JAXArray[source]#
\(\mathbf{P}_\infty = \mathbf{P}_{\infty,1} \otimes \mathbf{P}_{\infty,2}\)
- transition_matrix(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
\(A_k = A_{k,1} \otimes A_{k,2}\)
- process_noise(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
\(Q_k\) for a product is best determined via the identity \(Q_k = \mathbf{P}_\infty - A_k \mathbf{P}_\infty A_k^T\).
- observation_model(X: tinygp.helpers.JAXArray, component=None) tinygp.helpers.JAXArray[source]#
\(H = H_1 \otimes H_2\), with optional component masking.
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
\(H = H_1 \otimes H_2\)
- class smolgp.kernels.base.Wrapper[source]#
Bases:
StateSpaceModelA base class for wrapping kernels with some custom implementations
- kernel: StateSpaceModel#
- property dimension: int#
The dimension of the state space model, d
- coord_to_sortable(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
A helper function used to convert coordinates to sortable 1-D values
By default, this is the identity, but in cases where
Xis structured (e.g. multivariate inputs), this can be used to appropriately unwrap that structure.
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the process, \(F\)
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the process, \(\mathbf{P}_\infty\)
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation matrix for the process, \(H\)
- transition_matrix(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The transition matrix \(A_k\) between two states at coordinates X1 and X2.
Default behavior uses jax.scipy.linalg.expm(self.design_matrix() * (X2 - X1)), which is appropriate for stationary kernels defined by a linear Gaussian SSM.
Overload this method if you have a more general model or simply wish to define the transition matrix analytically.
- process_noise(X1: tinygp.helpers.JAXArray, X2: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The process noise matrix \(Q_k\)
Default behavior computes \(Q_k = \mathbf{P}_\infty - A_k \mathbf{P}_\infty A_k^T\) (see Eq. 7 in Solin & Särkka (2014)). Pass
use_van_loan=Trueto instead compute \(Q_k\) via the Van Loan (1978) matrix exponential method using \(F\), \(L\), and \(Q_c\).Overload this method if you have a more general model or wish to define the process noise analytically.
- class smolgp.kernels.base.Scale[source]#
Bases:
WrapperThe product of a scalar and a state space kernel.
- scale: tinygp.helpers.JAXArray | float#
- class smolgp.kernels.base.Constant(sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'Constant', **kwargs)[source]#
Bases:
StateSpaceModelA constant kernel
\[k(\mathbf{x}_i,\,\mathbf{x}_j) = \sigma^2\]where \(\sigma\) is a parameter.
- Parameters:
sigma – The parameter \(\sigma\) in the above equation.
- sigma: tinygp.helpers.JAXArray | float#
- name = 'Constant'#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for a Constant process, F
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of a Constant process, Pinf
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for a Constant process
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix L for a Constant process
- class smolgp.kernels.base.SHO(omega: tinygp.helpers.JAXArray | float, quality: tinygp.helpers.JAXArray | float, sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'SHO', **kwargs)[source]#
Bases:
StateSpaceModelThe damped, driven stochastic harmonic oscillator kernel
This form of the kernel was introduced by Foreman-Mackey et al. (2017), and it takes the form:
\[\begin{split}k(\Delta) = \sigma^2\,\exp\left(-\frac{\omega_0\,\Delta}{2\,Q}\right) \left\{\begin{array}{ll} 1 + \omega_0\,\Delta & \mbox{for } Q = 1/2 \\ \cosh(\eta\,\omega_0\,\Delta) + \frac{1}{2\eta Q} \sinh(\eta\,\omega_0\,\Delta) & \mbox{for } Q < 1/2 \\ \frac{1}{2\eta Q}\cos(\eta\,\omega_0\,\Delta) + \sin(\eta\,\omega_0\,\Delta) & \mbox{for } Q > 1/2 \end{array}\right.\end{split}\]for \(\Delta = |x_i - x_j|\), \(\eta = \sqrt{|1 - 1/(4Q^2)|}\).
- Parameters:
omega – The parameter \(\omega_0\).
quality – The parameter \(Q\).
sigma (optional) – The parameter \(\sigma\). Defaults to a value of 1. Specifying the explicit value here provides a slight performance boost compared to independently multiplying the kernel with a prefactor.
- omega: tinygp.helpers.JAXArray | float#
- quality: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- eta: tinygp.helpers.JAXArray | float#
- name = 'SHO'#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the SHO process, F
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the SHO process, Pinf
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for the SHO process
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix L for the SHO process
- class smolgp.kernels.base.Exp(scale: tinygp.helpers.JAXArray | float, sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'Exp', **kwargs)[source]#
Bases:
StateSpaceModelA state space implementation of
tinygp.kernels.quasisep.ExpThis kernel takes the form:
\[k(\Delta)=\sigma^2\,\exp\left(-\frac{\Delta}{\ell}\right)\]for \(\Delta = |x_i - x_j|\). Also known as the “Ornstein-Uhlenbeck” kernel, and is also equivalent to a Matérn-1/2 kernel.
- Parameters:
scale – The parameter \(\ell\).
sigma (optional) – The parameter \(\sigma\). Defaults to a value of 1.
- scale: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- lam: tinygp.helpers.JAXArray | float#
- name = 'Exp'#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the Exp process, F
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the Exp process, Pinf
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for the Exp process
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix L for the Exp process
- class smolgp.kernels.base.Matern32(scale: tinygp.helpers.JAXArray | float, sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'Matern32', **kwargs)[source]#
Bases:
StateSpaceModelA state space implementation of
tinygp.kernels.quasisep.Matern32This kernel takes the form:
\[k(\Delta)=\sigma^2\,\left(1+f\,\Delta\right)\,\exp(-f\,\Delta)\]for \(\Delta = |x_i - x_j|\) and \(f = \sqrt{3} / \ell\).
- Parameters:
scale – The parameter \(\ell\).
sigma (optional) – The parameter \(\sigma\). Defaults to a value of 1.
- scale: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- lam: tinygp.helpers.JAXArray | float#
- name = 'Matern32'#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the Matern-3/2 process, F
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the Matern-3/2 process, Pinf
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for the Matern-3/2 process
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix L for the Matern-3/2 process
- class smolgp.kernels.base.Matern52(scale: tinygp.helpers.JAXArray | float, sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'Matern52', **kwargs)[source]#
Bases:
StateSpaceModelA state space implementation of
tinygp.kernels.quasisep.Matern52This kernel takes the form:
\[k(\Delta)=\sigma^2\,\left(1+f\,\Delta + \frac{f^2\,\Delta^2}{3}\right) \,\exp(-f\,\Delta)\]for \(\Delta = |x_i - x_j|\) and \(f = \sqrt{5} / \ell\).
- Parameters:
scale – The parameter \(\ell\).
sigma (optional) – The parameter \(\sigma\). Defaults to a value of 1.
- scale: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- lam: tinygp.helpers.JAXArray | float#
- name = 'Matern52'#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the Matern-5/2 process, F
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the Matern-5/2 process, Pinf
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for the Matern-5/2 process
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix L for the Matern-5/2 process
- class smolgp.kernels.base.Cosine(scale, sigma=jnp.ones(()), name='Cosine', **kwargs)[source]#
Bases:
StateSpaceModelA state space implementation of
tinygp.kernels.quasisep.CosineThis kernel takes the form:
\[k(\Delta)=\sigma^2\,\cos(-2\,\pi\,\Delta/\ell)\]for \(\Delta = |x_i - x_j|\).
- Parameters:
scale – The parameter \(\ell\).
sigma (optional) – The parameter \(\sigma\). Defaults to a value of 1.
- scale: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- omega: tinygp.helpers.JAXArray | float#
- name = 'Cosine'#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the Cosine process, F
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the Cosine process, Pinf
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for the Cosine process
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix L for the Cosine process
- class smolgp.kernels.base.ExpSineSquared(period: tinygp.helpers.JAXArray | float, gamma: tinygp.helpers.JAXArray | float = jnp.ones(()), sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'ExpSineSquared', order: int | None = None, **kwargs)[source]#
Bases:
WrapperThe exponential sine squared or “periodic” kernel
\[k(\mathbf{x}_i,\,\mathbf{x}_j) = \sigma^2 \exp(-\Gamma\,\sin^2 \pi r)\]where, by default,
\[r = ||(\mathbf{x}_i - \mathbf{x}_j) / P||_1\]In the state space representation, this kernel is approximated using a finite number of basis functions. The method was introduced by Solin & Särkkä (2014). See their Figure 2 for the number of basis functions required to reach desired accuracy. Default behavior will automatically select the number of basis functions based on the length scale \(\ell\).
- Parameters:
period – The parameter \(P\).
gamma – The parameter \(\Gamma\).
sigma – The parameter \(\sigma\). Defaults to a value of 1.
- gamma: tinygp.helpers.JAXArray | float | None = None#
- period: tinygp.helpers.JAXArray | float#
- scale: tinygp.helpers.JAXArray | float#
- omega: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- order: int | None#
- kernel: StateSpaceModel#
- name = 'ExpSineSquared'#
- error_bound()[source]#
An upper bound on the error in the covariance from the Taylor series approximation.
See Sec 3.4 of Solin & Särkkä (2014).
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the process, \(\mathbf{P}_\infty\)
- class PeriodicTerm(order, omega, scale, **kwargs)[source]#
Bases:
StateSpaceModelA single term in the state space representation of the exponential sine squared or “periodic” kernel
See Solin & Särkkä (2014) for details.
- order: int#
- omega: tinygp.helpers.JAXArray | float#
- scale: tinygp.helpers.JAXArray | float#
- name#
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the PeriodicTerm, \(F\)
- stationary_covariance() tinygp.helpers.JAXArray[source]#
The stationary covariance of the PeriodicTerm process, \(\mathbf{P}_\infty\)
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation matrix for the PeriodicTerm, \(H\)
- noise() tinygp.helpers.JAXArray[source]#
The spectral density of the white noise for the PeriodicTerm, \(Q_c\)
- noise_effect_matrix() tinygp.helpers.JAXArray[source]#
The noise effect matrix \(L\) for the PeriodicTerm
- Ij(j, x, terms=50) tinygp.helpers.JAXArray[source]#
The modified Bessel function of the first kind, order j, at x. Approximated via a truncated Taylor series expansion.
- class smolgp.kernels.base.Matern(nu: tinygp.helpers.JAXArray | float, scale: tinygp.helpers.JAXArray | float, sigma: tinygp.helpers.JAXArray | float = jnp.ones(()), name: str = 'Matern', **kwargs)[source]#
Bases:
StateSpaceModelA state space implementation of the generic half-integer Matérn kernel with smoothness parameter \(\nu = p + 1/2\) for integer \(p \geq 0\), length scale \(\ell\), and amplitude \(\sigma\).
The model is dimension \(d = \nu + 1/2\) and has the form (see Eq. 12.34-35 of Särkkä and Solin 2019):
\[\begin{split}F = \begin{pmatrix} 0 & 1 & 0 & & \\ \vdots & 0 & 1 & & \\ & & \ddots & \ddots & \\ -a_1\lambda^d & -a_2\lambda^{d-1} & \cdots & -a_d\lambda \end{pmatrix}, L = \begin{pmatrix} 0 \\ \vdots \\ 0 \\ 1 \end{pmatrix},\end{split}\]where \(\lambda = \sqrt{2\nu}/\ell\) and the coefficients \(a_i = \binom{d}{i-1}\) are the binomial coefficients. The spectral noise density is given by:
\[Q_c = \sigma^2 \frac{[(d-1)!]^2}{(2d-2)!} (2\lambda)^{2d-1}.\]- Parameters:
nu – The smoothness parameter \(\nu\) (must be half-integer).
scale – The parameter \(\ell\).
sigma (optional) – The parameter \(\sigma\). Defaults to a value of 1.
- nu: tinygp.helpers.JAXArray | float#
- scale: tinygp.helpers.JAXArray | float#
- sigma: tinygp.helpers.JAXArray | float#
- lam: tinygp.helpers.JAXArray | float#
- name#
- property dimension: int#
The dimension of the state space for the Matérn process
- design_matrix() tinygp.helpers.JAXArray[source]#
The design (also called the feedback) matrix for the Matern process, F
- observation_matrix(X: tinygp.helpers.JAXArray) tinygp.helpers.JAXArray[source]#
The observation model H for the Matern process