pybop.costs.base_cost#

Classes#

BaseCost

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 evaluate(sol: pybop.simulators.solution.Solution, inputs: pybop.parameters.parameter.Inputs | None = None, calculate_sensitivities: bool = False) float | tuple[float, numpy.ndarray][source]#

Computes the cost function for the given predictions.

Parameters:
  • sol (pybop.Solution | pybamm.Solution) – The simulation result.

  • inputs (Inputs, optional) – Input parameters (default: None).

  • calculate_sensitivities (bool) – Whether to also return the sensitivities (default: False).

Returns:

If the solution has sensitivities, 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]]

failure(calculate_sensitivities: bool = True)[source]#
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(sol: pybop.simulators.solution.Solution) 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]

_de = 1.0[source]#
_domain_data = None[source]#
_target_data = None[source]#
domain = 'Time [s]'[source]#
property domain_data[source]#
grad_fail = None[source]#
minimising = True[source]#
property n_parameters[source]#
parameters[source]#
target = ['Voltage [V]'][source]#
property target_data[source]#