pybop.costs.base_cost#

Classes#

BaseCost

Base cost.

LogPrior

The log-prior as a cost, to be used with the LogPosterior class.

Module Contents#

class pybop.costs.base_cost.BaseCost[source]#

Base cost.

_de#

The gradient of the cost function to use if an error occurs during evaluation. Defaults to 1.0.

Type:

float

minimising#

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

evaluate(solution: pybop.simulators.solution.Solution | list[pybop.simulators.solution.Solution], inputs: pybop.parameters.parameter.Inputs | list[pybop.parameters.parameter.Inputs] | None = None, calculate_sensitivities: bool = False) pybop.costs.evaluation.Evaluation[source]#

Computes the cost function for the given predictions.

Parameters:
  • solution (Solution | list[Solution]) – The simulation result or a list of results.

  • inputs (Inputs | list[Inputs], optional) – Input parameters or a list of inputs (default: None).

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

abstractmethod evaluate_batch(solution: list[pybop.simulators.solution.Solution], inputs: list[pybop.parameters.parameter.Inputs], calculate_sensitivities: bool = False) pybop.costs.evaluation.Evaluation[source]#

Computes the cost function for the given predictions.

Parameters:
  • solution (list[Solution]) – A list of simulation results.

  • inputs (list[Inputs]) – The corresponding list of input parameters.

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

failure(parameter_names: collections.abc.Iterable[str], 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.

set_target(target: list[str] | str | None = None, dataset: pybop.processing.dataset.Dataset | None = None)[source]#

Set the target variable and target data from a pybop.Dataset.

stack_sensitivities(solution: pybop.simulators.solution.Solution) dict[str, numpy.ndarray][source]#

Stack the sensitivities for each output variable into a single array.

Parameters:

solution (pybop.Solution | pybamm.Solution) – A solution object containing a dictionary of sensitivities for each output variable.

Returns:

The sensitivities dy/dx(t) for each output variable y with respect to each parameter x over the domain t. The dictionary keys are the parameter names and the arrays are of dimensions (len(target), len(domain_data)).

Return type:

dict[str, np.ndarray[np.float64]]

_dataset = None#
_de = 1.0#
_domain = 'Time [s]'#
_domain_data = None#
_target = ['Voltage [V]']#
_target_data = None#
property domain#
property domain_data#
minimising = True#
property n_parameters#
property name#
parameters#
property target#
property target_data#
class pybop.costs.base_cost.LogPrior(parameters)[source]#

Bases: BaseCost

The log-prior as a cost, to be used with the LogPosterior class.

evaluate_batch(solution: list[pybop.simulators.solution.Solution], inputs: list[pybop.parameters.parameter.Inputs], calculate_sensitivities: bool = False) pybop.costs.evaluation.Evaluation[source]#

Computes the log-prior for the given inputs, and optionally the sensitivities.

Parameters:
  • solution (list[Solution]) – A list of simulation results.

  • inputs (list[Inputs]) – The corresponding list of input parameters.

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

minimising = False#
parameters#