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.
- 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]]