Skip to content

Commit 6dcafa1

Browse files
add updated parameter of subsolvers and add sigam-k to input.jl structure
1 parent 652701d commit 6dcafa1

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

src/R2DH.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ function R2DH(
6161
hess_op(nlp, x0),
6262
options,
6363
x0;
64+
l_bound = nlp.meta.lvar,
65+
u_bound = nlp.meta.uvar,
6466
kwargs...,
6567
)
6668
sqrt_ξ_νInv = outdict[:sqrt_ξ_νInv]
@@ -99,6 +101,7 @@ function R2DH(
99101
maxIter = options.maxIter
100102
maxTime = options.maxTime
101103
σmin = options.σmin
104+
σk = options.σk
102105
η1 = options.η1
103106
η2 = options.η2
104107
ν = options.ν
@@ -148,6 +151,7 @@ function R2DH(
148151
time_hist = zeros(maxIter+1)
149152
FHobj_hist = fill!(Vector{R}(undef, Mmonotone), R(-Inf))
150153
Complex_hist = zeros(Int, maxIter+1)
154+
k_prox = 0
151155
if verbose > 0
152156
#! format: off
153157
@info @sprintf "%6s %8s %8s %7s %8s %7s %7s %7s %1s" "iter" "f(x)" "h(x)" "√(ξ/ν)" "ρ" "σ" "‖x‖" "‖s‖" ""
@@ -156,13 +160,13 @@ function R2DH(
156160

157161
local ξ
158162
k = 0
159-
σk = σmin
160163

161164
fk = f(xk)
162165
∇fk = similar(xk)
163166
∇f!(∇fk, xk)
164167
∇fk⁻ = copy(∇fk)
165168
spectral_test = isa(D, SpectralGradient)
169+
# D.d .= D.d .+ σk
166170
Dkσk = D.d .+ σk
167171
DNorm = norm(D.d, Inf)
168172

@@ -174,15 +178,7 @@ function R2DH(
174178
tired = maxIter > 0 && k maxIter || elapsed_time > maxTime
175179

176180
while !(optimal || tired)
177-
k = k + 1
178-
elapsed_time = time() - start_time
179-
Fobj_hist[k] = fk
180-
Hobj_hist[k] = hk
181-
time_hist[k] = elapsed_time
182-
Mmonotone > 0 && (FHobj_hist[mod(k-1, Mmonotone) + 1] = fk + hk)
183-
184-
#Dkσk .= max.(Dkσk, eps(R))
185-
181+
k_prox += 1
186182
# model with diagonal hessian
187183
φ(d) = ∇fk' * d + (d' * (Dkσk .* d)) / 2
188184
mk(d) = φ(d) + ψ(d)
@@ -203,7 +199,15 @@ function R2DH(
203199
continue
204200
end
205201

206-
Complex_hist[k] += 1
202+
k = k + 1
203+
elapsed_time = time() - start_time
204+
Fobj_hist[k] = fk
205+
Hobj_hist[k] = hk
206+
time_hist[k] = elapsed_time
207+
Mmonotone > 0 && (FHobj_hist[mod(k-1, Mmonotone) + 1] = fk + hk)
208+
209+
Complex_hist[k] += k_prox
210+
k_prox = 0
207211
xkn .= xk .+ s
208212
fkn = f(xkn)
209213
hkn = h(xkn[selected])
@@ -260,6 +264,7 @@ function R2DH(
260264
end
261265

262266
Dkσk .= D.d .+ σk
267+
DNorm = norm(D.d, Inf)
263268
ν = 1 / ((DNorm + σk) * (1 + θ))
264269

265270
tired = maxIter > 0 && k maxIter

src/R2N.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function R2N(
5151
subsolver_logger::Logging.AbstractLogger = Logging.NullLogger(),
5252
subsolver = R2,
5353
subsolver_options = ROSolverOptions(ϵa = options.ϵa),
54+
Mmonotone::Int = 0,
5455
selected::AbstractVector{<:Integer} = 1:(f.meta.nvar),
5556
) where {H, R}
5657
start_time = time()
@@ -71,6 +72,7 @@ function R2N(
7172
σmin = options.σmin
7273
α = options.α
7374
β = options.β
75+
σk = options.σk
7476

7577
# store initial values of the subsolver_options fields that will be modified
7678
ν_subsolver = subsolver_options.ν
@@ -94,7 +96,6 @@ function R2N(
9496

9597
# initialize parameters
9698
#σk = max(1 / options.ν, σmin) #SVM
97-
σk = σmin
9899
xk = copy(x0)
99100
hk = h(xk[selected])
100101
if hk == Inf
@@ -112,6 +113,7 @@ function R2N(
112113

113114
Fobj_hist = zeros(maxIter)
114115
Hobj_hist = zeros(maxIter)
116+
FHobj_hist = fill!(Vector{R}(undef, Mmonotone), R(-Inf))
115117
Complex_hist = zeros(Int, maxIter)
116118
if verbose > 0
117119
#! format: off
@@ -143,6 +145,7 @@ function R2N(
143145
elapsed_time = time() - start_time
144146
Fobj_hist[k] = fk
145147
Hobj_hist[k] = hk
148+
Mmonotone > 0 && (FHobj_hist[mod(k-1, Mmonotone) + 1] = fk + hk)
146149

147150
# model for first prox-gradient step and ξ1
148151
φ1(d) = ∇fk' * d
@@ -168,9 +171,6 @@ function R2N(
168171
ξ1 = hk - mk1(s) + max(1, abs(hk)) * 10 * eps()
169172
ξ1 > 0 || error("R2N: first prox-gradient step should produce a decrease but ξ1 = $(ξ1)")
170173
sqrt_ξ1_νInv = sqrt(ξ1 * νInv)
171-
# println("sqrt_ξ1_νInv: ", sqrt_ξ1_νInv)
172-
# println("ξ1: ", ξ1)
173-
# println("νInv: ", νInv)
174174

175175
if ξ1 0 && k == 1
176176
ϵ_increment = ϵr * sqrt_ξ1_νInv
@@ -186,9 +186,9 @@ function R2N(
186186
s1 = copy(s)
187187

188188
# subsolver_options.ϵa = k == 1 ? 1.0e-1 : max(ϵ_subsolver, min(1.0e-2, ξ1 / 10))
189-
subsolver_options.ϵa = k == 1 ? 1.0e-3 : max(ϵ_subsolver, min(1e-3, sqrt_ξ1_νInv)) # 1.0e-5 default
189+
subsolver_options.ϵa = k == 1 ? 1.0e-3 : min(sqrt_ξ1_νInv ^ (1.5) , sqrt_ξ1_νInv * 1e-3) # 1.0e-5 default
190190
@debug "setting inner stopping tolerance to" subsolver_options.optTol
191-
subsolver_args = subsolver == R2DH ? (SpectralGradient(1., f.meta.nvar),) : ()
191+
subsolver_args = subsolver == R2DH ? (SpectralGradient(νInv, f.meta.nvar),) : ()
192192
s, iter, _ = with_logger(subsolver_logger) do
193193
subsolver(φ, ∇φ!, ψ, subsolver_args..., subsolver_options, s)
194194
end
@@ -208,18 +208,21 @@ function R2N(
208208
hkn = h(xkn[selected])
209209
hkn == -Inf && error("nonsmooth term is not proper")
210210
mks = mk(s) #- σk * dot(s, s) / 2
211-
Δobj = fk + hk - (fkn + hkn) + max(1, abs(fk + hk)) * 10 * eps()
211+
212+
fhmax = Mmonotone > 0 ? maximum(FHobj_hist) : fk + hk
213+
Δobj = fhmax - (fkn + hkn) + max(1, abs(fhmax)) * 10 * eps()
214+
Δmod = fhmax - (fk + mks) + max(1, abs(hk)) * 10 * eps()
212215
ξ = hk - mks + max(1, abs(hk)) * 10 * eps()
213216

214217
if 0 || isnan(ξ))
215218
error("R2N: failed to compute a step: ξ = ")
216219
end
217220

218-
ρk = Δobj / ξ
221+
ρk = Δobj / Δmod
219222

220223
R2N_stat = (η2 ρk < Inf) ? "" : (ρk < η1 ? "" : "=")
221224

222-
if (verbose > 0) && (k % ptf == 0)
225+
if (verbose > 0) && ((k % ptf == 0) || (k == 1))
223226
#! format: off
224227
@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(ξ1) ρk σk norm(xk) norm(s) λmax R2N_stat
225228
#! format: off
@@ -251,8 +254,7 @@ function R2N(
251254
if ρk < η1 || ρk == Inf
252255
σk = σk * γ
253256
end
254-
νInv = (1 + θ) *( σk + λmax)
255-
257+
νInv = (1 + θ) * (σk + λmax)
256258
tired = k maxIter || elapsed_time > maxTime
257259
end
258260

src/input_struct.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mutable struct ROSolverOptions{R}
99
maxIter::Int # maximum amount of inner iterations
1010
maxTime::Float64 #maximum time allotted to the algorithm in s
1111
σmin::R # minimum σk allowed for LM/R2 method
12+
σk::R # initial σk
1213
η1::R # step acceptance threshold
1314
η2::R # trust-region increase threshold
1415
α::R # νk Δ^{-1} parameter
@@ -27,6 +28,7 @@ mutable struct ROSolverOptions{R}
2728
maxIter::Int = 10000,
2829
maxTime::Float64 = 3600.0,
2930
σmin::R = eps(R),
31+
σk::R = eps(R)^(1 / 5),
3032
η1::R = √√eps(R),
3133
η2::R = R(0.9),
3234
α::R = 1 / eps(R),
@@ -44,6 +46,7 @@ mutable struct ROSolverOptions{R}
4446
@assert maxIter 0
4547
@assert maxTime 0
4648
@assert σmin 0
49+
@assert σk 0
4750
@assert 0 < η1 < η2 < 1
4851
@assert α > 0
4952
@assert ν > 0
@@ -59,6 +62,7 @@ mutable struct ROSolverOptions{R}
5962
maxIter,
6063
maxTime,
6164
σmin,
65+
σk,
6266
η1,
6367
η2,
6468
α,

0 commit comments

Comments
 (0)