From 5223e94717344fb8a0fd797f1d477d03f4941824 Mon Sep 17 00:00:00 2001 From: Tangi Migot Date: Fri, 4 Oct 2024 08:01:09 -0400 Subject: [PATCH] Add documentation for `isnls` in tuto (#182) * Add documentation for `isnls` in tuto --- docs/Project.toml | 1 + ...0-nls.md => 20-nonlinear-least-squares.md} | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) rename docs/src/{20-nls.md => 20-nonlinear-least-squares.md} (81%) diff --git a/docs/Project.toml b/docs/Project.toml index 29d9bbcb..b4aa29eb 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -3,6 +3,7 @@ ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" CaNNOLeS = "5a1c9e79-9c58-5ec0-afc4-3298fdea2875" DCISolver = "bee2e536-65f6-11e9-3844-e5bb4c9c55c9" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +ExpressionTreeForge = "93090adf-0e31-445f-8c8f-44d91f61d7ad" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" JSOSolvers = "10dff2fc-5484-5881-a0e0-c90441020f8a" JSOSuite = "ed6ae0be-a024-11e9-2788-05dbf8cd15d9" diff --git a/docs/src/20-nls.md b/docs/src/20-nonlinear-least-squares.md similarity index 81% rename from docs/src/20-nls.md rename to docs/src/20-nonlinear-least-squares.md index 2e492fa3..6fe23ba6 100644 --- a/docs/src/20-nls.md +++ b/docs/src/20-nonlinear-least-squares.md @@ -82,6 +82,40 @@ nls = MathOptNLSModel(model, [F1, F2], name="Ju-Rosenbrock") stats = minimize(nls) ``` +### JSOSuite automatic detection + +The package can be used to try detecting NLS-pattern in a model. + +```@example autodetection +using ADNLPModels, JSOSuite +f(x) = (x[2] - x[1]^3)^2 + (x[1] - 1)^2 +x0 = [-1.2; 1.0] +nlp = ADNLPModel(f, x0) +stats_nlp = minimize(nlp) +``` + +The function `isnls` requires the package [ExpressionTreeForge.jl](https://github.com/JuliaSmoothOptimizers/ExpressionTreeForge.jl). +In this example, it detects that the objective function is a nonlinear least squares. + +```@example autodetection +using ExpressionTreeForge +JSOSuite.isnls(nlp) +``` + +Therefore, defining an `ADNLSModel` might improve the solver's behavior. + +```@example autodetection +F(x) = [x[2] - x[1]^3, x[1] - 1] +x0 = [-1.2; 1.0] +nls = ADNLSModel(F, x0, 2) +stats_nls = minimize(nls) +``` + +```@example autodetection +using NLPModels +(neval_obj(nlp), neval_obj(nls)) +``` + ## Find a feasible point of an optimization problem or solve a nonlinear system We show here how to find the feasible point of a given model.