scipy最优化

scipy最优化

学习scipy进行优化函数:

参考:Optimization and root finding (scipy.optimize) — SciPy v1.9.3 Manual

scipy最优化的功能:

1、SciPy优化提供了最小化(或最大化)目标函数的函数,可以是有约束的;

2、非线性问题的求解器(支持局部和全局优化算法);

3、线性规划;

4、约束最小二乘和非线性最小二乘;

5、寻根;

6、曲线拟合;

标量函数优化

minimize_scalar(fun[, bracket, bounds, …])Minimization of scalar function of one variable.一元标量函数的最小化。

The minimize_scalar function supports the following methods:

局部多变量优化

minimize(fun, x0[, args, method, jac, hess, …])Minimization of scalar function of one or more variables.一个或多个变量的标量函数的最小化

The minimize function supports the following methods:

Constraints are passed to minimize function as a single object or as a list of objects from the following classes:

NonlinearConstraint(fun, lb, ub[, jac, …])Nonlinear constraint on the variables.
LinearConstraint(A[, lb, ub, keep_feasible])Linear constraint on the variables.

Simple bound constraints are handled separately and there is a special class for them:(有一个特殊的类是单独处理简单约束的)

Bounds[lb, ub, keep_feasible]Bounds constraint on the variables.变量的边界约束。

Quasi-Newton strategies implementing HessianUpdateStrategy interface can be used to approximate the Hessian in minimize function (available only for the ‘trust-constr’ method). Available quasi-Newton methods implementing this interface are:(实现HessianUpdateStrategy接口的拟牛顿策略可以用来近似Hessian的最小化函数(仅适用于“信任-constr”方法)。实现此接口的可用拟牛顿方法包括:)

BFGS([exception_strategy, min_curvature, …])Broyden-Fletcher-Goldfarb-Shanno (BFGS) Hessian update strategy.
SR1([min_denominator, init_scale])Symmetric-rank-1 Hessian update strategy.对称秩1的Hessian更新策略。

全局优化

basinhopping(func, x0[, niter, T, stepsize, …])Find the global minimum of a function using the basin-hopping algorithm.使用盆跳跃算法求函数的全局最小值。
brute(func, ranges[, args, Ns, full_output, …])Minimize a function over a given range by brute force.在给定范围内用蛮力最小化函数
differential_evolution(func, bounds[, args, …])Finds the global minimum of a multivariate function.求多元函数的全局最小值。
shgo(func, bounds[, args, constraints, n, …])Finds the global minimum of a function using SHG optimization.使用SHG优化查找函数的全局最小值。
dual_annealing(func, bounds[, args, …])Find the global minimum of a function using Dual Annealing.使用对偶退火求函数的全局最小值。
direct(func, bounds, *[, args, eps, maxfun, …])Finds the global minimum of a function using the DIRECT algorithm.使用DIRECT算法查找函数的全局最小值。

最小二乘法和曲线拟合

Nonlinear least-squares

least_squares(fun, x0[, jac, bounds, …])Solve a nonlinear least-squares problem with bounds on the variables.

Linear least-squares

nnls(A, b[, maxiter])Solve argmin_x L2(Ax - b ) for x>=0.
lsq_linear(A, b[, bounds, method, tol, …])Solve a linear least-squares problem with bounds on the variables.解一个变量有界的线性最小二乘问题

Curve fitting

curve_fit(f, xdata, ydata[, p0, sigma, …])Use non-linear least squares to fit a function, f, to data.使用非线性最小二乘法将函数f拟合到数据

寻根

标量的
root_scalar(f[, args, method, bracket, …])Find a root of a scalar function.
brentq(f, a, b[, args, xtol, rtol, maxiter, …])Find a root of a function in a bracketing interval using Brent’s method.(用Brent方法求一个区间内的函数的根。)
brenth(f, a, b[, args, xtol, rtol, maxiter, …])Find a root of a function in a bracketing interval using Brent’s method with hyperbolic extrapolation.(用Brent的双曲外推法求括号区间内函数的根)
ridder(f, a, b[, args, xtol, rtol, maxiter, …])Find a root of a function in an interval using Ridder’s method.(用Ridder的方法求一个函数在一个区间内的根)
bisect(f, a, b[, args, xtol, rtol, maxiter, …])Find root of a function within an interval using bisection.(用二等分法求一个区间内函数的根)
newton(func, x0[, fprime, args, tol, …])Find a zero of a real or complex function using the Newton-Raphson (or secant or Halley’s) method.(使用Newton-Raphson(或割线法或Halley法)求实函数或复函数的零点。)
toms748(f, a, b[, args, k, xtol, rtol, …])Find a zero using TOMS Algorithm 748 method.(使用TOMS算法748方法求一个零)
RootResults(root, iterations, …)Represents the root finding result.(结果)

The root_scalar function supports the following methods:

The table below lists situations and appropriate methods, along with asymptotic convergence rates per iteration (and per function evaluation) for successful convergence to a simple root(*). Bisection is the slowest of them all, adding one bit of accuracy for each function evaluation, but is guaranteed to converge. The other bracketing methods all (eventually) increase the number of accurate bits by about 50% for every function evaluation. The derivative-based methods, all built on newton, can converge quite quickly if the initial value is close to the root. They can also be applied to functions defined on (a subset of) the complex plane.(下表列出了成功收敛到一个简单的根的情况和适当的方法,以及每次迭代(和每个函数的评价)的渐近收敛速度(*). 二分法是其中最慢的一种,它为每个函数求值增加了一位精度,但保证了收敛。其他的括号法都(最终)增加了精确位数的50%左右,为每一个函数的计算。基于导数的方法,都是建立在牛顿的基础上,如果初始值接近于根,可以收敛得相当快。它们也可以应用于定义在复平面上的函数。)

