pybop.costs._weighted_cost#

Classes#

WeightedCost

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

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

  • has_identical_problems (bool) – If True, the shared problem will be evaluated once and saved before the self.compute() method of each cost is called (default: False).

  • has_separable_problem (bool) – This attribute must be set to False for WeightedCost objects. If the corresponding attribute of an individual cost is True, the problem is separable from the cost function and will be evaluated before the individual cost evaluation is called.

compute(y: dict, dy: numpy.ndarray | None = None) float | tuple[float, numpy.ndarray][source]#

Computes the cost function for the given predictions.

Parameters:
  • y (dict) – The dictionary of predictions with keys designating the signals for fitting.

  • dy (np.ndarray, optional) – The corresponding gradient with respect to the parameters for each signal.

Returns:

The weighted cost value.

Return type:

float

_has_identical_problems[source]#
_has_separable_problem = False[source]#
costs[source]#
property has_identical_problems[source]#