-
Notifications
You must be signed in to change notification settings - Fork 10
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
update LM solver #156
Open
MohamedLaghdafHABIBOULLAH
wants to merge
1
commit into
JuliaSmoothOptimizers:master
Choose a base branch
from
MohamedLaghdafHABIBOULLAH:LM-update
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
update LM solver #156
Changes from all commits
Commits
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 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,6 +47,7 @@ function LM( | |||||||||||||
subsolver = R2, | ||||||||||||||
subsolver_options = ROSolverOptions(ϵa = options.ϵa), | ||||||||||||||
selected::AbstractVector{<:Integer} = 1:(nls.meta.nvar), | ||||||||||||||
nonlinear::Bool = true, | ||||||||||||||
) where {H} | ||||||||||||||
start_time = time() | ||||||||||||||
elapsed_time = 0.0 | ||||||||||||||
|
@@ -62,6 +63,7 @@ function LM( | |||||||||||||
γ = options.γ | ||||||||||||||
θ = options.θ | ||||||||||||||
σmin = options.σmin | ||||||||||||||
σk = options.σk | ||||||||||||||
|
||||||||||||||
# store initial values of the subsolver_options fields that will be modified | ||||||||||||||
ν_subsolver = subsolver_options.ν | ||||||||||||||
|
@@ -85,7 +87,6 @@ function LM( | |||||||||||||
end | ||||||||||||||
|
||||||||||||||
# initialize parameters | ||||||||||||||
σk = max(1 / options.ν, σmin) | ||||||||||||||
xk = copy(x0) | ||||||||||||||
hk = h(xk[selected]) | ||||||||||||||
if hk == Inf | ||||||||||||||
|
@@ -104,13 +105,15 @@ function LM( | |||||||||||||
k = 0 | ||||||||||||||
Fobj_hist = zeros(maxIter) | ||||||||||||||
Hobj_hist = zeros(maxIter) | ||||||||||||||
R = eltype(xk) | ||||||||||||||
sqrt_ξ1_νInv = one(R) | ||||||||||||||
Complex_hist = zeros(Int, maxIter) | ||||||||||||||
Grad_hist = zeros(Int, maxIter) | ||||||||||||||
Resid_hist = zeros(Int, maxIter) | ||||||||||||||
|
||||||||||||||
if verbose > 0 | ||||||||||||||
#! format: off | ||||||||||||||
@info @sprintf "%6s %8s %8s %8s %7s %7s %8s %7s %7s %7s %7s %1s" "outer" "inner" "f(x)" "h(x)" "√ξ1" "√ξ" "ρ" "σ" "‖x‖" "‖s‖" "‖Jₖ‖²" "reg" | ||||||||||||||
@info @sprintf "%6s %8s %8s %8s %7s %7s %8s %7s %7s %7s %7s %1s" "outer" "inner" "f(x)" "h(x)" "√(ξ1/ν)" "√ξ" "ρ" "σ" "‖x‖" "‖s‖" "‖Jₖ‖²" "reg" | ||||||||||||||
#! format: on | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
|
@@ -176,22 +179,24 @@ function LM( | |||||||||||||
prox!(s, ψ, ∇fk, ν) | ||||||||||||||
ξ1 = fk + hk - mk1(s) + max(1, abs(fk + hk)) * 10 * eps() # TODO: isn't mk(s) returned by subsolver? | ||||||||||||||
ξ1 > 0 || error("LM: first prox-gradient step should produce a decrease but ξ1 = $(ξ1)") | ||||||||||||||
sqrt_ξ1_νInv = ξ1 > 0 ? sqrt(ξ1 * νInv) : 10. | ||||||||||||||
|
||||||||||||||
if ξ1 ≥ 0 && k == 1 | ||||||||||||||
ϵ_increment = ϵr * sqrt(ξ1) | ||||||||||||||
ϵ_increment = ϵr * sqrt_ξ1_νInv | ||||||||||||||
ϵ += ϵ_increment # make stopping test absolute and relative | ||||||||||||||
ϵ_subsolver += ϵ_increment | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
if sqrt(ξ1) < ϵ | ||||||||||||||
if sqrt_ξ1_νInv < ϵ | ||||||||||||||
# the current xk is approximately first-order stationary | ||||||||||||||
optimal = true | ||||||||||||||
continue | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
subsolver_options.ϵa = k == 1 ? 1.0e-1 : max(ϵ_subsolver, min(1.0e-2, ξ1 / 10)) | ||||||||||||||
# subsolver_options.ϵa = k == 1 ? 1.0e-1 : max(ϵ_subsolver, min(1.0e-2, ξ1 / 10)) | ||||||||||||||
subsolver_options.ϵa = k == 1 ? 1.0e-3 : min(sqrt_ξ1_νInv ^ (1.5) , sqrt_ξ1_νInv * 1e-3) # 1.0e-5 default | ||||||||||||||
subsolver_options.ν = ν | ||||||||||||||
subsolver_args = subsolver == TRDH ? (SpectralGradient(1 / ν, nls.meta.nvar),) : () | ||||||||||||||
subsolver_args = subsolver == R2DH ? (SpectralGradient(νInv, nls.meta.nvar),) : () | ||||||||||||||
@debug "setting inner stopping tolerance to" subsolver_options.optTol | ||||||||||||||
s, iter, _ = with_logger(subsolver_logger) do | ||||||||||||||
subsolver(φ, ∇φ!, ψ, subsolver_args..., subsolver_options, s) | ||||||||||||||
|
@@ -221,7 +226,7 @@ function LM( | |||||||||||||
|
||||||||||||||
if (verbose > 0) && (k % ptf == 0) | ||||||||||||||
#! format: off | ||||||||||||||
@info @sprintf "%6d %8d %8.1e %8.1e %7.1e %7.1e %8.1e %7.1e %7.1e %7.1e %7.1e %1s" k iter fk hk sqrt(ξ1) sqrt(ξ) ρk σk norm(xk) norm(s) νInv σ_stat | ||||||||||||||
@info @sprintf "%6d %8d %8.1e %8.1e %7.1e %7.1e %8.1e %7.1e %7.1e %7.1e %7.1e %1s" k iter fk hk sqrt_ξ1_νInv sqrt(ξ) ρk σk norm(xk) norm(s) νInv σ_stat | ||||||||||||||
#! format: off | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
|
@@ -243,7 +248,10 @@ function LM( | |||||||||||||
Jk = jac_op_residual(nls, xk) | ||||||||||||||
jtprod_residual!(nls, xk, Fk, ∇fk) | ||||||||||||||
|
||||||||||||||
σmax = opnorm(Jk) | ||||||||||||||
# update opnorm if not linear least squares | ||||||||||||||
if nonlinear == true | ||||||||||||||
σmax = opnorm(Jk) | ||||||||||||||
end | ||||||||||||||
Comment on lines
+252
to
+254
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
Complex_hist[k] += 1 | ||||||||||||||
end | ||||||||||||||
|
@@ -252,6 +260,7 @@ function LM( | |||||||||||||
σk = σk * γ | ||||||||||||||
end | ||||||||||||||
νInv = (1 + θ) * (σmax^2 + σk) # ‖J'J + σₖ I‖ = ‖J‖² + σₖ | ||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
tired = k ≥ maxIter || elapsed_time > maxTime | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
|
@@ -260,9 +269,9 @@ function LM( | |||||||||||||
@info @sprintf "%6d %8s %8.1e %8.1e" k "" fk hk | ||||||||||||||
elseif optimal | ||||||||||||||
#! format: off | ||||||||||||||
@info @sprintf "%6d %8d %8.1e %8.1e %7.1e %7.1e %8s %7.1e %7.1e %7.1e %7.1e" k 1 fk hk sqrt(ξ1) sqrt(ξ1) "" σk norm(xk) norm(s) νInv | ||||||||||||||
@info @sprintf "%6d %8d %8.1e %8.1e %7.1e %7.1e %8s %7.1e %7.1e %7.1e %7.1e" k 1 fk hk sqrt_ξ1_νInv sqrt(ξ1) "" σk norm(xk) norm(s) νInv | ||||||||||||||
#! format: on | ||||||||||||||
@info "LM: terminating with √ξ1 = $(sqrt(ξ1))" | ||||||||||||||
@info "LM: terminating with √(ξ1/ν) = $(sqrt_ξ1_νInv)" | ||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
status = if optimal | ||||||||||||||
|
@@ -279,7 +288,7 @@ function LM( | |||||||||||||
set_status!(stats, status) | ||||||||||||||
set_solution!(stats, xk) | ||||||||||||||
set_objective!(stats, fk + hk) | ||||||||||||||
set_residuals!(stats, zero(eltype(xk)), ξ1 ≥ 0 ? sqrt(ξ1) : ξ1) | ||||||||||||||
set_residuals!(stats, zero(eltype(xk)), ξ1 ≥ 0 ? sqrt_ξ1_νInv : ξ1) | ||||||||||||||
set_iter!(stats, k) | ||||||||||||||
set_time!(stats, elapsed_time) | ||||||||||||||
set_solver_specific!(stats, :Fhist, Fobj_hist[1:k]) | ||||||||||||||
|
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.
?????
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.
@MohamedLaghdafHABIBOULLAH What’s this?