derivkit.likelihood_kit module#

Provides the LikelihoodKit class.

Typical usage examples#

>>> import numpy as np
>>> from derivkit.likelihood_kit import LikelihoodKit
>>>
>>> # Gaussian example
>>> data = np.linspace(-5.0, 5.0, 200)
>>> theta = np.array([0.0])
>>> cov = np.array([[1.0]])
>>> lkit = LikelihoodKit(data=data, model_parameters=theta)
>>> grid, pdf = lkit.gaussian(cov=cov)
>>>
>>> # Poissonian example
>>> counts = np.array([1, 2, 3, 4])
>>> mu = np.array([0.5, 1.0, 1.5, 2.0])
>>> lkit = LikelihoodKit(data=counts, model_parameters=mu)
>>> reshaped_counts, pmf = lkit.poissonian()
class derivkit.likelihood_kit.LikelihoodKit(data: ArrayLike, model_parameters: ArrayLike)#

Bases: object

High-level interface for Gaussian and Poissonian likelihoods.

The class stores data and model_parameters and provides methods to evaluate the corresponding likelihoods.

Initialises the likelihoods object.

Parameters:
  • data – Observed data values. The expected shape depends on the particular likelihoods. For the Gaussian likelihoods, data is 1D or 2D, where axis 0 represents different samples and axis 1 the values. For the Poissonian likelihoods, data is reshaped to align with model_parameters.

  • model_parameters – Theoretical model values. For the Gaussian likelihoods, this is a 1D array of parameters used as the mean of the multivariate normal. For the Poissonian likelihoods, this is the expected counts (Poisson means).

gaussian(cov: ArrayLike, *, return_log: bool = True) tuple[tuple[ndarray[tuple[Any, ...], dtype[float64]], ...], ndarray[tuple[Any, ...], dtype[float64]]]#

Evaluates a Gaussian likelihoods for the stored data and parameters.

Parameters:
  • cov – Covariance matrix. May be a scalar, a 1D vector of diagonal variances, or a full 2D covariance matrix. It will be symmetrized and normalized internally.

  • return_log – If True, return the log-likelihoods instead of the probability density function.

Returns:

  • coordinate_grids is a tuple of 1D arrays giving the evaluation coordinates for each dimension.

  • probabilities is an array with the values of the multivariate Gaussian probability density (or log-density) evaluated on the Cartesian product of those coordinates.

Return type:

A tuple (coordinate_grids, probabilities) where

poissonian(*, return_log: bool = True) tuple[ndarray, ndarray]#

Evaluates a Poissonian likelihoods for the stored data and parameters.

Parameters:

return_log – If True, return the log-likelihoods instead of the probability mass function.

Returns:

  • counts is the data reshaped to align with the model parameters.

  • probabilities is an array of Poisson probabilities (or log-probabilities) computed from counts and model_parameters.

Return type:

A tuple (counts, probabilities) where