Skip to content

Commit b6cd089

Browse files
add theta to nu and remove summation
1 parent 339a6cf commit b6cd089

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/LM_alg.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,14 @@ function LM(
246246
shift!(ψ, xk)
247247
Jk = jac_op_residual(nls, xk)
248248
jtprod_residual!(nls, xk, Fk, ∇fk)
249-
250249
σmax = opnorm(Jk)
251-
252-
253250
Complex_hist[k] += 1
254251
end
255252

256253
if ρk < η1 || ρk == Inf
257254
σk = σk * γ
258255
end
259256
νInv = (1 + θ) * (σmax^2 + σk) # ‖J'J + σₖ I‖ = ‖J‖² + σₖ
260-
261257
tired = k maxIter || elapsed_time > maxTime
262258
end
263259

src/R2DH.jl

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ About each iterate xₖ, a step sₖ is computed as a solution of
1515
1616
min φ(s; xₖ) + ψ(s; xₖ)
1717
18-
where φ(s ; xₖ) = f(xₖ) + ∇f(xₖ)ᵀs + ½ sᵀ (σₖ+Dₖ) s (if `summation = true`) and φ(s ; xₖ) = f(xₖ) + ∇f(xₖ)ᵀs + ½ sᵀ (σₖ+Dₖ) s (if `summation = false`) is a quadratic approximation of f about xₖ,
18+
where φ(s ; xₖ) = f(xₖ) + ∇f(xₖ)ᵀs + ½ sᵀ (σₖ+Dₖ) s is a quadratic approximation of f about xₖ,
1919
ψ(s; xₖ) = h(xₖ + s), ‖⋅‖ is a user-defined norm, Dₖ is a diagonal Hessian approximation
2020
and σₖ > 0 is the regularization parameter.
2121
@@ -31,7 +31,6 @@ and σₖ > 0 is the regularization parameter.
3131
* `x0::AbstractVector`: an initial guess (in the first calling form: default = `nlp.meta.x0`)
3232
* `selected::AbstractVector{<:Integer}`: (default `1:length(x0)`).
3333
* `Bk`: initial diagonal Hessian approximation (default: `(one(R) / options.ν) * I`).
34-
* `summation`: boolean used to choose between the two versions of R2DH (see above, default : `true`).
3534
3635
The objective and gradient of `nlp` will be accessed.
3736
@@ -64,16 +63,17 @@ function R2DH(
6463
x0;
6564
kwargs...,
6665
)
67-
ξ = outdict[:ξ]
66+
sqrt_ξ_νInv = outdict[:sqrt_ξ_νInv]
6867
stats = GenericExecutionStats(nlp)
6968
set_status!(stats, outdict[:status])
7069
set_solution!(stats, xk)
7170
set_objective!(stats, outdict[:fk] + outdict[:hk])
72-
set_residuals!(stats, zero(eltype(xk)), ξ)
71+
set_residuals!(stats, zero(eltype(xk)), sqrt_ξ_νInv)
7372
set_iter!(stats, k)
7473
set_time!(stats, outdict[:elapsed_time])
7574
set_solver_specific!(stats, :Fhist, outdict[:Fhist])
7675
set_solver_specific!(stats, :Hhist, outdict[:Hhist])
76+
set_solver_specific!(stats, :Time_hist, outdict[:Time_hist])
7777
set_solver_specific!(stats, :NonSmooth, outdict[:NonSmooth])
7878
set_solver_specific!(stats, :SubsolverCounter, outdict[:Chist])
7979
return stats
@@ -88,7 +88,6 @@ function R2DH(
8888
x0::AbstractVector{R};
8989
Mmonotone::Int = 5,
9090
selected::AbstractVector{<:Integer} = 1:length(x0),
91-
summation::Bool = true,
9291
kwargs...,
9392
) where {F <: Function, G <: Function, H, R <: Real, DQN <: AbstractDiagonalQuasiNewtonOperator}
9493
start_time = time()
@@ -104,6 +103,7 @@ function R2DH(
104103
η2 = options.η2
105104
ν = options.ν
106105
γ = options.γ
106+
θ = options.θ
107107

108108
local l_bound, u_bound
109109
has_bnds = false
@@ -145,28 +145,28 @@ function R2DH(
145145

146146
Fobj_hist = zeros(maxIter)
147147
Hobj_hist = zeros(maxIter)
148+
time_hist = zeros(maxIter)
148149
FHobj_hist = fill!(Vector{R}(undef, Mmonotone), R(-Inf))
149150
Complex_hist = zeros(Int, maxIter)
150151
if verbose > 0
151152
#! format: off
152-
@info @sprintf "%6s %8s %8s %7s %8s %7s %7s %7s %1s" "iter" "f(x)" "h(x)" "ξ" "ρ" "σ" "‖x‖" "‖s‖" ""
153+
@info @sprintf "%6s %8s %8s %7s %8s %7s %7s %7s %1s" "iter" "f(x)" "h(x)" "(ξ/ν)" "ρ" "σ" "‖x‖" "‖s‖" ""
153154
#! format: off
154155
end
155156

156157
local ξ
157158
k = 0
158-
σk = summation ? σmin : max(1 / ν, σmin)
159+
σk = σmin
159160

160161
fk = f(xk)
161162
∇fk = similar(xk)
162163
∇f!(∇fk, xk)
163164
∇fk⁻ = copy(∇fk)
164165
spectral_test = isa(D, SpectralGradient)
165-
D.d .= summation ? D.d .+ σk : D.d .* σk
166+
Dkσk = D.d .+ σk
166167
DNorm = norm(D.d, Inf)
167168

168-
169-
ν = 1 / DNorm
169+
ν = 1 / ((DNorm + σk) * (1 + θ))
170170
mν∇fk = -ν * ∇fk
171171
sqrt_ξ_νInv = one(R)
172172

@@ -178,22 +178,27 @@ function R2DH(
178178
elapsed_time = time() - start_time
179179
Fobj_hist[k] = fk
180180
Hobj_hist[k] = hk
181+
time_hist[k] = elapsed_time
181182
Mmonotone > 0 && (FHobj_hist[mod(k-1, Mmonotone) + 1] = fk + hk)
182183

183-
D.d .= max.(D.d, eps(R))
184-
185-
186184
# model with diagonal hessian
187-
φ(d) = ∇fk' * d + (d' * (D.d .* d)) / 2
185+
φ(d) = ∇fk' * d + (d' * (Dkσk .* d)) / 2
188186
mk(d) = φ(d) + ψ(d)
189187

190188
if spectral_test
191189
prox!(s, ψ, mν∇fk, ν)
192190
else
193-
iprox!(s, ψ, ∇fk, D)
191+
iprox!(s, ψ, ∇fk, Dkσk)
194192
end
195193

196-
# iprox!(s, ψ, ∇fk, D)
194+
if mk(s) > 1/eps(R)
195+
σk = σk * γ
196+
Dkσk .= D.d .+ σk
197+
DNorm = norm(D.d, Inf)
198+
ν = 1 / ((DNorm + σk) * (1 + θ))
199+
@. mν∇fk = -ν * ∇fk
200+
continue
201+
end
197202

198203
Complex_hist[k] += 1
199204
xkn .= xk .+ s
@@ -225,7 +230,7 @@ function R2DH(
225230

226231
σ_stat = (η2 ρk < Inf) ? "" : (ρk < η1 ? "" : "=")
227232

228-
if (verbose > 0) && (k % ptf == 0)
233+
if (verbose > 0) && ((k % ptf == 0) || (k == 1))
229234
#! format: off
230235
@info @sprintf "%6d %8.1e %8.1e %7.1e %8.1e %7.1e %7.1e %7.1e %1s" k fk hk sqrt_ξ_νInv ρk σk norm(xk) norm(s) σ_stat
231236
#! format: on
@@ -251,9 +256,9 @@ function R2DH(
251256
σk = σk * γ
252257
end
253258

254-
D.d .= summation ? D.d .+ σk : D.d .* σk
259+
Dkσk .= D.d .+ σk
255260
DNorm = norm(D.d, Inf)
256-
ν = 1 / DNorm
261+
ν = 1 / ((DNorm + σk) * (1 + θ))
257262

258263
tired = maxIter > 0 && k maxIter
259264
if !tired
@@ -284,12 +289,13 @@ function R2DH(
284289
outdict = Dict(
285290
:Fhist => Fobj_hist[1:k],
286291
:Hhist => Hobj_hist[1:k],
292+
:Time_hist => time_hist[1:k],
287293
:Chist => Complex_hist[1:k],
288294
:NonSmooth => h,
289295
:status => status,
290296
:fk => fk,
291297
:hk => hk,
292-
:ξ => ξ,
298+
:sqrt_ξ_νInv => sqrt_ξ_νInv,
293299
:elapsed_time => elapsed_time,
294300
)
295301

0 commit comments

Comments
 (0)