Skip to content

Commit

Permalink
Change R2_alg so that it returns list of times
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedLaghdafHABIBOULLAH committed Sep 17, 2024
1 parent b6cd089 commit acaad65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/R2DH.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ function R2DH(
s = zero(xk)
ψ = has_bnds ? shifted(h, xk, l_bound - xk, u_bound - xk, selected) : shifted(h, xk)

Fobj_hist = zeros(maxIter)
Hobj_hist = zeros(maxIter)
time_hist = zeros(maxIter)
Fobj_hist = zeros(maxIter+1)
Hobj_hist = zeros(maxIter+1)
time_hist = zeros(maxIter+1)
FHobj_hist = fill!(Vector{R}(undef, Mmonotone), R(-Inf))
Complex_hist = zeros(Int, maxIter)
Complex_hist = zeros(Int, maxIter+1)
if verbose > 0
#! format: off
@info @sprintf "%6s %8s %8s %7s %8s %7s %7s %7s %1s" "iter" "f(x)" "h(x)" "√(ξ/ν)" "ρ" "σ" "‖x‖" "‖s‖" ""
Expand Down Expand Up @@ -181,6 +181,8 @@ function R2DH(
time_hist[k] = elapsed_time
Mmonotone > 0 && (FHobj_hist[mod(k-1, Mmonotone) + 1] = fk + hk)

#Dkσk .= max.(Dkσk, eps(R))

# model with diagonal hessian
φ(d) = ∇fk' * d + (d' * (Dkσk .* d)) / 2
mk(d) = φ(d) + ψ(d)
Expand All @@ -190,8 +192,9 @@ function R2DH(
else
iprox!(s, ψ, ∇fk, Dkσk)
end
mks = mk(s)

if mk(s) > 1/eps(R)
if mks < -1e5
σk = σk * γ
Dkσk .= D.d .+ σk
DNorm = norm(D.d, Inf)
Expand All @@ -208,8 +211,8 @@ function R2DH(

fhmax = Mmonotone > 0 ? maximum(FHobj_hist) : fk + hk
Δobj = fhmax - (fkn + hkn) + max(1, abs(fhmax)) * 10 * eps()
Δmod = fhmax - (fk + mk(s)) + max(1, abs(hk)) * 10 * eps()
ξ = hk - mk(s) + max(1, abs(hk)) * 10 * eps()
Δmod = fhmax - (fk + mks) + max(1, abs(hk)) * 10 * eps()
ξ = hk - mks + max(1, abs(hk)) * 10 * eps()
sqrt_ξ_νInv = ξ 0 ? sqrt/ ν) : sqrt(-ξ / ν)

if ξ 0 && k == 1
Expand Down
10 changes: 10 additions & 0 deletions src/R2_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mutable struct R2Solver{
Fobj_hist::Vector{R}
Hobj_hist::Vector{R}
Complex_hist::Vector{Int}
Time_hist::Vector{R}
end

function R2Solver(
Expand All @@ -46,6 +47,7 @@ function R2Solver(
end
Fobj_hist = zeros(R, maxIter + 2)
Hobj_hist = zeros(R, maxIter + 2)
Time_hist = zeros(R, maxIter + 2)
Complex_hist = zeros(Int, maxIter + 2)
return R2Solver(
xk,
Expand All @@ -62,6 +64,7 @@ function R2Solver(
Fobj_hist,
Hobj_hist,
Complex_hist,
Time_hist,
)
end

Expand All @@ -87,6 +90,7 @@ function R2Solver(reg_nlp::AbstractRegularizedNLPModel{T, V}; max_iter::Int = 10
end
Fobj_hist = zeros(T, max_iter + 2)
Hobj_hist = zeros(T, max_iter + 2)
Time_hist = zeros(T, max_iter + 2)
Complex_hist = zeros(Int, max_iter + 2)

ψ =
Expand All @@ -107,6 +111,7 @@ function R2Solver(reg_nlp::AbstractRegularizedNLPModel{T, V}; max_iter::Int = 10
Fobj_hist,
Hobj_hist,
Complex_hist,
Time_hist,
)
end

Expand Down Expand Up @@ -201,6 +206,7 @@ function R2(
ν = options.ν,
γ = options.γ,
)
return stats
end

function R2(
Expand Down Expand Up @@ -232,6 +238,7 @@ function R2(
outdict = Dict(
:Fhist => stats.solver_specific[:Fhist],
:Hhist => stats.solver_specific[:Hhist],
:Time_hist => stats.solver_specific[:Time_hist],
:Chist => stats.solver_specific[:SubsolverCounter],
:NonSmooth => h,
:status => stats.status,
Expand Down Expand Up @@ -274,6 +281,7 @@ function R2(
outdict = Dict(
:Fhist => stats.solver_specific[:Fhist],
:Hhist => stats.solver_specific[:Hhist],
:Time_hist => stats.solver_specific[:Time_hist],
:Chist => stats.solver_specific[:SubsolverCounter],
:NonSmooth => h,
:status => stats.status,
Expand All @@ -295,10 +303,12 @@ function R2(reg_nlp::AbstractRegularizedNLPModel; kwargs...)
solver.Fobj_hist[stats.iter + 1] = stats.solver_specific[:smooth_obj]
solver.Hobj_hist[stats.iter + 1] = stats.solver_specific[:nonsmooth_obj]
solver.Complex_hist[stats.iter + 1] += 1
solver.Time_hist[stats.iter + 1] = stats.elapsed_time
end
solve!(solver, reg_nlp, stats; callback = cb, max_iter = max_iter, kwargs...)
set_solver_specific!(stats, :Fhist, solver.Fobj_hist[1:(stats.iter + 1)])
set_solver_specific!(stats, :Hhist, solver.Hobj_hist[1:(stats.iter + 1)])
set_solver_specific!(stats, :Time_hist, solver.Time_hist[1:(stats.iter + 1)])
set_solver_specific!(stats, :SubsolverCounter, solver.Complex_hist[1:(stats.iter + 1)])
return stats
end
Expand Down

0 comments on commit acaad65

Please sign in to comment.