在这里插入图片描述

See also

scipy.optimize.cython_optimize – Typed Cython versions of zeros functions

Fixed point finding:

fixed_point(func, x0[, args, xtol, maxiter, …])Find a fixed point of the function.
多维的
root(fun, x0[, args, method, jac, tol, …])Find a root of a vector function.

The root function supports the following methods:

线性问题

milp(c, *[, integrality, bounds, …])Mixed-integer linear programming混合整数线性规划
linprog(c[, A_ub, b_ub, A_eq, b_eq, bounds, …])Linear programming: minimize a linear objective function subject to linear equality and inequality constraints.(线性规划:在线性等式和不等式约束下使线性目标函数最小化。)

The linprog function supports the following methods:

The simplex, interior-point, and revised simplex methods support callback functions, such as:(单纯形、内点和修正单纯形方法支持回调函数,例如:)

linprog_verbose_callback(res)A sample callback function demonstrating the linprog callback interface.一个示例回调函数,演示了linprog回调接口

分配问题

linear_sum_assignmentSolve the linear sum assignment problem.
quadratic_assignment(A, B[, method, options])Approximates solution to the quadratic assignment problem and the graph matching problem.(给出了二次分配问题和图匹配问题的近似解。)

The quadratic_assignment function supports the following methods:

工具函数

Finite-difference approximation有限差分近似

approx_fprime(xk, f[, epsilon])Finite difference approximation of the derivatives of a scalar or vector-valued function.
check_grad(func, grad, x0, *args[, epsilon, …])Check the correctness of a gradient function by comparing it against a (forward) finite-difference approximation of the gradient.通过将梯度函数与梯度的(前向)有限差分近似进行比较,检查梯度函数的正确性。

Line search 线性搜索

bracket(func[, xa, xb, args, grow_limit, …])Bracket the minimum of the function.
line_search(f, myfprime, xk, pk[, gfk, …])Find alpha that satisfies strong Wolfe conditions.找到满足强Wolfe条件的alpha。

Hessian approximation海森近似

LbfgsInvHessProduct(*args, kwargs)Linear operator for the L-BFGS approximate inverse Hessian.
HessianUpdateStrategy()Interface for implementing Hessian update strategies.用于实现Hessian更新策略的接口。

Benchmark problems 基准测试问题

rosen(x)The Rosenbrock function.罗森布洛克函数。
rosen_der(x)The derivative (i.e.衍生工具
rosen_hess(x)The Hessian matrix of the Rosenbrock function.罗森布洛克函数的海森矩阵
rosen_hess_prod(x, p)Product of the Hessian matrix of the Rosenbrock function with a vector.Rosenbrock函数与向量的Hessian矩阵的乘积。

遗留函数(准备废弃,就不学习了!!)

The functions below are not recommended for use in new scripts; all of these methods are accessible via a newer, more consistent interfaces, provided by the interfaces above.(下面的函数不建议在新脚本中使用;所有这些方法都可以通过上面的接口提供的更新、更一致的接口访问。)

Optimization

General-purpose multivariate methods:

fmin(func, x0[, args, xtol, ftol, maxiter, …])Minimize a function using the downhill simplex algorithm.
fmin_powell(func, x0[, args, xtol, ftol, …])Minimize a function using modified Powell’s method.
fmin_cg(f, x0[, fprime, args, gtol, norm, …])Minimize a function using a nonlinear conjugate gradient algorithm.
fmin_bfgs(f, x0[, fprime, args, gtol, norm, …])Minimize a function using the BFGS algorithm.
fmin_ncg(f, x0, fprime[, fhess_p, fhess, …])Unconstrained minimization of a function using the Newton-CG method.

Constrained multivariate methods:

fmin_l_bfgs_b(func, x0[, fprime, args, …])Minimize a function func using the L-BFGS-B algorithm.
fmin_tnc(func, x0[, fprime, args, …])Minimize a function with variables subject to bounds, using gradient information in a truncated Newton algorithm.
fmin_cobyla(func, x0, cons[, args, …])Minimize a function using the Constrained Optimization By Linear Approximation (COBYLA) method.
fmin_slsqp(func, x0[, eqcons, f_eqcons, …])Minimize a function using Sequential Least Squares Programming

Univariate (scalar) minimization methods:

fminbound(func, x1, x2[, args, xtol, …])Bounded minimization for scalar functions.
brent(func[, args, brack, tol, full_output, …])Given a function of one variable and a possible bracket, return the local minimum of the function isolated to a fractional precision of tol.
golden(func[, args, brack, tol, …])Return the minimum of a function of one variable using golden section method.

Least-squares

leastsq(func, x0[, args, Dfun, full_output, …])Minimize the sum of squares of a set of equations.

Root finding

General nonlinear solvers:

fsolve(func, x0[, args, fprime, …])Find the roots of a function.
broyden1(F, xin[, iter, alpha, …])Find a root of a function, using Broyden’s first Jacobian approximation.
broyden2(F, xin[, iter, alpha, …])Find a root of a function, using Broyden’s second Jacobian approximation.

Large-scale nonlinear solvers:

newton_krylov(F, xin[, iter, rdiff, method, …])Find a root of a function, using Krylov approximation for inverse Jacobian.
anderson(F, xin[, iter, alpha, w0, M, …])Find a root of a function, using (extended) Anderson mixing.

Simple iteration solvers:

excitingmixing(F, xin[, iter, alpha, …])Find a root of a function, using a tuned diagonal Jacobian approximation.
linearmixing(F, xin[, iter, alpha, verbose, …])Find a root of a function, using a scalar Jacobian approximation.
diagbroyden(F, xin[, iter, alpha, verbose, …])Find a root of a function, using diagonal Broyden Jacobian approximation.
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KPer_Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值