pybop.optimisers.base_optimiser#
Classes#
A base class for defining optimisation methods. Optimisers perform minimisation of the cost |
|
Stores optimisation progress data. |
Module Contents#
- class pybop.optimisers.base_optimiser.BaseOptimiser(cost, **optimiser_kwargs)[source]#
Bases:
pybop.CostInterfaceA 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
- 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.
- 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:
- 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.