Skip to content

Likelihoods

gpjax.likelihoods

tfb = tfp.bijectors module-attribute
tfd = tfp.distributions module-attribute
NonGaussian = Union[Poisson, Bernoulli] module-attribute
__all__ = ['AbstractLikelihood', 'NonGaussian', 'Gaussian', 'Bernoulli', 'Poisson', 'inv_probit'] module-attribute
AbstractLikelihood dataclass

Bases: Module

Abstract base class for likelihoods.

num_datapoints: int = static_field() class-attribute instance-attribute
integrator: AbstractIntegrator = static_field(GHQuadratureIntegrator()) class-attribute instance-attribute
__init_subclass__(mutable: bool = False)
replace(**kwargs: Any) -> Self

Replace the values of the fields of the object.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_meta(**kwargs: Any) -> Self

Replace the metadata of the fields.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the metadata of the fields of the object.

{}
Returns
Module: with the metadata of the fields replaced.
update_meta(**kwargs: Any) -> Self

Update the metadata of the fields. The metadata must already exist.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_trainable(**kwargs: Dict[str, bool]) -> Self

Replace the trainability status of local nodes of the Module.

replace_bijector(**kwargs: Dict[str, tfb.Bijector]) -> Self

Replace the bijectors of local nodes of the Module.

constrain() -> Self

Transform model parameters to the constrained space according to their defined bijectors.

Returns
Module: transformed to the constrained space.
unconstrain() -> Self

Transform model parameters to the unconstrained space according to their defined bijectors.

Returns
Module: transformed to the unconstrained space.
stop_gradient() -> Self

Stop gradients flowing through the Module.

Returns
Module: with gradients stopped.
trainables() -> Self
__call__(*args: Any, **kwargs: Any) -> tfd.Distribution

Evaluate the likelihood function at a given predictive distribution.

Parameters:

Name Type Description Default
*args Any

Arguments to be passed to the likelihood's predict method.

()
**kwargs Any

Keyword arguments to be passed to the likelihood's predict method.

{}
Returns
tfd.Distribution: The predictive distribution.
predict(*args: Any, **kwargs: Any) -> tfd.Distribution abstractmethod

Evaluate the likelihood function at a given predictive distribution.

Parameters:

Name Type Description Default
*args Any

Arguments to be passed to the likelihood's predict method.

()
**kwargs Any

Keyword arguments to be passed to the likelihood's predict method.

{}
Returns
tfd.Distribution: The predictive distribution.

Return the link function of the likelihood function.

tfd.Distribution: The distribution of observations, y, given values of the
    Gaussian process, f.
expected_log_likelihood(y: Float[Array, 'N D'], mean: Float[Array, 'N D'], variance: Float[Array, 'N D']) -> Float[Array, ' N']

Compute the expected log likelihood.

For a variational distribution q(f)∼N(m,s)q(f)\sim\mathcal{N}(m, s) and a likelihood p(y∣f)p(y|f), compute the expected log likelihood:

Eq(f)[log⁑p(y∣f)] \mathbb{E}_{q(f)}\left[\log p(y|f)\right]

Parameters:

Name Type Description Default
y Float[Array, 'N D']

The observed response variable.

required
mean Float[Array, 'N D']

The variational mean.

required
variance Float[Array, 'N D']

The variational variance.

required

Returns:

Name Type Description
ScalarFloat Float[Array, ' N']

The expected log likelihood.

Gaussian dataclass

Bases: AbstractLikelihood

Gaussian likelihood object.

Parameters:

Name Type Description Default
obs_stddev Union[ScalarFloat, Float[Array, '#N']]

the standard deviation of the Gaussian observation noise.

param_field(array(1.0), bijector=Softplus())
num_datapoints: int = static_field() class-attribute instance-attribute
obs_stddev: Union[ScalarFloat, Float[Array, '#N']] = param_field(jnp.array(1.0), bijector=tfb.Softplus()) class-attribute instance-attribute
integrator: AbstractIntegrator = static_field(AnalyticalGaussianIntegrator()) class-attribute instance-attribute
__init_subclass__(mutable: bool = False)
replace(**kwargs: Any) -> Self

Replace the values of the fields of the object.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_meta(**kwargs: Any) -> Self

Replace the metadata of the fields.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the metadata of the fields of the object.

{}
Returns
Module: with the metadata of the fields replaced.
update_meta(**kwargs: Any) -> Self

Update the metadata of the fields. The metadata must already exist.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_trainable(**kwargs: Dict[str, bool]) -> Self

