pybop.optimisers._cost_interface#

Classes#

CostInterface

A base class for the optimisers and samplers that provides a common interface between

Module Contents#

class pybop.optimisers._cost_interface.CostInterface(transformation: pybop.Transformation | None = None, invert_cost: bool = False)[source]#

A base class for the optimisers and samplers that provides a common interface between the optimiser/sampler and the cost evaluation.

_inverts_cost(cost)[source]#

Returns the true cost if the optimiser is operating in the inverted space else returns the cost as is.

call_cost(x: pybop.Inputs | list, cost: pybop.BaseCost | callable, calculate_grad: bool = False) float | tuple[float, numpy.ndarray][source]#

Provides the interface between the cost and the optimiser.

Applies any transformation to the input parameter values, calls the cost function, inverts the sign of the cost and gradient if the target is maximisation and reverses the effect of any transformation on the gradient.

Parameters:
  • x (Inputs or list-like) – The input parameters for which the cost and optionally the gradient will be computed.

  • cost (pybop.BaseCost or callable) – The objective to be optimised, which can be either a pybop.Cost or callable function.

  • calculate_grad (bool, optional, default=False) – If True, both cost and gradient will be computed. Otherwise, only the cost is computed.

Returns:

  • If calculate_grad is False, returns the computed cost (float).

  • If calculate_grad is True, returns a tuple containing the cost (float) and the gradient (np.ndarray).

Return type:

float or tuple

transform_list_of_values(list_of_values)[source]#

Apply transformation if it exists.

transform_values(values)[source]#

Apply transformation if it exists.

invert_cost = False[source]#
property transformation[source]#