pybop.costs.feature_distances#

Classes#

ExponentialFeatureDistance

Exponential fit cost function.

FeatureDistance

Base for defining cost functions based on comparing fit functions.

SquareRootFeatureDistance

Square-root fit cost function.

Functions#

indices_of(values, target)

Module Contents#

class pybop.costs.feature_distances.ExponentialFeatureDistance(dataset: pybop.processing.dataset.Dataset, target: str = None, feature: str = 'inverse_timescale', time_start: float = None, time_end: float = None)[source]#

Bases: FeatureDistance

Exponential fit cost function.

Fits an exponential and compares either its asymptote, its magnitude, or its timescale between model predictions and target data.

Supported features: - “asymptote”: The exponential fit value at infinite time. - “magnitude”: The prefactor of the exponential term. - “timescale”: The denominator in the exponential argument. - “inverse_timescale”: 1 over “timescale”; may perform better.

_feature_selection(fit)[source]#
_fit_guess(t, y)[source]#
_inverse_fit_function(y, b, c, d)[source]#

Logarithm function to transform data for a linear fit.

_supported_features = ['asymptote', 'magnitude', 'timescale', 'inverse_timescale']#
class pybop.costs.feature_distances.FeatureDistance(dataset: pybop.processing.dataset.Dataset, target: str = None, feature: str = None, time_start: float = None, time_end: float = None)[source]#

Bases: pybop.costs.base_cost.BaseCost

Base for defining cost functions based on comparing fit functions.

Parameters:
  • dataset (pybop.Dataset) – Dataset object containing the target data.

  • target (str, optional) – The name of the target variable.

  • feature (str, optional) – The name of the parameter to use for fitting, must be one of the supported features.

  • time_start (float, optional) – Set the time (in seconds) from which onwards the data shall be fitted, counted from the start of the data. Default is the start.

  • time_end (float, optional) – Set the time (in seconds) until which the data shall be fitted, counted from the start of the data. Default is the end.

__call__(y: numpy.ndarray, dy: numpy.ndarray | None = None) float | tuple[float, numpy.ndarray][source]#
_feature_selection(fit)[source]#
_fit(t, y)[source]#

Uses SciPy to fit data. For numerical reasons, the fitting involves applying the fit function to data and comparing to identity.

_fit_guess(t, y)[source]#
_inverse_fit_function(y, *args)[source]#
evaluate(solution: pybop.simulators.solution.Solution, inputs: pybop.parameters.parameter.Inputs | None = None, calculate_sensitivities: bool = False) pybop.costs.evaluation.Evaluation[source]#

Evaluate the feature distance for the given solution.

_supported_features = []#
end_index#
feature = None#
start_index#
time_end = None#
time_start = None#
class pybop.costs.feature_distances.SquareRootFeatureDistance(dataset: pybop.processing.dataset.Dataset, target: str = None, feature: str = 'inverse_slope', time_start: float = None, time_end: float = None)[source]#

Bases: FeatureDistance

Square-root fit cost function.

Fits a square-root fit function and compares either its offset or its slope between model predictions and target data.

Supported features: - “offset”: The value of the square-root fit at the start. - “slope”: The prefactor of the square-root over time. - “inverse_slope”: 1 over “slope”; may perform better.

_feature_selection(fit)[source]#
_fit_guess(t, y)[source]#
_inverse_fit_function(y, b, c)[source]#

Square function to transform data for a linear fit.

_supported_features = ['offset', 'slope', 'inverse_slope']#
pybop.costs.feature_distances.indices_of(values, target)[source]#