Constrained model tuning
Find parameters that minimize a scalar objective with bounds or constraints.
SciPy · Module
scipy.optimize provides numerical routines for minimization, global optimization, least-squares fitting, curve fitting, and root solving. It includes methods for scalar, multivariate, constrained, unconstrained, and equation-system problems.
The module groups numerical routines for choosing minima or solving equations. For multivariate scalar minimization, pass an objective function and initial point to minimize; select other routines when the problem is global, least-squares, scalar, or an equation-system task.
import scipy.optimize| Name | Type | Description |
|---|---|---|
fun | callable | Objective function that maps the candidate variable vector to a scalar value. |
x0 | array_like | Initial guess for the variables. |
Optimization routines return method-specific result objects or values; the cited overview page does not define a single module-wide return type.
minimize handles both constrained and unconstrained scalar objectives with multiple variables.basinhopping, differential_evolution, shgo, and dual_annealing.root addresses systems of equations and offers several solver families.import numpy as np
from scipy.optimize import minimize
result = minimize(lambda x: (x[0] - 3)**2, x0=np.array([0.0]))
print(result.x, result.fun)Minimizes a one-variable quadratic from an initial guess and prints the solution and objective value.
Find parameters that minimize a scalar objective with bounds or constraints.
Fit parameters by minimizing residual errors.
Locate zeros of a scalar function or solve an equation system.
Search for optima when local methods may be insufficient.
scipy.optimize cover?scipy.optimize provides routines for several numerical problem types, including constrained and unconstrained multivariate minimization, global optimization, least-squares fitting, scalar minimization and root finding, and multivariate equation solving.
Follow-up: Which routine fits nonlinear residual fitting? least_squares; for parametric curve fitting, the documentation also identifies curve_fit.
minimize?Use minimize for unconstrained or constrained minimization of a multivariate scalar function. It supports multiple algorithms, so the method can be selected according to the problem.
Follow-up: What if the objective is one-dimensional? Use minimize_scalar rather than treating it as a multivariate minimization problem.
Use root to solve multivariate systems of equations. The documented algorithm families include hybrid Powell, Levenberg–Marquardt, and large-scale Newton–Krylov approaches.
Follow-up: What is the scalar counterpart? Use root_scalar for univariate root finding.
minimizebasinhoppingdifferential_evolutionshgodual_annealingleast_squarescurve_fitminimize_scalar