Skip to content

Prior

prior

Prior components.

These prior implementations adhere to a common interface provided by the abstract base class. New prior distributions can be implemented through subclassing.

Classes:

Name Description
BaseLogPrior

Base class for prior distributions.

UniformLogPrior

Implementation of a uniform prior.

GaussianLogPrior

Implementation of Gaussian prior.

mtmlda.components.prior.BaseLogPrior

Bases: ABC

Base class for prior distributions.

This class prescribes the basic interface for a prior distribution, as required by other components. Basically, a prior needs to provide methods to evaluate its log-likelihood, and to draw samples from it. The base class also provides an UM-Bridge like call interface for the evaluation of the log-probability.

Methods:

Name Description
__call__

UM-Bridge-like call interface for the log-prior

evaluate

Evaluate the log-probability for a given parameter vector

sample

Draw a sample from the prior

__init__ abstractmethod

__init__(seed: int) -> None

Base class constructor, takin seed for the internal random number generator.

Parameters:

Name Type Description Default
seed int

RNG seed

required

__call__

__call__(parameter: list[list[float]]) -> list[list[float]]

UM-Bridge-like call interface for log-probability evaluation.

This method simply converts the input parameter to a numpy array and delegates the call to the evaluate method. the output is again transformed to the UM-Bridge format.

Parameters:

Name Type Description Default
parameter list[list[float]]

Parameter candidate

required

Returns:

Type Description
list[list[float]]

list[list[float]]: Log-probability value

evaluate abstractmethod

evaluate(parameter: np.ndarray) -> float

Compute log-probability for given parameter.

sample abstractmethod

sample() -> np.ndarray

Draw a sample from the prior.

mtmlda.components.prior.UniformLogPrior

Bases: BaseLogPrior

Implementation of a uniform prior.

__init__

__init__(parameter_intervals: np.ndarray, seed: int) -> None

Constructor.

Parameters:

Name Type Description Default
parameter_intervals np.ndarray

Bounds for each parameter

required
seed int

RNG seed

required

Raises:

Type Description
ValueError

Checks for valid parameter intervals

evaluate

evaluate(parameter: np.ndarray) -> float

Compute log-probability for given parameter.

Note that the prior simply returns 0 if the parameter is within the bounds, and -inf otherwise. This is because a uniform prior enters into the posterior only as a constant, which is irrelevant in MCMC.

Raises:

Type Description
ValueError

Checks for valid parameter dimension

sample

sample() -> np.ndarray

Draw a sample from the prior.

mtmlda.components.prior.GaussianLogPrior

Bases: BaseLogPrior

Implementation of Gaussian prior.

__init__

__init__(mean: np.ndarray, covariance: np.ndarray, seed: int) -> None

Constructor.

Parameters:

Name Type Description Default
mean np.ndarray

Mean vector

required
covariance np.ndarray

Covariance matrix

required
seed int

RNG seed

required

Raises:

Type Description
ValueError

Checks for valid mean and covariance dimensions

evaluate

evaluate(parameter: np.array) -> float

Compute log-probability for given parameter.

Raises:

Type Description
ValueError

Checks for valid parameter dimension

sample

sample() -> np.ndarray

Draw a sample from the prior.