Replace the trainability status of local nodes of the Module.

replace_bijector(**kwargs: Dict[str, tfb.Bijector]) -> Self

Replace the bijectors of local nodes of the Module.

constrain() -> Self

Transform model parameters to the constrained space according to their defined bijectors.

Returns
Module: transformed to the constrained space.
unconstrain() -> Self

Transform model parameters to the unconstrained space according to their defined bijectors.

Returns
Module: transformed to the unconstrained space.
stop_gradient() -> Self

Stop gradients flowing through the Module.

Returns
Module: with gradients stopped.
trainables() -> Self
__call__(*args: Any, **kwargs: Any) -> tfd.Distribution

Evaluate the likelihood function at a given predictive distribution.

Parameters:

Name Type Description Default
*args Any

Arguments to be passed to the likelihood's predict method.

()
**kwargs Any

Keyword arguments to be passed to the likelihood's predict method.

{}
Returns
tfd.Distribution: The predictive distribution.
expected_log_likelihood(y: Float[Array, 'N D'], mean: Float[Array, 'N D'], variance: Float[Array, 'N D']) -> Float[Array, ' N']

Compute the expected log likelihood.

For a variational distribution q(f)∼N(m,s)q(f)\sim\mathcal{N}(m, s) and a likelihood p(y∣f)p(y|f), compute the expected log likelihood:

Eq(f)[log⁑p(y∣f)] \mathbb{E}_{q(f)}\left[\log p(y|f)\right]

Parameters:

Name Type Description Default
y Float[Array, 'N D']

The observed response variable.

required
mean Float[Array, 'N D']

The variational mean.

required
variance Float[Array, 'N D']

The variational variance.

required

Returns:

Name Type Description
ScalarFloat Float[Array, ' N']

The expected log likelihood.

The link function of the Gaussian likelihood.

Parameters:

Name Type Description Default
f Float[Array, ...]

Function values.

required
tfd.Normal: The likelihood function.
predict(dist: Union[tfd.MultivariateNormalTriL, GaussianDistribution]) -> tfd.MultivariateNormalFullCovariance

Evaluate the Gaussian likelihood.

Evaluate the Gaussian likelihood function at a given predictive distribution. Computationally, this is equivalent to summing the observation noise term to the diagonal elements of the predictive distribution's covariance matrix.

Parameters:

Name Type Description Default
dist Distribution

The Gaussian process posterior, evaluated at a finite set of test points.

required
Returns
tfd.Distribution: The predictive distribution.
Bernoulli dataclass

Bases: AbstractLikelihood

num_datapoints: int = static_field() class-attribute instance-attribute
integrator: AbstractIntegrator = static_field(GHQuadratureIntegrator()) class-attribute instance-attribute
__init_subclass__(mutable: bool = False)
replace(**kwargs: Any) -> Self

Replace the values of the fields of the object.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_meta(**kwargs: Any) -> Self

Replace the metadata of the fields.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the metadata of the fields of the object.

{}
Returns
Module: with the metadata of the fields replaced.
update_meta(**kwargs: Any) -> Self

Update the metadata of the fields. The metadata must already exist.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_trainable(**kwargs: Dict[str, bool]) -> Self

Replace the trainability status of local nodes of the Module.

replace_bijector(**kwargs: Dict[str, tfb.Bijector]) -> Self

Replace the bijectors of local nodes of the Module.

constrain() -> Self

Transform model parameters to the constrained space according to their defined bijectors.

Returns
Module: transformed to the constrained space.
unconstrain() -> Self

Transform model parameters to the unconstrained space according to their defined bijectors.

Returns
Module: transformed to the unconstrained space.
stop_gradient() -> Self

Stop gradients flowing through the Module.

Returns
Module: with gradients stopped.
trainables() -> Self
__call__(*args: Any, **kwargs: Any) -> tfd.Distribution

Evaluate the likelihood function at a given predictive distribution.

Parameters:

Name Type Description Default
*args Any

Arguments to be passed to the likelihood's predict method.

()
**kwargs Any

Keyword arguments to be passed to the likelihood's predict method.

{}
Returns
tfd.Distribution: The predictive distribution.
expected_log_likelihood(y: Float[Array, 'N D'], mean: Float[Array, 'N D'], variance: Float[Array, 'N D']) -> Float[Array, ' N']

Compute the expected log likelihood.

For a variational distribution q(f)∼N(m,s)q(f)\sim\mathcal{N}(m, s) and a likelihood p(y∣f)p(y|f), compute the expected log likelihood:

