pybop.costs._likelihoods#

Classes#

BaseLikelihood

Base class for likelihoods

GaussianLogLikelihood

This class represents a Gaussian Log Likelihood, which assumes that the

GaussianLogLikelihoodKnownSigma

This class represents a Gaussian Log Likelihood with a known sigma,

MAP

Maximum a posteriori cost function.

Module Contents#

class pybop.costs._likelihoods.BaseLikelihood(problem: pybop.problems.base_problem.BaseProblem)[source]#

Bases: pybop.costs.base_cost.BaseCost

Base class for likelihoods

class pybop.costs._likelihoods.GaussianLogLikelihood(problem: pybop.problems.base_problem.BaseProblem, sigma0: float | List[float] | List[pybop.parameters.parameter.Parameter] = 0.002, dsigma_scale: float = 1.0)[source]#

Bases: BaseLikelihood

This class represents a Gaussian Log Likelihood, which assumes that the data follows a Gaussian distribution and computes the log-likelihood of observed data under this assumption.

This class estimates the standard deviation of the Gaussian distribution alongside the parameters of the model.

_logpi#

Precomputed offset value for the log-likelihood function.

Type:

float

_dsigma_scale#

Scale factor for derivative of standard deviation.

Type:

float

_add_sigma_parameters(sigma0)[source]#
_add_single_sigma(index, value)[source]#
_evaluate(inputs: pybop.parameters.parameter.Inputs, grad: None | numpy.ndarray = None) float[source]#

Evaluates the Gaussian log-likelihood for the given parameters.

Parameters:

inputs (Inputs) – The parameters for which to evaluate the log-likelihood, including the n_outputs standard deviations of the Gaussian distributions.

Returns:

The log-likelihood value, or -inf if the standard deviations are non-positive.

Return type:

float

_evaluateS1(inputs: pybop.parameters.parameter.Inputs) Tuple[float, numpy.ndarray][source]#

Calls the problem.evaluateS1 method and calculates the log-likelihood.

Parameters:

inputs (Inputs) – The parameters for which to evaluate the log-likelihood.

Returns:

The log-likelihood and its gradient.

Return type:

Tuple[float, np.ndarray]

_pad_sigma0(sigma0)[source]#
property dsigma_scale[source]#
Scaling factor for the dsigma term in the gradient calculation.
class pybop.costs._likelihoods.GaussianLogLikelihoodKnownSigma(problem: pybop.problems.base_problem.BaseProblem, sigma0: List[float] | float)[source]#

Bases: BaseLikelihood

This class represents a Gaussian Log Likelihood with a known sigma, which assumes that the data follows a Gaussian distribution and computes the log-likelihood of observed data under this assumption.

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.

_evaluate(inputs: pybop.parameters.parameter.Inputs, grad: None | numpy.ndarray = None) float[source]#

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

_evaluateS1(inputs: pybop.parameters.parameter.Inputs) Tuple[float, numpy.ndarray][source]#

Calls the problem.evaluateS1 method and calculates the log-likelihood and gradient.

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

Check the validity of sigma0.

class pybop.costs._likelihoods.MAP(problem, likelihood, sigma0=None, gradient_step=0.001)[source]#

Bases: BaseLikelihood

Maximum a posteriori cost function.

Computes the maximum a posteriori cost function, which is the sum of the log likelihood and the log prior. The goal of maximising is achieved by setting minimising = False in the optimiser settings.

Inherits all parameters and attributes from BaseLikelihood.

_evaluate(inputs: pybop.parameters.parameter.Inputs, grad=None) float[source]#

Calculate the maximum a posteriori cost for a given set of parameters.

Parameters:
  • inputs (Inputs) – The parameters for which to evaluate the cost.

  • grad (array-like, optional) – An array to store the gradient of the cost function with respect to the parameters.

Returns:

The maximum a posteriori cost.

Return type:

float

_evaluateS1(inputs: pybop.parameters.parameter.Inputs) Tuple[float, numpy.ndarray][source]#

Compute the maximum a posteriori with respect to the parameters. The method passes the likelihood gradient to the optimiser without modification.

Parameters:

inputs (Inputs) – The parameters for which to compute the cost and gradient.

Returns:

A tuple containing the cost and the gradient. The cost is a float, and the gradient is an array-like of the same length as x.

Return type:

tuple

Raises:

ValueError – If an error occurs during the calculation of the cost or gradient.