pybop.optimisers.scipy_optimisers#
Classes#
A base class for defining optimisation methods from the SciPy library. |
|
Adapts SciPy's differential_evolution function for global optimisation. |
|
Adapts SciPy's minimize function for use as an optimisation strategy. |
Module Contents#
- class pybop.optimisers.scipy_optimisers.BaseSciPyOptimiser(cost, **optimiser_kwargs)[source]#
Bases:
pybop.BaseOptimiserA base class for defining optimisation methods from the SciPy library.
- Parameters:
x0 (array_like) – Initial position from which optimisation will start.
bounds (dict, sequence or scipy.optimize.Bounds, optional) – Bounds for variables as supported by the selected method.
**optimiser_kwargs (optional) – Valid SciPy option keys and their values.
- class pybop.optimisers.scipy_optimisers.SciPyDifferentialEvolution(cost, **optimiser_kwargs)[source]#
Bases:
BaseSciPyOptimiserAdapts SciPy’s differential_evolution function for global optimisation.
This class provides a global optimisation strategy based on differential evolution, useful for problems involving continuous parameters and potentially multiple local minima.
- Parameters:
bounds (dict, sequence or scipy.optimize.Bounds) – Bounds for variables. Must be provided as it is essential for differential evolution. Each element is a tuple (min, max) for the corresponding variable.
**optimiser_kwargs (optional) –
Valid SciPy differential_evolution options: strategy : str, optional
The differential evolution strategy to use. Should be one of: - ‘best1bin’ - ‘best1exp’ - ‘rand1exp’ - ‘randtobest1exp’ - ‘currenttobest1exp’ - ‘best2exp’ - ‘rand2exp’ - ‘randtobest1bin’ - ‘currenttobest1bin’ - ‘best2bin’ - ‘rand2bin’ - ‘rand1bin’ Default is ‘best1bin’.
- maxiterint, optional
Maximum number of generations. Default is 1000.
- popsizeint, optional
Multiplier for setting the total population size. The population has popsize * len(x) individuals. Default is 15.
- tolfloat, optional
Relative tolerance for convergence. Default is 0.01.
- mutationfloat or tuple(float, float), optional
The mutation constant. If specified as a float, should be in [0, 2]. If specified as a tuple (min, max), dithering is used. Default is (0.5, 1.0).
- recombinationfloat, optional
The recombination constant, should be in [0, 1]. Default is 0.7.
- seedint, optional
Random seed for reproducibility.
- dispbool, optional
Display status messages. Default is False.
- callbackcallable, optional
Called after each iteration with the current result as argument.
- polishbool, optional
If True, performs a local optimisation on the solution. Default is True.
- initstr or array-like, optional
Specify initial population. Can be ‘latinhypercube’, ‘random’, or an array of shape (M, len(x)).
- atolfloat, optional
Absolute tolerance for convergence. Default is 0.
- updating{‘immediate’, ‘deferred’}, optional
If ‘immediate’, best solution vector is continuously updated within a single generation. Default is ‘immediate’.
- workersint or map-like callable, optional
If workers is an int the population is subdivided into workers sections and evaluated in parallel. Default is 1.
- constraints{NonlinearConstraint, LinearConstraint, Bounds}, optional
Constraints on the solver.
See also
scipy.optimize.differential_evolutionThe SciPy method this class is based on.
Notes
Differential Evolution is a stochastic population based method that is useful for global optimisation problems. At each pass through the population the algorithm mutates each candidate solution by mixing with other candidate solutions to create a trial candidate. The fitness of all candidates is then evaluated and for each candidate if the trial candidate is an improvement, it takes its place in the population for the next iteration.
- class pybop.optimisers.scipy_optimisers.SciPyMinimize(cost, **optimiser_kwargs)[source]#
Bases:
BaseSciPyOptimiserAdapts SciPy’s minimize function for use as an optimisation strategy.
This class provides an interface to various scalar minimisation algorithms implemented in SciPy, allowing fine-tuning of the optimisation process through method selection and option configuration.
- Parameters:
**optimiser_kwargs (optional) –
Valid SciPy Minimize option keys and their values: x0 : array_like
Initial position from which optimisation will start.
- methodstr
The optimisation method, options include: ‘Nelder-Mead’, ‘Powell’, ‘CG’, ‘BFGS’, ‘Newton-CG’, ‘L-BFGS-B’, ‘TNC’, ‘COBYLA’, ‘SLSQP’, ‘trust-constr’, ‘dogleg’, ‘trust-ncg’, ‘trust-exact’, ‘trust-krylov’.
- jac{callable, ‘2-point’, ‘3-point’, ‘cs’, bool}, optional
Method for computing the gradient vector.
- hess{callable, ‘2-point’, ‘3-point’, ‘cs’, HessianUpdateStrategy}, optional
Method for computing the Hessian matrix.
- hesspcallable, optional
Hessian of objective function times an arbitrary vector p.
- boundssequence or scipy.optimize.Bounds, optional
Bounds on variables for L-BFGS-B, TNC, SLSQP, trust-constr methods.
- constraints{Constraint, dict} or List of {Constraint, dict}, optional
Constraints definition for constrained optimisation.
- tolfloat, optional
Tolerance for termination.
- optionsdict, optional
Method-specific options. Common options include: maxiter : int
Maximum number of iterations.
- dispbool
Set to True to print convergence messages.
- ftolfloat
Function tolerance for termination.
- gtolfloat
Gradient tolerance for termination.
- epsfloat
Step size for finite difference approximation.
- maxfevint
Maximum number of function evaluations.
- maxcorint
Maximum number of variable metric corrections (L-BFGS-B).
See also
scipy.optimize.minimizeThe SciPy method this class is based on.
Notes
Different optimisation methods may support different options. Consult SciPy’s documentation for method-specific options and constraints.
- _run_optimiser()[source]#
Executes the optimisation process using SciPy’s minimize function.
- Returns:
result – The result of the optimisation including the optimised parameter values and cost.
- Return type:
scipy.optimize.OptimizeResult