pybop.costs.base_cost#
Classes#
Base cost. |
Module Contents#
- class pybop.costs.base_cost.BaseCost[source]#
Base cost.
- _de[source]#
The gradient of the cost function to use if an error occurs during evaluation. Defaults to 1.0.
- Type:
float
- minimising[source]#
If False, tells the optimiser to switch the sign of the cost and gradient to maximise by default rather than minimise (default: True).
- Type:
bool, optional
- abstractmethod compute(y: dict[str, numpy.ndarray], 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 output variables for fitting.
dy (dict[str, dict[str, np.ndarray]], optional) – The corresponding sensitivities to each parameter for each output variable.
- 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_fail_gradient(de: float = 1.0)[source]#
Set the fail gradient to a specified value.
The fail gradient is used if an error occurs during the calculation of the gradient. This method allows updating the default gradient value.
- Parameters:
de (float) – The new fail gradient value to be used.
- stack_sensitivities(dy) numpy.ndarray[source]#
Stack the sensitivities for each output variable and parameter into a single array.
- Parameters:
dict[str – A dictionary of the sensitivities dy/dx(t) for each parameter x and target y.
dict[str – A dictionary of the sensitivities dy/dx(t) for each parameter x and target y.
np.ndarray[np.float64]]] – A dictionary of the sensitivities dy/dx(t) for each parameter x and target y.
- Returns:
The combined sensitivities dy/dx(t) for each parameter and target, with dimensions of (len(parameters), len(target), len(domain_data)).
- Return type:
np.ndarray[np.float64]