diff --git a/src/R2_alg.jl b/src/R2_alg.jl index 91c54543..4d9ba7b4 100644 --- a/src/R2_alg.jl +++ b/src/R2_alg.jl @@ -69,12 +69,13 @@ function R2( f::F, ∇f!::G, h::H, - options::ROSolverOptions, - x0::AbstractVector, -) where {F <: Function, G <: Function, H} + options::ROSolverOptions{R}, + x0::AbstractVector{R}, +) where {F <: Function, G <: Function, H, R <: Real} start_time = time() elapsed_time = 0.0 ϵ = options.ϵ + neg_tol = options.neg_tol verbose = options.verbose maxIter = options.maxIter maxTime = options.maxTime @@ -146,13 +147,13 @@ function R2( Complex_hist[k] += 1 mks = mk(s) ξ = hk - mks + max(1, abs(hk)) * 10 * eps() - ξ > 0 || error("R2: prox-gradient step should produce a decrease but ξ = $(ξ)") - - if sqrt(ξ) < ϵ + + if (ξ < 0 && sqrt(-ξ) ≤ -neg_tol) || (ξ ≥ 0 && sqrt(ξ) ≤ ϵ) optimal = true continue end + ξ > 0 || error("R2: prox-gradient step should produce a decrease but ξ = $(ξ)") xkn .= xk .+ s fkn = f(xkn) hkn = h(xkn) diff --git a/src/input_struct.jl b/src/input_struct.jl index 56e94663..a111065f 100644 --- a/src/input_struct.jl +++ b/src/input_struct.jl @@ -2,6 +2,7 @@ export ROSolverOptions mutable struct ROSolverOptions{R} ϵ::R # termination criteria + neg_tol::R # tolerance when ξ < 0 Δk::R # trust region radius verbose::Int # print every so often maxIter::Int # maximum amount of inner iterations @@ -17,6 +18,7 @@ mutable struct ROSolverOptions{R} function ROSolverOptions{R}(; ϵ::R = √eps(R), + neg_tol::R = eps(R)^(1 / 3), Δk::R = one(R), verbose::Int = 0, maxIter::Int = 10000, @@ -26,11 +28,24 @@ mutable struct ROSolverOptions{R} η2::R = R(0.9), α::R = 1 / eps(R), ν::R = 1.0e-3, - γ::R = R(3.0), + γ::R = R(3), θ::R = R(1e-3), - β::R = R(10.0), + β::R = R(10), ) where {R <: Real} - return new{R}(ϵ, Δk, verbose, maxIter, maxTime, σmin, η1, η2, α, ν, γ, θ, β) + @assert ϵ ≥ 0 + @assert neg_tol ≥ 0 + @assert Δk > 0 + @assert verbose ≥ 0 + @assert maxIter ≥ 0 + @assert maxTime ≥ 0 + @assert σmin ≥ 0 + @assert 0 < η1 < η2 < 1 + @assert α > 0 + @assert ν > 0 + @assert γ > 1 + @assert θ > 0 + @assert β ≥ 1 + return new{R}(ϵ, neg_tol, Δk, verbose, maxIter, maxTime, σmin, η1, η2, α, ν, γ, θ, β) end end