我是只寫硬核科研推文的張運霄,
歡迎來到科研九宮格
scipy.optimize
優化問題可以有以下幾種:
最小化問題 minimize
曲線擬合問題 curve_fit
最小平方擬合問題 least_squares
求根 root
本文只列舉函數,和算法,比較重要的算法有Nelder-Mead 算法和Levenberg-Marquardt算法。具體用法參考連接。
https://docs.scipy.org/doc/scipy/reference/optimize.html
scipy.optimize.minimize
fmin: 只有 Nelder-Mead simplex algorithm,已經被minimize取代
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize
Minimization of scalar function of one or more variables.
method:
』Nelder-Mead』
』Powell』
』CG』
』BFGS』
』Newton-CG』
』L-BFGS-B』
』TNC』
』COBYLA』
』SLSQP』
’trust-constr』
』dogleg』
’trust-ncg』
’trust-krylov』
’trust-exact』
scipy.optimize.least_squares
leastsq: 只有 Levenberg-Marquardt algorithm,已經被least_squares替代
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html#scipy.optimize.least_squares
Solve a nonlinear least-squares problem with bounds on the variables.
Given the residuals f(x) (an m-D real function of n real variables) and the loss function rho(s) (a scalar function), least_squares finds a local minimum of the cost function F(x):
minimize F(x) = 0.5 * sum(rho(f_i(x)**2), i = 0, ..., m - 1)
subject to lb <= x <= ub
method:
『lm』
『trf』
『dogbox』
『trf』 : Trust Region Reflective algorithm, particularly suitable for large sparse problems with bounds. Generally robust method.
『dogbox』 : dogleg algorithm with rectangular trust regions, typical use case is small problems with bounds. Not recommended for problems with rank-deficient Jacobian.
『lm』 : Levenberg-Marquardt algorithm as implemented in MINPACK. Doesn’t handle bounds and sparse Jacobians. Usually the most efficient method for small unconstrained problems.
scipy.optimize.curve_fit
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html#scipy.optimize.curve_fit
method:
『lm』
『trf』
『dogbox』
Default is 『lm』 for unconstrained problems and 『trf』 if bounds are provided. The method 『lm』 won’t work when the number of observations is less than the number of variables, use 『trf』 or 『dogbox』 in this case.
scipy.optimize.root_scalar
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root_scalar.html#scipy.optimize.root_scalar
method:
『bisect』
『brentq』
『brenth』
『ridder』
『toms748』
『newton』
『secant』
『halley』
scipy.optimize.root
find a root of a vector function.
method:
『hybr』
『lm』
『broyden1』
『broyden2』
『anderson』
『linearmixing』
『diagbroyden』
『excitingmixing』
『krylov』
『df-sane』
往期推薦
看看歷史文章?都挺好的
長按關注科研九宮格,喜歡請點個"在看"~