Native R ports of the optimizers of SciPy 1.18.1 (scipy.optimize), with
the interface of OptimizationSciPy.jl: pass them to solve() with an
OptimizationProblem().
Usage
ScipyMinimize(method = "BFGS")
ScipyNelderMead()
ScipyPowell()
ScipyCG()
ScipyBFGS()
ScipyNewtonCG()
ScipyLBFGSB()
ScipyTNC()
ScipyCOBYLA()
ScipyCOBYQA()
ScipySLSQP()
ScipyTrustConstr()
ScipyDogleg()
ScipyTrustNCG()
ScipyTrustKrylov()
ScipyTrustExact()
ScipyMinimizeScalar(method = "brent")
ScipyBrent()
ScipyBounded()
ScipyGolden()
ScipyLeastSquares(method = "trf", loss = "linear")
ScipyLeastSquaresTRF()
ScipyLeastSquaresDogbox()
ScipyLeastSquaresLM()
ScipyRootScalar(method = "brentq")
ScipyRoot(method = "hybr")
ScipyLinprog(method = "highs")
ScipyMilp()
ScipyDifferentialEvolution()
ScipyBasinhopping()
ScipyDualAnnealing()
ScipyShgo()
ScipyDirect()
ScipyBrute()Details
ScipyMinimize(method)runsscipy.optimize.minimizewith one of the methods"Nelder-Mead","Powell","CG","BFGS"(the default),"Newton-CG","L-BFGS-B","TNC","COBYLA","COBYQA","SLSQP","trust-constr","dogleg","trust-ncg","trust-krylov"and"trust-exact";ScipyNelderMead()...ScipyTrustExact()are shorthands. Bounds are used by Nelder-Mead, Powell, L-BFGS-B, TNC, COBYLA, COBYQA, SLSQP and trust-constr, constraints by SLSQP, trust-constr, COBYLA and COBYQA. Without a gradient function, the gradient based methods use the forward differences of SciPy.ScipyMinimizeScalar(method)minimizes a function of one variable by"brent"(the default;ScipyBrent()),"bounded"(ScipyBounded(), on the interval of the bounds) or"golden"(ScipyGolden()).ScipyLeastSquares(method, loss)minimizes the sum of squares of the vector returned by the objective, by"trf"(ScipyLeastSquaresTRF()),"dogbox"(ScipyLeastSquaresDogbox()) or"lm"(ScipyLeastSquaresLM(), MINPACK's Levenberg Marquardt), with a robustloss("linear","soft_l1","huber","cauchy","arctan"). The solution's objective is the cost0.5 * sum(rho(r^2)).ScipyRootScalar(method)finds a zero of a function of one variable: the bracketing methods"brentq","brenth","bisect","ridder"and"toms748"use the bounds as the bracket,"newton","secant"and"halley"start fromu0.ScipyRoot(method)finds a zero of the vector function returned by the objective:"hybr"(MINPACK's Powell hybrid method),"lm","broyden1","broyden2","anderson","linearmixing","diagbroyden","excitingmixing","krylov"and"df-sane".ScipyLinprog(method)solves the linear program whose cost vector is the value of the objective, with the optionsA_ub,b_ub,A_eq,b_eqgiven tosolve()and the bounds of the problem.ScipyMilp()solves a mixed integer linear program with the optionsintegrality,A,lb_conandub_con.ScipyDifferentialEvolution(),ScipyBasinhopping(),ScipyDualAnnealing(),ScipyShgo(),ScipyDirect()andScipyBrute()are the global optimizers of SciPy; all but basinhopping need finite bounds. The randomized ones take the optionseed(an integer forset.seed(); the caller's random state is restored).
SciPy solves linear and mixed integer programs with the HiGHS library;
here a native port of the HiGHS LP presolve and postsolve and of the
HiGHS simplex solver (dual simplex method with scaling, cost
perturbation, dual steepest edge pricing and the bound flipping ratio
test, primal simplex cleanup, the HFactor LU factorization with
Forrest-Tomlin updates) solves them, with
presolve = FALSE passed on as in SciPy; "highs-ipm" runs IPX with
crossover (run_crossover = "off" skips it) and the simplex clean up of
HiGHS, and ScipyMilp() runs the port of the HiGHS MIP solver
(presolve, cuts, heuristics, symmetry handling and branch and bound) with
the node_limit, mip_rel_gap, time_limit and presolve options of
SciPy. ScipyCOBYQA() solves its
interpolation systems with R's LAPACK (SciPy uses Accelerate or
OpenBLAS), so its points agree to rounding and a long run can take a
slightly different path to the same solution; it evaluates the nonlinear
constraints at the point of the user also when variables are fixed by the
bounds or scaled (scale = TRUE), where SciPy 1.18.1 passes them the
reduced point.
ScipyTrustConstr() factorizes its augmented systems with a dense LU
(SciPy uses SuperLU), so a last bit difference can change its path while
the solution agrees. ScipyShgo() samples with the simplicial method only
(the other methods triangulate with Qhull).
ScipyDirect() drops the rectangles off the convex hull, as SciPy's
DIRECT code does only with its log switched on.
Common options of solve(): maxiters, abstol and reltol, mapped to
the SciPy options as OptimizationSciPy.jl does; every other option is
passed to the SciPy function (for example xatol, maxfev, adaptive
for Nelder-Mead, popsize for differential evolution). The solution's
original is the SciPy result (x, fun, nit, nfev, status,
message, ...).
Examples
rosen <- function(u, p) (p[1] - u[1])^2 + p[2] * (u[2] - u[1] * u[1])^2
prob <- OptimizationProblem(rosen, c(-1, 2), c(1, 100))
solve(prob, ScipyNelderMead())$u
#> [1] 0.9999909 0.9999827
solve(prob, ScipyBFGS())$u
#> [1] 0.9999951 0.9999903