pybop.costs._likelihoods#
Classes#
Base class for likelihoods. |
|
Base class for likelihood classes which have a meta-likelihood such as LogPosterior or |
|
This class represents a Gaussian log-likelihood, which computes the log-likelihood under |
|
This class represents a Gaussian log-likelihood with a known sigma, which computes the |
|
The Log Posterior for a given problem. |
|
This class scaled a BaseLogLikelihood class by the number of observations. |
Module Contents#
- class pybop.costs._likelihoods.BaseLikelihood(problem: pybop.problems.base_problem.BaseProblem)[source]#
Bases:
pybop.costs.base_cost.BaseCostBase class for likelihoods.
- observed_fisher(inputs: pybop.parameters.parameter.Inputs | list | numpy.ndarray) numpy.ndarray | None[source]#
Compute the observed Fisher Information Matrix (FIM) for the given data.
The Fisher information is computed as the outer product of the gradients with respect to the model parameters, scaled by the inverse of the dataset size. This method should only be used with exponential-based likelihood functions.
- Parameters:
inputs (Union[dict[str, float], list-like]) – Input data for model evaluation.
- Returns:
The observed Fisher Information Matrix.
- Return type:
np.ndarray
- class pybop.costs._likelihoods.BaseMetaLikelihood(log_likelihood: BaseLikelihood)[source]#
Bases:
BaseLikelihoodBase class for likelihood classes which have a meta-likelihood such as LogPosterior or ScaledLoglikelihood. This class points the required attributes towards the composed likelihood class.
- property likelihood: BaseLikelihood[source]#
- class pybop.costs._likelihoods.GaussianLogLikelihood(problem: pybop.problems.base_problem.BaseProblem, sigma0: float | list[float] | list[pybop.parameters.parameter.Parameter] = 0.01, dsigma_scale: float = 1.0)[source]#
Bases:
BaseLikelihoodThis class represents a Gaussian log-likelihood, which computes the log-likelihood under the assumption that measurement noise on the target data follows a Gaussian distribution.
This class estimates the standard deviation of the Gaussian distribution alongside the parameters of the model.
- compute(y: dict, dy: numpy.ndarray | None = None) float | tuple[float, numpy.ndarray][source]#
Compute the Gaussian log-likelihood for the given parameters.
This method only computes the likelihood, without calling problem.evaluate().
- Parameters:
y (dict[str, np.ndarray[np.float64]]) – The dictionary of predictions with keys designating the signals for fitting.
dy (dict[str, dict[str, np.ndarray]], optional) – The corresponding gradient with respect to each parameter for each signal.
- Returns:
If dy is not None, returns a tuple containing the log-likelihood (float) and the gradient with dimension (len(parameters)), otherwise returns only the log-likelihood.
- Return type:
np.float64 or tuple[np.float64, np.ndarray[np.float64]]
- class pybop.costs._likelihoods.GaussianLogLikelihoodKnownSigma(problem: pybop.problems.base_problem.BaseProblem, sigma0: list[float] | float)[source]#
Bases:
BaseLikelihoodThis class represents a Gaussian log-likelihood with a known sigma, which computes the log-likelihood under the assumption that measurement noise on the target data follows a Gaussian distribution.
- Parameters:
sigma0 (scalar or array) – Initial standard deviation around
x0. Either a scalar value (one standard deviation for all coordinates) or an array with one entry per dimension.
- class pybop.costs._likelihoods.LogPosterior(log_likelihood: BaseLikelihood, log_prior: pybop.BasePrior | scipy.stats.rv_continuous | None = None, gradient_step: float = 0.001)[source]#
Bases:
BaseMetaLikelihoodThe Log Posterior for a given problem.
Computes the log-posterior which is proportional to the sum of the log-likelihood and the log-prior.
- Parameters:
log_likelihood (BaseLikelihood) – The likelihood class of type
BaseLikelihood.log_prior (Optional, Union[pybop.BasePrior, stats.rv_continuous]) – The prior class of type
BasePriororstats.rv_continuous. If not provided, the prior class will be taken from the parameter priors constructed in the pybop.Parameters class.gradient_step (float, default: 1e-3) – The step size for the finite-difference gradient calculation if the
log_prioris not of typeBasePrior.
- compute(y: dict, dy: numpy.ndarray | None = None) float | tuple[float, numpy.ndarray][source]#
Calculate the posterior cost for a given forward model prediction.
- Parameters:
y (dict[str, np.ndarray[np.float64]]) – The dictionary of predictions with keys designating the signals for fitting.
dy (dict[str, dict[str, np.ndarray]], optional) – The corresponding sensitivities to each parameter for each signal.
- Returns:
If dy is not None, returns a tuple containing the log-likelihood (float) and the gradient with dimension (len(parameters)), otherwise returns only the log-likelihood.
- Return type:
np.float64 or tuple[np.float64, np.ndarray[np.float64]]
- property prior: pybop.parameters.priors.BasePrior[source]#
- class pybop.costs._likelihoods.ScaledLogLikelihood(log_likelihood: BaseLikelihood)[source]#
Bases:
BaseMetaLikelihoodThis class scaled a BaseLogLikelihood class by the number of observations. The scaling factor is given below:
\[\mathcal{\hat{L(\theta)}} = \frac{1}{N} \mathcal{L(\theta)}\]This class aims to provide numerical values with lower magnitude than the canonical likelihoods, which can improve optimiser convergence in certain cases.
- compute(y: dict, dy: numpy.ndarray | None = None) float | tuple[float, numpy.ndarray][source]#
Compute the cost and, if dy is not None, its gradient with respect to the parameters.
This method only computes the cost, without calling the problem.evaluate(). This method must be implemented by subclasses.
- Parameters:
y (dict) – A dictionary of predictions with keys designating the signals for fitting.
dy (np.ndarray, optional) – The corresponding gradient with respect to the parameters for each signal.
- Raises:
NotImplementedError – If the method has not been implemented by the subclass.