From 3275f43f440ba7b5cf4ba28d378baea5595a8c62 Mon Sep 17 00:00:00 2001 From: rjbaral Date: Fri, 29 Sep 2023 16:47:35 -0700 Subject: [PATCH 1/2] added *correct* (per discussion) gradient nls-checking --- src/LMTR_alg.jl | 7 +++++++ src/LM_alg.jl | 9 ++++++++- test/runtests.jl | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/LMTR_alg.jl b/src/LMTR_alg.jl index 2f0d6ae1..ae6620f5 100644 --- a/src/LMTR_alg.jl +++ b/src/LMTR_alg.jl @@ -110,6 +110,9 @@ function LMTR( 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" @@ -140,6 +143,8 @@ function LMTR( 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 @@ -292,5 +297,7 @@ function LMTR( 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 diff --git a/src/LM_alg.jl b/src/LM_alg.jl index 161d76a1..f2a178b2 100644 --- a/src/LM_alg.jl +++ b/src/LM_alg.jl @@ -105,6 +105,9 @@ function LM( 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‖" "‖Jₖ‖²" "reg" @@ -133,6 +136,8 @@ function LM( 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 @@ -215,7 +220,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/ν) sqrt(ξ/ν) ρk σk norm(xk) norm(s) νInv σ_stat #! format: off end @@ -281,5 +286,7 @@ function LM( 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 diff --git a/test/runtests.jl b/test/runtests.jl index b63743b4..a288cbb6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -83,6 +83,8 @@ for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1"), (IndBallL0(10 * com @test typeof(out.dual_feas) == eltype(out.solution) @test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:Hhist]) @test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:SubsolverCounter]) + @test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:NLSGradHist]) + @test out.solver_specific[:NLSGradHist][end] == bpdn_nls.counters.neval_jprod_residual + bpdn_nls.counters.neval_jtprod_residual - 1 @test obj(bpdn_nls, out.solution) == out.solver_specific[:Fhist][end] @test h(out.solution) == out.solver_specific[:Hhist][end] @test out.status == :first_order @@ -106,6 +108,8 @@ for (h, h_name) ∈ ((NormL1(λ), "l1"),) @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:Hhist]) @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:SubsolverCounter]) + @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:NLSGradHist]) + @test LMTR_out.solver_specific[:NLSGradHist][end] == bpdn_nls.counters.neval_jprod_residual + bpdn_nls.counters.neval_jtprod_residual - 1 @test obj(bpdn_nls, LMTR_out.solution) == LMTR_out.solver_specific[:Fhist][end] @test h(LMTR_out.solution) == LMTR_out.solver_specific[:Hhist][end] @test LMTR_out.status == :first_order From 59df63cd4b715301a82a7c30697d3e9855c5a014 Mon Sep 17 00:00:00 2001 From: Dominique Date: Wed, 4 Oct 2023 09:47:29 -0400 Subject: [PATCH 2/2] Update src/LM_alg.jl --- src/LM_alg.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LM_alg.jl b/src/LM_alg.jl index f2a178b2..dc5c29e1 100644 --- a/src/LM_alg.jl +++ b/src/LM_alg.jl @@ -220,7 +220,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) sqrt(ξ) ρk σk norm(xk) norm(s) νInv σ_stat #! format: off end