GaussianDistribution#
- class gpjax.distributions.GaussianDistribution(loc, scale, validate_args=None)[source]#
Bases:
DistributionMultivariate Gaussian distribution for GP predictions.
This is the return type of all
predict()methods in GPJax. It wraps a mean vector and a covariancelx.AbstractLinearOperator, providing methods for sampling, computing log-probabilities, and evaluating KL divergences.The distribution is parameterised as
\[p(\mathbf{x}) = \mathcal{N}(\mathbf{x}; \boldsymbol{\mu}, \mathbf{\Sigma})\]where \(\boldsymbol{\mu}\) is the
loc(mean) vector and \(\mathbf{\Sigma}\) is represented by thescalelx.AbstractLinearOperator.- Parameters:
loc (Float[Array, " N"]) – Mean vector of the distribution.
scale (lx.AbstractLinearOperator) – Covariance matrix represented as a Lineax linear operator (e.g.
lx.MatrixLinearOperatororlx.DiagonalLinearOperator).
Examples
>>> import jax.numpy as jnp >>> import lineax as lx >>> from gpjax.distributions import GaussianDistribution >>> mu = jnp.array([0.0, 1.0]) >>> cov = lx.MatrixLinearOperator(jnp.eye(2)) >>> dist = GaussianDistribution(loc=mu, scale=cov) >>> dist.mean Array([0., 1.], dtype=float32) >>> dist.variance Array([1., 1.], dtype=float32)
Expand for references to
gpjax.distributions.GaussianDistribution- covariance()[source]#
Materialises the full covariance matrix as a dense array.
- Returns:
Dense covariance matrix.
- Return type:
Float[Array, “N N”]
- property covariance_matrix: Float[jaxlib._jax.Array, 'N N'] | Float[ndarray, 'N N']#
Property alias for
covariance().
- entropy()[source]#
Calculates the differential entropy of the distribution.
\[H[p] = \tfrac{1}{2}\bigl(N(1 + \ln 2\pi) + \ln|\mathbf{\Sigma}|\bigr)\]- Returns:
Entropy in nats.
- Return type:
- kl_divergence(other)[source]#
KL divergence from
selftoother.Computes \(\operatorname{KL}[q \| p]\) where
selfis q andotheris p.- Parameters:
other (GaussianDistribution) – The reference distribution p.
- Returns:
KL divergence in nats.
- Return type:
- log_prob(y)[source]#
Calculates the log pdf of the multivariate Gaussian.
\[\log p(\mathbf{y}) = -\tfrac{1}{2}\bigl[ N\ln 2\pi + \ln|\mathbf{\Sigma}| + (\mathbf{y} - \boldsymbol{\mu})^\top \mathbf{\Sigma}^{-1} (\mathbf{y} - \boldsymbol{\mu}) \bigr]\]- Parameters:
y (Float[Array, " N"]) – Point at which to evaluate the log-density.
- Returns:
Log probability.
- Return type:
- property mean: Float[jaxlib._jax.Array, 'N'] | Float[ndarray, 'N']#
Calculates the mean.
Expand for references to
gpjax.distributions.GaussianDistribution.mean
- median()[source]#
Calculates the median (equal to the mean for a Gaussian).
- Return type:
Float[jaxlib._jax.Array, ‘N’] | Float[ndarray, ‘N’]
- mode()[source]#
Calculates the mode (equal to the mean for a Gaussian).
- Return type:
Float[jaxlib._jax.Array, ‘N’] | Float[ndarray, ‘N’]
- sample(key, sample_shape=())[source]#
Draw samples from the distribution.
Generates samples via the reparameterisation trick:
\[\mathbf{x} = \boldsymbol{\mu} + \mathbf{L}\mathbf{z}, \quad \mathbf{z} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})\]where \(\mathbf{L}\) is the lower Cholesky factor of the covariance.
- stddev()[source]#
Calculates the marginal standard deviation.
- Return type:
Float[jaxlib._jax.Array, ‘N’] | Float[ndarray, ‘N’]
- support = RealVector(Real(), 1)#
- property variance: Float[jaxlib._jax.Array, 'N'] | Float[ndarray, 'N']#
Calculates the marginal variance (diagonal of the covariance).
Expand for references to
gpjax.distributions.GaussianDistribution.variance