-
Notifications
You must be signed in to change notification settings - Fork 10
JSO Compliance : LM #200
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
Open
MaxenceGollier
wants to merge
17
commits into
JuliaSmoothOptimizers:master
Choose a base branch
from
MaxenceGollier:LM-JSO
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
JSO Compliance : LM #200
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
58f26a1
start LM update
MaxenceGollier 3ffc73b
JSO-compliant LM draft
MaxenceGollier 02b6cce
make LMModel type stable
MaxenceGollier 458aae8
improve type stability in LM
MaxenceGollier 5101a10
add LM doc
MaxenceGollier 144f9a4
add LM function signatures
MaxenceGollier 576bb88
update tests
MaxenceGollier f85deac
solve function signature bugs
MaxenceGollier 53c40b8
remove dead code
MaxenceGollier 3c8e92e
apply julia formatter
MaxenceGollier de6a62b
implicit jacobian update
MaxenceGollier 63b9e3a
Merge branch 'JuliaSmoothOptimizers:master' into LM-JSO
MaxenceGollier b4cb5b7
remove temporary struct
MaxenceGollier 25fc1da
Merge branch 'JuliaSmoothOptimizers:master' into LM-JSO
MaxenceGollier 77ddd78
update callback docstring
MaxenceGollier 69e8409
Merge branch 'JuliaSmoothOptimizers:master' into LM-JSO
MaxenceGollier 7df41cc
fix arrow prints
MaxenceGollier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export LMModel | ||
|
||
@doc raw""" | ||
LMModel(j_prod!, jt_prod, F, v, σ, xk) | ||
|
||
Given the unconstrained optimization problem: | ||
```math | ||
\min \tfrac{1}{2} \| F(x) \|^2, | ||
``` | ||
this model represents the smooth LM subproblem: | ||
```math | ||
\min_s \ \tfrac{1}{2} \| F(x) + J(x)s \|^2 + \tfrac{1}{2} σ \|s\|^2 | ||
``` | ||
where `J` is the Jacobian of `F` at `xk`, represented via matrix-free operations. | ||
`j_prod!(xk, s, out)` computes `J(xk) * s`, and `jt_prod!(xk, r, out)` computes `J(xk)' * r`. | ||
|
||
`σ > 0` is a regularization parameter and `v` is a vector of the same size as `F(xk)` used for intermediary computations. | ||
""" | ||
mutable struct LMModel{T <: Real, V <: AbstractVector{T}, Jac <: Union{AbstractMatrix, AbstractLinearOperator}} <: | ||
AbstractNLPModel{T, V} | ||
J::Jac | ||
F::V | ||
v::V | ||
xk::V | ||
σ::T | ||
meta::NLPModelMeta{T, V} | ||
counters::Counters | ||
end | ||
|
||
function LMModel(J::Jac, F::V, σ::T, xk::V) where {T, V, Jac} | ||
meta = NLPModelMeta( | ||
length(xk), | ||
x0 = xk, # Perhaps we should add lvar and uvar as well here. | ||
) | ||
v = similar(F) | ||
return LMModel(J, F, v, xk, σ, meta, Counters()) | ||
end | ||
|
||
function NLPModels.obj(nlp::LMModel, x::AbstractVector{T}) where {T} | ||
@lencheck nlp.meta.nvar x | ||
increment!(nlp, :neval_obj) | ||
mul!(nlp.v, nlp.J, x) | ||
nlp.v .+= nlp.F | ||
return (dot(nlp.v, nlp.v) + nlp.σ * dot(x, x)) / 2 | ||
end | ||
|
||
function NLPModels.grad!(nlp::LMModel, x::AbstractVector{T}, g::AbstractVector{T}) where {T} | ||
@lencheck nlp.meta.nvar x | ||
@lencheck nlp.meta.nvar g | ||
increment!(nlp, :neval_grad) | ||
mul!(nlp.v, nlp.J, x) | ||
nlp.v .+= nlp.F | ||
mul!(g, nlp.J', nlp.v) | ||
@. g += nlp.σ .* x | ||
return g | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, would it be possible to reuse LLSModels?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how,$\frac{1}{2} ∥Ax-b∥^2_2$ , not $\frac{1}{2} ∥Ax-b∥^2_2 + \frac{\sigma}{2}∥x∥^2_2$ ,
LLSModels
doessure we could write
but this will be impractical in my opinion.