pybop.optimisers.base_optimiser#
Classes#
A base class for defining optimisation methods. |
|
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.
- bounds[source]#
Dictionary containing the parameter bounds with keys ‘lower’ and ‘upper’.
- Type:
dict
- sigma0[source]#
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[source]#
If True, the optimisation progress is printed (default: False).
- Type:
bool, optional
- minimising[source]#
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[source]#
If True, the feasibility of the optimised parameters is checked (default: True).
- Type:
bool, optional
- allow_infeasible_solutions[source]#
If True, infeasible parameter values will be allowed in the optimisation (default: True).
- Type:
bool, optional
- log[source]#
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.
- log_update(x=None, x_best=None, cost=None)[source]#
Update the log with new values.
- Parameters:
x (list or array-like, optional) – Parameter values (default: None).
x_best (list or array-like, optional) – Paraneter values corresponding to the best cost yet (default: None).
cost (float, optional) – Cost value (default: None).
- 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.
- class pybop.optimisers.base_optimiser.Result(x: numpy.ndarray = None, final_cost: float | None = None, n_iterations: int | None = None, scipy_result=None)[source]#
Stores the result of the optimisation.
- nit#
Number of iterations performed by the optimiser.
- Type:
int