pybop.costs.base_cost#
Classes#
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
- abstractmethod evaluate(solution: 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:
solution (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]]
- 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:
BaseCostThe log-prior as a cost, to be used with the LogPosterior class.
- evaluate(solution: pybop.simulators.solution.Solution, inputs: pybop.parameters.parameter.Inputs | None = None, calculate_sensitivities: bool = False) float | tuple[float, numpy.ndarray][source]#
Computes the log-prior for the given inputs, and optionally the sensitivities.
- minimising = False#
- parameters#