Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduction to JSOSolvers #44

Merged
merged 4 commits into from
Feb 2, 2023
Merged

Introduction to JSOSolvers #44

merged 4 commits into from
Feb 2, 2023

Conversation

tmigot
Copy link
Member

@tmigot tmigot commented Jan 27, 2023

#3

@geoffroyleconte
Copy link
Member

That's a detail but maybe you could provide links to the algorithms in the table? Otherwise LGTM.

@geoffroyleconte
Copy link
Member

I'd say to the docstring, but as you prefer.

Copy link
Member

@paraynaud paraynaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with .jmd files, does a julia environnement runs the code contain in it? like @example ?

tutorials/introduction-to-jsosolvers/index.jmd Outdated Show resolved Hide resolved
tutorials/introduction-to-jsosolvers/index.jmd Outdated Show resolved Hide resolved
tutorials/introduction-to-jsosolvers/index.jmd Outdated Show resolved Hide resolved
@abelsiqueira
Copy link
Member

@paraynaud, they should be executed. You can review the preview here: https://juliasmoothoptimizers.github.io/JSOTutorials.jl/introduction-to-jsosolvers/

Copy link
Member

@abelsiqueira abelsiqueira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tangi, thanks for another tutorial. I left some comments as well.

tutorials/introduction-to-jsosolvers/index.jmd Outdated Show resolved Hide resolved
tutorials/introduction-to-jsosolvers/index.jmd Outdated Show resolved Hide resolved

The solvers `tron` and `trunk` both have a specialized implementation for input models of type `AbstractNLSModel`.

The following example illustrate this specialization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better example would be a data-fitting NLS, so you can plot the solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @abelsiqueira for the review! I added a data-fitting example on top of the existing examples and using keywords.

tutorials/introduction-to-jsosolvers/index.jmd Outdated Show resolved Hide resolved
- `verbose::Int = 0`: if > 0, display iteration details every `verbose` iteration.

Refer to the documentation of each solver for further details on the available keyword arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an example for basic usage as well.

@github-actions
Copy link
Contributor

Once the build has completed, you can preview your PR at this URL: https://juliasmoothoptimizers.github.io/JSOTutorials.jl/

@github-actions
Copy link
Contributor

Once the build has completed, you can preview your PR at this URL: https://juliasmoothoptimizers.github.io/JSOTutorials.jl/

Copy link
Member

@abelsiqueira abelsiqueira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made more comments about the NLS problem. Instead of using some random data, I choose a more traditional NLS problem from https://www.itl.nist.gov/div898/strd/nls/nls_main.shtml
The text will need an update to match the new problem.


We build a nonlinear model `m` with unknown parameters α and β, and generate randomly some observations of this model.
```julia
m(α, β, x) = α * cos(x) + β * sin(x) # nonlinear models with unknown α and β
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is linear in alpha and beta, this is actually LLS.
Instead, we can use a classic NLS, like Thurber: https://www.itl.nist.gov/div898/strd/nls/data/LINKS/DATA/Thurber.dat

Suggested change
m(α, β, x) = α * cos(x) + β * sin(x) # nonlinear models with unknown α and β
m(β, x) = (β[1] + β[2] * x + β[3] * x^2 + β[4] * x^3) / (1 + β[5] * x + β[6] * x^2 + β[7] * x^3) # nonlinear models with unknown β vector

Comment on lines 74 to 76
ndata = 100 # size of data sample
data = [rand() * 2 - 1 for i=1:ndata]
obs = [m(0.5, 0.5, xi) for xi in data] + rand(ndata) / 10; # observations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the data: https://gist.github.com/abelsiqueira/8ca109888b22b6ab1e76825f0567c668

Suggested change
ndata = 100 # size of data sample
data = [rand() * 2 - 1 for i=1:ndata]
obs = [m(0.5, 0.5, xi) for xi in data] + rand(ndata) / 10; # observations
url_prefix = "https://gist.githubusercontent.com/abelsiqueira/8ca109888b22b6ab1e76825f0567c668/raw/f3f38d61f750b443fb4307efbf853447275441a5/"
data = CSV.read(download(joinpath(url_prefix, "thurber.csv")), DataFrame)
x, y = data.x, data.y

Comment on lines 81 to 85
```julia
F(w) = [m(w[1], w[2], xi) - yi for (xi, yi) in zip(data, obs)]
w0 = [0., 0.]
nls = ADNLSModel(F, w0, ndata)
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```julia
F(w) = [m(w[1], w[2], xi) - yi for (xi, yi) in zip(data, obs)]
w0 = [0., 0.]
nls = ADNLSModel(F, w0, ndata)
```
```julia
F(β) = [m(β, xi) - yi for (xi, yi) in zip(x, y)]
β0 = CSV.read(download(joinpath(url_prefix, "thurber-x0.csv")), DataFrame).beta
ndata = length(x)
nls = ADNLSModel(F, β, ndata)

Comment on lines 95 to 98
using Plots
scatter(data, obs, c=:blue, m=:square, title="Basic nonlinear regression", ylab="m(α, β, x)", xlab="x")
mtest = [m(stats.solution[1], stats.solution[2], xi) for xi=-1:0.01:1]
plot!(-1:0.01:1, mtest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using Plots
scatter(data, obs, c=:blue, m=:square, title="Basic nonlinear regression", ylab="m(α, β, x)", xlab="x")
mtest = [m(stats.solution[1], stats.solution[2], xi) for xi=-1:0.01:1]
plot!(-1:0.01:1, mtest)
using Plots
scatter(x, y, c=:blue, m=:square, title="Nonlinear regression", lab="data")
plot!(x, t -> m(stats.solution, t), c=:red, lw=2, lab="fit")

nls = ADNLSModel(F, w0, ndata)
```

As shown before, we can use any `JSOSolvers` solvers to solve this problem. For instance, we use `trunk` with a time limit of `60` seconds.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As shown before, we can use any `JSOSolvers` solvers to solve this problem. For instance, we use `trunk` with a time limit of `60` seconds.
As shown before, we can use any `JSOSolvers` solvers to solve this problem, but since `trunk` has a specialized version for unconstrained NLS, we will use it, with a time limit of `60` seconds.

@tmigot
Copy link
Member Author

tmigot commented Feb 1, 2023

Thanks @abelsiqueira for the suggestion! I added it to the tutorial.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

Once the build has completed, you can preview your PR at this URL: https://juliasmoothoptimizers.github.io/JSOTutorials.jl/

Copy link
Member

@abelsiqueira abelsiqueira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tmigot tmigot merged commit 18e40f7 into main Feb 2, 2023
@tmigot tmigot deleted the add-jsotutorials branch February 2, 2023 13:00
@tmigot
Copy link
Member Author

tmigot commented Feb 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants