Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/LMTR_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ where F(x) and J(x) are the residual and its Jacobian at x, respectively, ψ(s;
### Return values

* `xk`: the final iterate
* `Fobj_hist`: an array with the history of values of the smooth objective
* `Hobj_hist`: an array with the history of values of the nonsmooth objective
* `Complex_hist`: an array with the history of number of inner iterations.
"""
function LMTR(
nls::AbstractNLSModel,
Expand Down Expand Up @@ -107,12 +104,6 @@ function LMTR(
treats_bounds ? shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) :
shifted(h, xk, Δk, χ)

Fobj_hist = zeros(maxIter)
Hobj_hist = zeros(maxIter)
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‖" "1/ν" "TR"
Expand Down Expand Up @@ -141,10 +132,6 @@ function LMTR(
while !(optimal || tired)
k = k + 1
elapsed_time = time() - start_time
Fobj_hist[k] = fk
Hobj_hist[k] = hk
Grad_hist[k] = nls.counters.neval_jtprod_residual + nls.counters.neval_jprod_residual
Resid_hist[k] = nls.counters.neval_residual

# model for first prox-gradient iteration
φ1(d) = begin
Expand Down Expand Up @@ -206,8 +193,6 @@ function LMTR(
subsolver_options.ϵa = ϵa_subsolver
subsolver_options.Δk = Δk_subsolver

Complex_hist[k] = iter

sNorm = χ(s)
xkn .= xk .+ s
residual!(nls, xkn, Fkn)
Expand Down Expand Up @@ -293,11 +278,5 @@ function LMTR(
set_residuals!(stats, zero(eltype(xk)), ξ1 ≥ 0 ? sqrt(ξ1) : ξ1)
set_iter!(stats, k)
set_time!(stats, elapsed_time)
set_solver_specific!(stats, :Fhist, Fobj_hist[1:k])
set_solver_specific!(stats, :Hhist, Hobj_hist[1:k])
set_solver_specific!(stats, :NonSmooth, h)
set_solver_specific!(stats, :SubsolverCounter, Complex_hist[1:k])
set_solver_specific!(stats, :NLSGradHist, Grad_hist[1:k])
set_solver_specific!(stats, :ResidHist, Resid_hist[1:k])
return stats
end
22 changes: 1 addition & 21 deletions src/LM_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ and σ > 0 is a regularization parameter.
### Return values

* `xk`: the final iterate
* `Fobj_hist`: an array with the history of values of the smooth objective
* `Hobj_hist`: an array with the history of values of the nonsmooth objective
* `Complex_hist`: an array with the history of number of inner iterations.
"""
function LM(
nls::AbstractNLSModel,
Expand Down Expand Up @@ -102,11 +99,6 @@ function LM(

local ξ1
k = 0
Fobj_hist = zeros(maxIter)
Hobj_hist = zeros(maxIter)
Complex_hist = zeros(Int, maxIter)
Grad_hist = zeros(Int, maxIter)
Resid_hist = zeros(Int, maxIter)

if verbose > 0
#! format: off
Expand Down Expand Up @@ -134,10 +126,6 @@ function LM(
while !(optimal || tired)
k = k + 1
elapsed_time = time() - start_time
Fobj_hist[k] = fk
Hobj_hist[k] = hk
Grad_hist[k] = nls.counters.neval_jtprod_residual + nls.counters.neval_jprod_residual
Resid_hist[k] = nls.counters.neval_residual

# model for first prox-gradient iteration
φ1(d) = begin
Expand Down Expand Up @@ -199,8 +187,6 @@ function LM(
subsolver_options.ν = ν_subsolver
subsolver_options.ϵa = ϵa_subsolver

Complex_hist[k] = iter

xkn .= xk .+ s
residual!(nls, xkn, Fkn)
fkn = dot(Fkn, Fkn) / 2
Expand Down Expand Up @@ -245,7 +231,7 @@ function LM(
σmax = opnorm(Jk)
νInv = (1 + θ) * (σmax^2 + σk) # ‖J'J + σₖ I‖ = ‖J‖² + σₖ

Complex_hist[k] += 1
# Complex_hist[k] += 1
end

if ρk < η1 || ρk == Inf
Expand Down Expand Up @@ -282,11 +268,5 @@ function LM(
set_residuals!(stats, zero(eltype(xk)), ξ1 ≥ 0 ? sqrt(ξ1) : ξ1)
set_iter!(stats, k)
set_time!(stats, elapsed_time)
set_solver_specific!(stats, :Fhist, Fobj_hist[1:k])
set_solver_specific!(stats, :Hhist, Hobj_hist[1:k])
set_solver_specific!(stats, :NonSmooth, h)
set_solver_specific!(stats, :SubsolverCounter, Complex_hist[1:k])
set_solver_specific!(stats, :NLSGradHist, Grad_hist[1:k])
set_solver_specific!(stats, :ResidHist, Resid_hist[1:k])
return stats
end
61 changes: 4 additions & 57 deletions src/R2_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ mutable struct R2Solver{R, S <: AbstractVector{R}} <: AbstractOptimizationSolver
u_bound::S
l_bound_m_x::S
u_bound_m_x::S
Fobj_hist::Vector{R}
Hobj_hist::Vector{R}
Complex_hist::Vector{Int}
end

function R2Solver(
Expand All @@ -36,24 +33,7 @@ function R2Solver(
l_bound_m_x = similar(xk, 0)
u_bound_m_x = similar(xk, 0)
end
Fobj_hist = zeros(R, maxIter)
Hobj_hist = zeros(R, maxIter)
Complex_hist = zeros(Int, maxIter)
return R2Solver(
xk,
∇fk,
mν∇fk,
xkn,
s,
has_bnds,
l_bound,
u_bound,
l_bound_m_x,
u_bound_m_x,
Fobj_hist,
Hobj_hist,
Complex_hist,
)
return R2Solver(xk, ∇fk, mν∇fk, xkn, s, has_bnds, l_bound, u_bound, l_bound_m_x, u_bound_m_x)
end

"""
Expand Down Expand Up @@ -96,9 +76,6 @@ In the second form, instead of `nlp`, the user may pass in
### Return values

* `xk`: the final iterate
* `Fobj_hist`: an array with the history of values of the smooth objective
* `Hobj_hist`: an array with the history of values of the nonsmooth objective
* `Complex_hist`: an array with the history of number of inner iterations.
"""
function R2(nlp::AbstractNLPModel, args...; kwargs...)
kwargs_dict = Dict(kwargs...)
Expand All @@ -120,10 +97,6 @@ function R2(nlp::AbstractNLPModel, args...; kwargs...)
set_residuals!(stats, zero(eltype(xk)), ξ)
set_iter!(stats, k)
set_time!(stats, outdict[:elapsed_time])
set_solver_specific!(stats, :Fhist, outdict[:Fhist])
set_solver_specific!(stats, :Hhist, outdict[:Hhist])
set_solver_specific!(stats, :NonSmooth, outdict[:NonSmooth])
set_solver_specific!(stats, :SubsolverCounter, outdict[:Chist])
return stats
end

Expand All @@ -142,17 +115,7 @@ function R2(
solver = R2Solver(x0, options, similar(x0, 0), similar(x0, 0))
k, status, fk, hk, ξ = R2!(solver, f, ∇f!, h, options, x0; selected = selected)
elapsed_time = time() - start_time
outdict = Dict(
:Fhist => solver.Fobj_hist[1:k],
:Hhist => solver.Hobj_hist[1:k],
:Chist => solver.Complex_hist[1:k],
:NonSmooth => h,
:status => status,
:fk => fk,
:hk => hk,
:ξ => ξ,
:elapsed_time => elapsed_time,
)
outdict = Dict(:status => status, :fk => fk, :hk => hk, :ξ => ξ, :elapsed_time => elapsed_time)
return solver.xk, k, outdict
end

Expand All @@ -172,17 +135,7 @@ function R2(
solver = R2Solver(x0, options, l_bound, u_bound)
k, status, fk, hk, ξ = R2!(solver, f, ∇f!, h, options, x0; selected = selected)
elapsed_time = time() - start_time
outdict = Dict(
:Fhist => solver.Fobj_hist[1:k],
:Hhist => solver.Hobj_hist[1:k],
:Chist => solver.Complex_hist[1:k],
:NonSmooth => h,
:status => status,
:fk => fk,
:hk => hk,
:ξ => ξ,
:elapsed_time => elapsed_time,
)
outdict = Dict(:status => status, :fk => fk, :hk => hk, :ξ => ξ, :elapsed_time => elapsed_time)
return solver.xk, k, outdict
end

Expand Down Expand Up @@ -223,9 +176,6 @@ function R2!(
l_bound_m_x = solver.l_bound_m_x
u_bound_m_x = solver.u_bound_m_x
end
Fobj_hist = solver.Fobj_hist
Hobj_hist = solver.Hobj_hist
Complex_hist = solver.Complex_hist

if verbose == 0
ptf = Inf
Expand Down Expand Up @@ -278,23 +228,20 @@ function R2!(
while !(optimal || tired)
k = k + 1
elapsed_time = time() - start_time
Fobj_hist[k] = fk
Hobj_hist[k] = hk

# define model
φk(d) = dot(∇fk, d)
mk(d)::R = φk(d) + ψ(d)::R

prox!(s, ψ, mν∇fk, ν)
Complex_hist[k] += 1
mks = mk(s)
ξ = hk - mks + max(1, abs(hk)) * 10 * eps()
sqrt_ξ_νInv = ξ ≥ 0 ? sqrt(ξ / ν) : sqrt(-ξ / ν)

if ξ ≥ 0 && k == 1
ϵ += ϵr * sqrt_ξ_νInv # make stopping test absolute and relative
end

if (ξ < 0 && sqrt_ξ_νInv ≤ neg_tol) || (ξ ≥ 0 && sqrt_ξ_νInv ≤ ϵ)
optimal = true
continue
Expand Down
29 changes: 3 additions & 26 deletions src/TRDH_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ In the second form, instead of `nlp`, the user may pass in
### Return values

* `xk`: the final iterate
* `Fobj_hist`: an array with the history of values of the smooth objective
* `Hobj_hist`: an array with the history of values of the nonsmooth objective
* `Complex_hist`: an array with the history of number of inner iterations.
"""
function TRDH(
nlp::AbstractNLPModel{R},
Expand Down Expand Up @@ -75,10 +72,6 @@ function TRDH(
set_residuals!(stats, zero(eltype(xk)), ξ)
set_iter!(stats, k)
set_time!(stats, outdict[:elapsed_time])
set_solver_specific!(stats, :Fhist, outdict[:Fhist])
set_solver_specific!(stats, :Hhist, outdict[:Hhist])
set_solver_specific!(stats, :NonSmooth, outdict[:NonSmooth])
set_solver_specific!(stats, :SubsolverCounter, outdict[:Chist])
return stats
end

Expand Down Expand Up @@ -182,9 +175,6 @@ function TRDH(
end
end

Fobj_hist = zeros(maxIter)
Hobj_hist = zeros(maxIter)
Complex_hist = zeros(Int, maxIter)
if verbose > 0
#! format: off
if reduce_TR
Expand Down Expand Up @@ -217,16 +207,13 @@ function TRDH(
while !(optimal || tired)
k = k + 1
elapsed_time = time() - start_time
Fobj_hist[k] = fk
Hobj_hist[k] = hk

# model for prox-gradient step to update Δk if ||s|| is too small and ξ1
φ1(d) = ∇fk' * d
mk1(d) = φ1(d) + ψ(d)

if reduce_TR
prox!(s, ψ, mν∇fk, ν)
Complex_hist[k] += 1
ξ1 = hk - mk1(s) + max(1, abs(hk)) * 10 * eps()
sqrt_ξ_νInv = ξ1 ≥ 0 ? sqrt(ξ1 / ν) : sqrt(-ξ1 / ν)

Expand All @@ -252,12 +239,11 @@ function TRDH(
set_radius!(ψ, Δ_effective)
end

# model with diagonal hessian
# model with diagonal hessian
φ(d) = ∇fk' * d + (d' * (Dk.d .* d)) / 2
mk(d) = φ(d) + ψ(d)

iprox!(s, ψ, ∇fk, Dk)
Complex_hist[k] += 1

sNorm = χ(s)
xkn .= xk .+ s
Expand Down Expand Up @@ -361,17 +347,8 @@ function TRDH(
else
:exception
end
outdict = Dict(
:Fhist => Fobj_hist[1:k],
:Hhist => Hobj_hist[1:k],
:Chist => Complex_hist[1:k],
:NonSmooth => h,
:status => status,
:fk => fk,
:hk => hk,
:ξ => sqrt_ξ_νInv,
:elapsed_time => elapsed_time,
)
outdict =
Dict(:status => status, :fk => fk, :hk => hk, :ξ => sqrt_ξ_νInv, :elapsed_time => elapsed_time)

return xk, k, outdict
end
16 changes: 1 addition & 15 deletions src/TR_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ The Hessian is accessed as an abstract operator and need not be the exact Hessia

### Return values

* `xk`: the final iterate
* `Fobj_hist`: an array with the history of values of the smooth objective
* `Hobj_hist`: an array with the history of values of the nonsmooth objective
* `Complex_hist`: an array with the history of number of inner iterations.
* `xk`: the final iterate.
"""
function TR(
f::AbstractNLPModel,
Expand Down Expand Up @@ -112,9 +109,6 @@ function TR(
shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) :
shifted(h, xk, Δk, χ)

Fobj_hist = zeros(maxIter)
Hobj_hist = zeros(maxIter)
Complex_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‖" "‖Bₖ‖" "TR"
Expand Down Expand Up @@ -142,8 +136,6 @@ function TR(
while !(optimal || tired)
k = k + 1
elapsed_time = time() - start_time
Fobj_hist[k] = fk
Hobj_hist[k] = hk

# model for first prox-gradient step and ξ1
φ1(d) = ∇fk' * d
Expand Down Expand Up @@ -195,8 +187,6 @@ function TR(
subsolver_options.ϵa = ϵa_subsolver
subsolver_options.Δk = Δk_subsolver

Complex_hist[k] = sum(outdict[:Chist])

sNorm = χ(s)
xkn .= xk .+ s
fkn = obj(f, xkn)
Expand Down Expand Up @@ -282,9 +272,5 @@ function TR(
set_residuals!(stats, zero(eltype(xk)), sqrt_ξ1_νInv)
set_iter!(stats, k)
set_time!(stats, elapsed_time)
set_solver_specific!(stats, :Fhist, Fobj_hist[1:k])
set_solver_specific!(stats, :Hhist, Hobj_hist[1:k])
set_solver_specific!(stats, :NonSmooth, h)
set_solver_specific!(stats, :SubsolverCounter, Complex_hist[1:k])
return stats
end
Loading