Eq(f)[log⁑p(y∣f)] \mathbb{E}_{q(f)}\left[\log p(y|f)\right]

Parameters:

Name Type Description Default
y Float[Array, 'N D']

The observed response variable.

required
mean Float[Array, 'N D']

The variational mean.

required
variance Float[Array, 'N D']

The variational variance.

required

Returns:

Name Type Description
ScalarFloat Float[Array, ' N']

The expected log likelihood.

The probit link function of the Bernoulli likelihood.

Parameters:

Name Type Description Default
f Float[Array, ...]

Function values.

required
tfd.Distribution: The likelihood function.
predict(dist: tfd.Distribution) -> tfd.Distribution

Evaluate the pointwise predictive distribution.

Evaluate the pointwise predictive distribution, given a Gaussian process posterior and likelihood parameters.

Parameters:

Name Type Description Default
dist Distribution

The Gaussian process posterior, evaluated at a finite set of test points.

required
Returns
tfd.Distribution: The pointwise predictive distribution.
Poisson dataclass

Bases: AbstractLikelihood

num_datapoints: int = static_field() class-attribute instance-attribute
integrator: AbstractIntegrator = static_field(GHQuadratureIntegrator()) class-attribute instance-attribute
__init_subclass__(mutable: bool = False)
replace(**kwargs: Any) -> Self

Replace the values of the fields of the object.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_meta(**kwargs: Any) -> Self

Replace the metadata of the fields.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the metadata of the fields of the object.

{}
Returns
Module: with the metadata of the fields replaced.
update_meta(**kwargs: Any) -> Self

Update the metadata of the fields. The metadata must already exist.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments to replace the fields of the object.

{}
Returns
Module: with the fields replaced.
replace_trainable(**kwargs: Dict[str, bool]) -> Self

Replace the trainability status of local nodes of the Module.

replace_bijector(**kwargs: Dict[str, tfb.Bijector]) -> Self

Replace the bijectors of local nodes of the Module.

constrain() -> Self

Transform model parameters to the constrained space according to their defined bijectors.

Returns
Module: transformed to the constrained space.
unconstrain() -> Self

Transform model parameters to the unconstrained space according to their defined bijectors.

Returns
Module: transformed to the unconstrained space.
stop_gradient() -> Self

Stop gradients flowing through the Module.

Returns
Module: with gradients stopped.
trainables() -> Self
__call__(*args: Any, **kwargs: Any) -> tfd.Distribution

Evaluate the likelihood function at a given predictive distribution.

Parameters:

Name Type Description Default
*args Any

Arguments to be passed to the likelihood's predict method.

()
**kwargs Any

Keyword arguments to be passed to the likelihood's predict method.

{}
Returns
tfd.Distribution: The predictive distribution.
expected_log_likelihood(y: Float[Array, 'N D'], mean: Float[Array, 'N D'], variance: Float[Array, 'N D']) -> Float[Array, ' N']

Compute the expected log likelihood.

For a variational distribution q(f)∼N(m,s)q(f)\sim\mathcal{N}(m, s) and a likelihood p(y∣f)p(y|f), compute the expected log likelihood:

Eq(f)[log⁑p(y∣f)] \mathbb{E}_{q(f)}\left[\log p(y|f)\right]

Parameters:

Name Type Description Default
y Float[Array, 'N D']

The observed response variable.

required
mean Float[Array, 'N D']

The variational mean.

required
variance Float[Array, 'N D']

The variational variance.

required

Returns:

Name Type Description
ScalarFloat Float[Array, ' N']

The expected log likelihood.

The link function of the Poisson likelihood.

Parameters:

Name Type Description Default
f Float[Array, ...]

Function values.

required

Returns:

Type Description
Distribution

tfd.Distribution: The likelihood function.

predict(dist: tfd.Distribution) -> tfd.Distribution

Evaluate the pointwise predictive distribution.

Evaluate the pointwise predictive distribution, given a Gaussian process posterior and likelihood parameters.

Parameters:

Name Type Description Default
dist Distribution

The Gaussian process posterior, evaluated at a finite set of test points.

required

Returns:

Type Description
Distribution

tfd.Distribution: The pointwise predictive distribution.

inv_probit(x: Float[Array, ' *N']) -> Float[Array, ' *N']

Compute the inverse probit function.

Parameters:

Name Type Description Default
x Float[Array, '*N']

A vector of values.

required
Returns
Float[Array, "*N"]: The inverse probit of the input vector.