NLPModelsJuMP is a combination of NLPModels and JuMP, as the name implies. Sometimes it may be required to refer to the specific documentation, as we'll present here only the documention specific to NLPModelsJuMP.
MathOptNLPModel(model, hessian=true, name="Generic")
Construct a MathOptNLPModel
from a JuMP
model.
hessian
should be set to false
for multivariate user-defined functions registered without hessian.
sourceMathOptNLPModel
is a simple yet efficient model. It uses JuMP to define the problem, and can be accessed through the NLPModels API. An advantage of MathOptNLPModel
over simpler models such as ADNLPModels
is that they provide sparse derivates.
Let's define the famous Rosenbrock function
\[f(x) = (x_1 - 1)^2 + 100(x_2 - x_1^2)^2,\]
with starting point $x^0 = (-1.2,1.0)$.
using NLPModels, NLPModelsJuMP, JuMP
x0 = [-1.2; 1.0]
model = Model() # No solver is required
@@ -107,7 +107,7 @@
println("cx = $(cons(nlp, nlp.meta.x0))")
println("Jx = $(jac(nlp, nlp.meta.x0))")
cx = [-0.19999999999999996, -2.2]
-Jx = sparse([1, 2, 1, 2], [1, 1, 2, 2], [1.0, 1.0, 1.0, -1.2], 2, 2)
MathOptNLSModel(model, F, hessian=true, name="Generic")
Construct a MathOptNLSModel
from a JuMP
model and a container of JuMP GenericAffExpr
(generated by @expression) and NonlinearExpression
(generated by @NLexpression).
hessian
should be set to false
for multivariate user-defined functions registered without hessian.
sourceMathOptNLSModel
is a model for nonlinear least squares using JuMP, The objective function of NLS problems has the form $f(x) = \tfrac{1}{2}\|F(x)\|^2$, but specialized methods handle $F$ directly, instead of $f$. To use MathOptNLSModel
, we define a JuMP model without the objective, and use NLexpression
s to define the residual function $F$. For instance, the Rosenbrock function can be expressed in nonlinear least squares format by defining
\[F(x) = \begin{bmatrix} x_1 - 1\\ 10(x_2 - x_1^2) \end{bmatrix},\]
and noting that $f(x) = \|F(x)\|^2$ (the constant $\frac{1}{2}$ is ignored as it doesn't change the solution). We implement this function as
using NLPModels, NLPModelsJuMP, JuMP
+Jx = sparse([1, 2, 1, 2], [1, 1, 2, 2], [1.0, 1.0, 1.0, -1.2], 2, 2)
MathOptNLSModel(model, F, hessian=true, name="Generic")
Construct a MathOptNLSModel
from a JuMP
model and a container of JuMP GenericAffExpr
(generated by @expression) and NonlinearExpression
(generated by @NLexpression).
hessian
should be set to false
for multivariate user-defined functions registered without hessian.
sourceMathOptNLSModel
is a model for nonlinear least squares using JuMP, The objective function of NLS problems has the form $f(x) = \tfrac{1}{2}\|F(x)\|^2$, but specialized methods handle $F$ directly, instead of $f$. To use MathOptNLSModel
, we define a JuMP model without the objective, and use NLexpression
s to define the residual function $F$. For instance, the Rosenbrock function can be expressed in nonlinear least squares format by defining
\[F(x) = \begin{bmatrix} x_1 - 1\\ 10(x_2 - x_1^2) \end{bmatrix},\]
and noting that $f(x) = \|F(x)\|^2$ (the constant $\frac{1}{2}$ is ignored as it doesn't change the solution). We implement this function as
using NLPModels, NLPModelsJuMP, JuMP
model = Model()
x0 = [-1.2; 1.0]
@@ -121,4 +121,4 @@
-2.2
-4.3999999999999995
jac_residual(nls, nls.meta.x0)
2×2 SparseArrays.SparseMatrixCSC{Float64, Int64} with 3 stored entries:
1.0 ⋅
- 24.0 10.0
The package NLSProblems provides a collection of problems already defined as MathOptNLSModel
.