Skip to content

Commit 0cc1144

Browse files
arnavk23tmigot
andauthored
Documentation for nonlinear least squares (NLS) problems (#411)
* Clarify documentation for nonlinear least squares (NLS) problems: classification, implementation, and usage for contributors and users. * addressing review comments * Apply suggestions from code review Co-authored-by: Tangi Migot <tangi.migot@gmail.com> * Remove NLS guidelines from contributing.md Removed guidelines for Nonlinear Least Squares (NLS) problems from the contributing documentation. * addressing review comments --------- Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
1 parent 101e896 commit 0cc1144

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

docs/src/meta.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ OptimizationProblems.AMPGO02_meta
1717
```
1818
See `? OptimizationProblems.meta` for more documentation on the various entries and their default values.
1919

20-
This structre is completed by getters to access the number of variables, `get_nameoftheproblem_nvar`,the number of constraints, `get_nameoftheproblem_ncon`, the number of linear constraints, `get_nameoftheproblem_nlin`, the number of nonlinear constraints, `get_nameoftheproblem_nnln`, the number of equality constraints, `get_nameoftheproblem_nequ`, and the number of inequality constraints, `get_nameoftheproblem_nineq`.
20+
This structure is completed by getters to access the number of variables, `get_nameoftheproblem_nvar`, the number of constraints, `get_nameoftheproblem_ncon`, the number of linear constraints, `get_nameoftheproblem_nlin`, the number of nonlinear constraints, `get_nameoftheproblem_nnln`, the number of equality constraints, `get_nameoftheproblem_nequ`, and the number of inequality constraints, `get_nameoftheproblem_nineq`.
2121
```@example 1
2222
OptimizationProblems.get_AMPGO02_nvar()
2323
```
@@ -50,3 +50,13 @@ adproblems = (
5050
eval(Meta.parse("ADNLPProblems.$(pb[:name])()")) for pb in eachrow(names_pb_vars)
5151
)
5252
```
53+
54+
### Nonlinear Least Squares Problems (NLS)
55+
Problems with `:objtype` set to `:least_squares` are nonlinear least squares problems (NLS). For these, you can access the number of NLS equations using a getter like `get_nameoftheproblem_nls_nequ()`.
56+
```@example 1
57+
OptimizationProblems.get_lanczos1_nls_nequ()
58+
```
59+
To filter all NLS problems in the metadata DataFrame:
60+
```@example 1
61+
nls_problems = OptimizationProblems.meta[OptimizationProblems.meta.objtype .== :least_squares, :name]
62+
```

docs/src/tutorial.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using OptimizationProblems, OptimizationProblems.ADNLPProblems
4747
problems = OptimizationProblems.meta[!, :name]
4848
length(problems)
4949
```
50-
Similarly, to the PureJuMP models, it suffices to select any of this problem to get the model.
50+
Similarly, to the PureJuMP models, it suffices to select any of these problems to get the model.
5151
``` @example ex2
5252
nlp = zangwil3()
5353
```
@@ -62,8 +62,31 @@ One of the advantages of these problems is that they are type-stable. Indeed, on
6262
``` @example ex2
6363
nlp16_12 = woods(n=12, type=Float16)
6464
```
65-
Then, all the API will be compatible with the precised type.
65+
Then, all the API will be compatible with the specified type.
6666
``` @example ex2
6767
using NLPModels
6868
obj(nlp16_12, zeros(Float16, 12))
6969
```
70+
71+
### Nonlinear Least Squares Problems (NLS)
72+
73+
Some problems are classified as nonlinear least squares (NLS). These problems may provide both an `ADNLPModel` and an `ADNLSModel` implementation, and dispatch to one or the other using the `use_nls` keyword argument, see [`arglina`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl) for a concrete example of this pattern.
74+
75+
Using `ADNLSModel` can be preferable when a solver exploits the least-squares structure directly (residual vector and Jacobian), which is often more efficient and numerically robust than treating the same problem as a generic nonlinear program (`ADNLPModel`).
76+
77+
To obtain the least squares model (`ADNLSModel`), use the `use_nls=true` keyword argument when constructing the problem:
78+
``` @example ex2
79+
lanczos1_nlp = lanczos1()
80+
lanczos1_nls = lanczos1(use_nls=true)
81+
typeof(lanczos1_nlp)
82+
typeof(lanczos1_nls)
83+
```
84+
85+
To list all NLS problems:
86+
``` @example ex2
87+
nls_problems = OptimizationProblems.meta[OptimizationProblems.meta.objtype .== :least_squares, :name]
88+
```
89+
To access the number of NLS equations for a problem:
90+
``` @example ex2
91+
OptimizationProblems.get_lanczos1_nls_nequ()
92+
```

0 commit comments

Comments
 (0)