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:
objectHigh-level interface for Gaussian and Poissonian likelihoods.
The class stores
dataandmodel_parametersand 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,
datais 1D or 2D, where axis 0 represents different samples and axis 1 the values. For the Poissonian likelihoods,datais reshaped to align withmodel_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_gridsis a tuple of 1D arrays giving the evaluation coordinates for each dimension.probabilitiesis 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:
countsis the data reshaped to align with the model parameters.probabilitiesis an array of Poisson probabilities (or log-probabilities) computed fromcountsandmodel_parameters.
- Return type:
A tuple
(counts, probabilities)where