pybop.optimisers.base_optimiser#

Classes#

BaseOptimiser

A base class for defining optimisation methods.

Result

Stores the result of the optimisation.

Module Contents#

class pybop.optimisers.base_optimiser.BaseOptimiser(cost, **optimiser_kwargs)[source]#

A base class for defining optimisation methods.

This class serves as a base class for creating optimisers. It provides a basic structure for an optimisation algorithm, including the initial setup and a method stub for performing the optimisation process. Child classes should override _set_up_optimiser and the _run method with a specific algorithm.

Parameters:
  • cost (pybop.BaseCost or pints.ErrorMeasure) – An objective function to be optimised, which can be either a pybop.Cost or PINTS error measure

  • **optimiser_kwargs (optional) – Valid option keys and their values.

x0#

Initial parameter values for the optimisation.

Type:

numpy.ndarray

bounds#

Dictionary containing the parameter bounds with keys ‘lower’ and ‘upper’.

Type:

dict

sigma0#

Initial step size or standard deviation around x0. Either a scalar value (one standard deviation for all coordinates) or an array with one entry per dimension. Not all methods will use this information.

Type:

float or sequence

verbose#

If True, the optimisation progress is printed (default: False).

Type:

bool, optional

minimising#

If True, the target is to minimise the cost, else target is to maximise by minimising the negative cost (default: True).

Type:

bool, optional

physical_viability#

If True, the feasibility of the optimised parameters is checked (default: True).

Type:

bool, optional

allow_infeasible_solutions#

If True, infeasible parameter values will be allowed in the optimisation (default: True).

Type:

bool, optional

log#

A log of the parameter values tried during the optimisation and associated costs.

Type:

dict

abstract _run()[source]#

Contains the logic for the optimisation algorithm.

This method should be implemented by child classes to perform the actual optimisation.

Raises:

NotImplementedError – If the method has not been implemented by the subclass.

abstract _set_up_optimiser()[source]#

Parse optimiser options and prepare the optimiser.

This method should be implemented by child classes.

Raises:

NotImplementedError – If the method has not been implemented by the subclass.

check_optimal_parameters(x)[source]#

Check if the optimised parameters are physically viable.

Parameters:

x (array-like) – Optimised parameter values.

name()[source]#

Returns the name of the optimiser, to be overwritten by child classes.

Returns:

The name of the optimiser, which is “Optimisation” for this base class.

Return type:

str

run()[source]#

Run the optimisation and return the optimised parameters and final cost.

Returns:

  • x (numpy.ndarray) – The best parameter set found by the optimisation.

  • final_cost (float) – The final cost associated with the best parameters.

set_allow_infeasible_solutions(allow=True)[source]#

Set whether to allow infeasible solutions or not.

Parameters:

iterations (bool, optional) – Whether to allow infeasible solutions.

set_base_options()[source]#

Update the base optimiser options and remove them from the options dictionary.

store_optimised_parameters(x)[source]#

Update the problem parameters with optimised values.

The optimised parameter values are stored within the associated PyBOP parameter class.

Parameters:

x (array-like) – Optimised parameter values.

class pybop.optimisers.base_optimiser.Result(x: numpy.ndarray = None, final_cost: float = None, n_iterations: int = None, scipy_result=None)[source]#

Stores the result of the optimisation.

x#

The solution of the optimisation.

Type:

ndarray

final_cost#

The cost associated with the solution x.

Type:

float

nit#

Number of iterations performed by the optimiser.

Type:

int

scipy_result#

The result obtained from a SciPy optimiser.

Type:

scipy.optimize.OptimizeResult, optional