pybop.costs.weighted_cost#
Classes#
A subclass for constructing a linear combination of cost functions as |
Module Contents#
- class pybop.costs.weighted_cost.WeightedCost(*costs, weights: list[float] | None = None)[source]#
Bases:
pybop.costs.base_cost.BaseCostA subclass for constructing a linear combination of cost functions as a single weighted cost function.
- Parameters:
costs (pybop.BaseCost) – The individual PyBOP cost objects.
weights (list[float]) – A list of values with which to weight the cost values.
- 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]]