pybop.costs.fitting_costs#

Classes#

FittingCost

Overwrites and extends BaseCost class for fitting-type cost functions.

ObserverCost

Observer cost function.

Module Contents#

class pybop.costs.fitting_costs.FittingCost(problem, weighting: str | numpy.ndarray = None)[source]#

Bases: pybop.costs.base_cost.BaseCost

Overwrites and extends BaseCost class for fitting-type cost functions.

This class is intended to be subclassed to create specific cost functions for evaluating model predictions against a set of data. The cost function quantifies the goodness-of-fit between the model predictions and the observed data, with a lower cost value indicating a better fit.

Additional Parameters#

weightingUnion[str, np.ndarray], optional

The type of weighting to use when taking the sum or mean of the error measure.

abstractmethod _error_measure(r: numpy.ndarray, dy: numpy.ndarray | 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(signal), len(domain_data)).

  • dy (np.ndarray, optional) – The corresponding gradient with respect to the parameters for each signal. The dimensions of dy are (len(parameters), len(signal), 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]]

compute(y: dict, dy: dict | None = None) float | tuple[float, numpy.ndarray][source]#

Computes the cost function for the given predictions.

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 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]]

weighting = None[source]#
class pybop.costs.fitting_costs.ObserverCost(observer: pybop.observers.observer.Observer)[source]#

Bases: pybop.costs.base_cost.BaseCost

Observer cost function.

Computes the cost function for an observer model, which is log likelihood of the data points given the model parameters.

Inherits all parameters and attributes from BaseCost.

compute(y: dict, dy: numpy.ndarray | None = None) float[source]#

Computes the cost function for the given predictions.

Parameters:
  • y (dict) – The 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.

Returns:

The observer cost (negative of the log likelihood).

Return type:

float

_has_separable_problem = False[source]#
_observer[source]#