Expand description
Optimisation: one-dimensional, gradient-based, derivative-free, least-squares, constrained, linear, dynamic and stochastic methods.
See the book chapter Optimisation.
Modules§
- assignment
- The linear sum assignment problem (SciPy’s
linear_sum_assignment): match rows to columns of a cost matrix, one-to-one, to minimise (or maximise) the total cost, by the shortest augmenting path algorithm of Jonker and Volgenant as described by Crouse (2016). - bounded
- Optimisation with simple bounds
l ≤ x ≤ u, followingscipy.optimize: - brute
- Brute-force minimisation over a grid (SciPy’s
optimize.brute). - cobyla
- COBYLA: constrained optimisation by linear approximations (Powell, 1994; SciPy’s
minimize(method='COBYLA')), a derivative-free method for problems with nonlinear inequality constraints. - cobyqa
- COBYQA: constrained optimisation by quadratic approximations (Ragonneau, 2022; SciPy’s
minimize(method='COBYQA')), a derivative-free trust-region method for problems with bounds and nonlinear inequality and equality constraints. - conjugate_
gradient - Nonlinear conjugate gradient minimization.
- constrained
- Nonlinearly constrained minimization:
min f(x)subject toh(x) = 0(equalities) andg(x) ≤ 0(inequalities). - differential_
evolution - Differential evolution (Storn and Price), a population-based global minimizer.
- dynamic_
programming - Dynamic programming: classic optimisation problems solved by tabulation, and solvers for Markov decision processes.
- finite_
differences - Forward-difference gradients and gradient checking (SciPy’s
optimize.approx_fprimeandoptimize.check_grad). - global
- Global optimisation of functions with many local minima, following
scipy.optimize: basin hopping (basinhopping), generalised simulated annealing with local search (dual_annealing), and the deterministic DIRECT algorithm (direct, the locally biased DIRECT-L variant that is SciPy’s default). - golden_
section_ search - Golden section search for the minimum of a unimodal function of one variable.
- gradient_
descent - This file contains the implementation of the gradient descent algorithm for optimization.
Gradient descent is an iterative optimization algorithm used to find the minimum of a function.
The algorithm works by taking steps proportional to the negative of the gradient of the function at the current point. The size of the steps is determined by a learning rate, which is a hyperparameter that controls how quickly the algorithm converges to the minimum.
It stops when the objective changes by less than the tolerance (default 1e-5) in one step, or
after
max_iterations(default 1000). That test does not measure the gradient: with a small learning rate the objective changes little per step even far from a minimum, so check the result. Too large a learning rate (above2/Lfor anL-smooth function) diverges. With bounds, each step is projected onto the box (projected gradient descent). - isotonic
- Isotonic regression by the pool-adjacent-violators algorithm (SciPy’s
optimize.isotonic_regression). - least_
squares - Nonlinear least squares by the Levenberg-Marquardt method, and curve fitting built on it.
- line_
search - Line searches for gradient-based minimizers.
- linear_
programming - Linear programming by the two-phase simplex method.
- milp
- Mixed-integer linear programming by branch and bound (SciPy’s
optimize.milp, which uses HiGHS): aLinearProgramin which some variables must take integer values. - nelder_
mead_ method - This file implements the Nelder-Mead method for optimization. The Nelder-Mead method is a gradient-free optimization algorithm that is used to find the minimum of a function. The algorithm works by maintaining a simplex of n+1 points in n-dimensional space, where each point represents a candidate solution to the optimization problem. The algorithm iteratively updates the simplex by performing operations such as reflection, expansion, contraction, and shrinkage, based on the function values at the vertices of the simplex. The algorithm continues until it reaches a point where the function values at the vertices of the simplex are sufficiently close to each other, indicating that it has found a local minimum. The Nelder-Mead method can be effective for optimizing non-convex functions and functions with noisy gradients, but it can also be computationally expensive and may require careful tuning of the algorithm’s parameters to achieve good performance.
- newton_
raphson_ method - Newton’s method for minimization: each step solves
∇²f(x) p = −∇f(x)and moves tox + p(projected onto the bounds, if any). It converges quadratically near a minimum with a positive definite Hessian, but it is the pure method, with no line search or trust region: from a poor start, or where the Hessian is indefinite, it can move uphill or towards a saddle point. For robust minimization preferBfgs. - optimization_
traits - Here are traits that are used in optimization algorithms. They are defined here to avoid circular dependencies between the optimization algorithms and the traits they use.
- particle_
swarm - Particle swarm optimization (Kennedy and Eberhart, with Clerc’s constriction coefficients).
- powells_
method - Powell’s method: derivative-free minimisation by successive line searches along a set of conjugate directions.
- qap
- The quadratic assignment problem (SciPy’s
quadratic_assignment): find the permutationpminimisingΣᵢⱼ A[i][j] B[p(i)][p(j)], by Vogelstein et al.’s Fast Approximate QAP or by 2-opt local search. - quasi_
newton - Quasi-Newton minimizers: BFGS with a dense inverse-Hessian approximation and limited-memory
L-BFGS. Both use a strong Wolfe line search, which keeps the curvature condition
yᵀs > 0and hence the approximation positive definite. - shgo
- Simplicial homology global optimisation (Endres, Sandrock and Focke, 2018; SciPy’s
shgowithsampling_method='simplicial'(the default) or'sobol'). - simulated_
annealing - This file implements simulated annealing for optimization. Simulated annealing is a probabilistic optimization algorithm that is inspired by the process of annealing in metallurgy, where a material is heated and then slowly cooled to allow it to reach a state of minimum energy. In optimization, simulated annealing is used to find the minimum of an objective function by allowing for occasional uphill moves, which can help the algorithm escape local minima and explore the search space more effectively. The algorithm works by starting with an initial solution and then iteratively generating new candidate solutions by making small random changes to the current solution. The new solution is accepted with a probability that depends on the difference in objective function values between the current and new solutions, as well as a temperature parameter that controls the likelihood of accepting worse solutions. As the algorithm progresses, the temperature is gradually decreased, which reduces the probability of accepting worse solutions and allows the algorithm to converge to a minimum.
- slsqp
- SLSQP: sequential least-squares quadratic programming (Kraft, 1988; SciPy’s
minimize(method='SLSQP')) for smooth problems with bounds and nonlinear equality and inequality constraints. - tnc
- Bound-constrained minimisation by a truncated Newton method (the method of SciPy’s
minimize(method="TNC"), Nash’s truncated Newton with bounds). - trust_
constr trust-constr: a trust-region interior-point method for nonlinearly constrained problems (Byrd, Hribar and Nocedal, 1999; SciPy’sminimize(method='trust-constr')).- trust_
region - Trust-region Newton methods, ported from SciPy’s
minimize:trust-ncg(the Steihaug conjugate-gradient subproblem, needing only Hessian-vector products),dogleg(for positive definite Hessians) andtrust-exact(Moré and Sorensen’s nearly exact subproblem solution).