pybop.costs.likelihoods#

Classes#

GaussianLogLikelihood

This class represents a Gaussian log-likelihood, which evaluates the log-likelihood under

GaussianLogLikelihoodKnownSigma

This class represents a Gaussian log-likelihood with a known sigma, which evaluates the

LogLikelihood

Base class for likelihoods.

LogPosterior

The log-posterior defined as the sum of the log-likelihood and the log-prior.

Module Contents#

class pybop.costs.likelihoods.GaussianLogLikelihood(dataset: pybop._dataset.Dataset, sigma0: float | list[float] | list[pybop.parameters.parameter.Parameter] = 0.01, dsigma_scale: float = 1.0, target: str | list[str] = None)[source]#

Bases: LogLikelihood

This class represents a Gaussian log-likelihood, which evaluates 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.

_logpi[source]#

Precomputed offset value for the log-likelihood function.

Type:

float

_dsigma_scale[source]#

Scale factor for derivative of standard deviation.

Type:

float

__call__(r: numpy.ndarray, dy: numpy.ndarray | None = None, inputs: pybop.parameters.parameter.Inputs | None = None) float | tuple[float, numpy.ndarray][source]#

Compute the Gaussian log-likelihood for the given parameters.

_add_single_sigma(index, value)[source]#
_pad_sigma0(sigma0)[source]#
set_sigma0(sigma0: float | list[float] | list[pybop.parameters.parameter.Parameter])[source]#

Set sigma0 after checking its validity.

_dsigma_scale = 1.0[source]#
_logpi[source]#
property dsigma_scale[source]#

Scaling factor for the dsigma term in the gradient calculation.

class pybop.costs.likelihoods.GaussianLogLikelihoodKnownSigma(dataset: pybop._dataset.Dataset, sigma0: list[float] | float, target: str | list[str] = None)[source]#

Bases: LogLikelihood

This class represents a Gaussian log-likelihood with a known sigma, which evaluates 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.

__call__(r: numpy.ndarray, dy: numpy.ndarray | None = None, inputs: pybop.parameters.parameter.Inputs | None = None) float | tuple[float, numpy.ndarray][source]#

Compute the Gaussian log-likelihood for the given parameters with known sigma.

set_sigma0(sigma0: numpy.ndarray | float)[source]#

Set sigma0 after checking its validity.

class pybop.costs.likelihoods.LogLikelihood(dataset: pybop._dataset.Dataset, target: str | list[str] = None)[source]#

Bases: pybop.costs.error_measures.ErrorMeasure

Base class for likelihoods.

Exists to distinguish between error measures and likelihood-based costs.

abstractmethod set_sigma0(sigma0: numpy.ndarray | float, n_outputs: int, n_data: int)[source]#

Set sigma0 after checking its validity.

minimising = False[source]#
parameters[source]#
sigma0 = None[source]#
class pybop.costs.likelihoods.LogPosterior(log_likelihood: LogLikelihood, prior: pybop.parameters.priors.BasePrior | scipy.stats.rv_continuous | None = None)[source]#

Bases: LogLikelihood

The log-posterior defined as the sum of the log-likelihood and the log-prior.

Additional Parameters#

log_likelihoodLogLikelihood

The likelihood class of type LogLikelihood.

priorOptional, Union[pybop.BasePrior, stats.rv_continuous]

The prior class of type BasePrior or stats.rv_continuous. If not provided, the prior class will be taken from the parameter priors constructed in the pybop.Parameters class.

__call__(r: numpy.ndarray, dy: numpy.ndarray | None = None, inputs: pybop.parameters.parameter.Inputs | None = None) float | tuple[float, numpy.ndarray][source]#

Computes the cost function for the given predictions.

Parameters:
  • r (np.ndarray) – The residual difference between the model prediction and the target. The dimensions of r are (len(target), len(domain_data)).

  • dy (np.ndarray, optional) – The corresponding gradient with respect to the parameters for each output variable. The dimensions of dy are (len(parameters), len(target), len(domain_data)).

Returns:

If dy is not None, returns a tuple containing the cost (float) and the gradient with dimension (len(parameters)), otherwise returns only the cost.

Return type:

np.float64 or tuple[np.float64, np.ndarray[np.float64]]

set_joint_prior()[source]#
joint_prior = None[source]#
log_likelihood[source]#
parameters[source]#
prior = None[source]#