pybop.optimisers.base_optimiser#

Classes#

BaseOptimiser

A base class for defining optimisation methods. Optimisers perform minimisation of the cost

OptimisationLog

Stores optimisation progress data.

Module Contents#

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

Bases: pybop.CostInterface

A base class for defining optimisation methods. Optimisers perform minimisation of the cost function; maximisation may be performed instead using the option invert_cost=True.

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 callable) – An objective function to be optimised, which can be either a pybop.Cost or callable function.

  • **optimiser_kwargs (optional) –

    Valid option keys and their values, for example: x0 : numpy.ndarray

    Initial values of the parameters for the optimisation.

    boundsdict

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

    sigma0float or sequence

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

    verbosebool, optional

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

    verbose_print_rateint, optional

    The frequency in iterations to print the optimisation progress (default: 50).

    physical_viabilitybool, optional

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

    allow_infeasible_solutionsbool, optional

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

log[source]#

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

Type:

dict

_parameter_sensitivities()[source]#
_print_verbose_output()[source]#

Print verbose optimization information if enabled.

abstractmethod _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.

abstractmethod _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.

_to_list(array_like)[source]#

Convert input to a list.

_update_log_entry(key, value)[source]#

Update a log entry if the value is provided.

log_update(iterations=None, evaluations=None, x=None, x_best=None, cost=None, cost_best=None, x0=None)[source]#

Update the log with new values.

Parameters:
  • iterations (list or array-like, optional) – Iteration indices to log (default: None).

  • evaluations (list or array-like, optional) – Evaluation indices to log (default: None).

  • x (list or array-like, optional) – Parameter values (default: None).

  • x_best (list or array-like, optional) – Parameter values corresponding to the best cost yet (default: None).

  • cost (list, optional) – Cost values corresponding to x (default: None).

  • cost_best (list, optional) – Cost values corresponding to x_best (default: None).

  • x0 (list or array-like, optional) – Initial parameter values (default: None).

abstractmethod name()[source]#

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

Returns:

The name of the optimiser

Return type:

str

run()[source]#

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

Returns:

results – The pybop optimisation result class.

Return type:

OptimisationResult

set_allow_infeasible_solutions(allow: bool = 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.

_iter_count = 0[source]#
_needs_sensitivities = False[source]#
allow_infeasible_solutions = False[source]#
bounds = None[source]#
default_max_iterations = 1000[source]#
log[source]#
property needs_sensitivities[source]#
parameters[source]#
physical_viability = False[source]#
result = None[source]#
sigma0 = 0.02[source]#
unset_options[source]#
unset_options_store[source]#
verbose = False[source]#
verbose_print_rate = 50[source]#
x0[source]#
class pybop.optimisers.base_optimiser.OptimisationLog[source]#

Stores optimisation progress data.

cost: list[float] = [][source]#
cost_best: list[float] = [][source]#
evaluations: list[int] = [][source]#
iterations: list[int] = [][source]#
x: list[list[float]] = [][source]#
x0: list[list[float]] = [][source]#
x_best: list[list[float]] = [][source]#