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.costs.base_cost.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.

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_target(target: list[list[str]] | list[str] | str | None = None)[source]#

Set the target variable for all costs. Expecting a list of list[str] the same length as self.costs.

_domain#
costs#
property target#