diff --git a/src/R2_alg.jl b/src/R2_alg.jl index 91c54543..d23e4b0c 100644 --- a/src/R2_alg.jl +++ b/src/R2_alg.jl @@ -69,9 +69,10 @@ function R2( f::F, ∇f!::G, h::H, - options::ROSolverOptions, - x0::AbstractVector, -) where {F <: Function, G <: Function, H} + options::ROSolverOptions{R}, + x0::AbstractVector{R}, + neg_tol::R = -eps(R)^(1/3) , +) where {F <: Function, G <: Function, H, R <: Real} start_time = time() elapsed_time = 0.0 ϵ = options.ϵ @@ -83,6 +84,7 @@ function R2( η2 = options.η2 ν = options.ν γ = options.γ + neg_tol < 0 || error("neg_tol must be negative") if verbose == 0 ptf = Inf @@ -146,13 +148,14 @@ 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 neg_tol <= ξ <= ϵ^2 optimal = true + ξ = abs(ξ) continue end + ξ > 0 || error("R2: prox-gradient step should produce a decrease but ξ = $(ξ)") xkn .= xk .+ s fkn = f(xkn) hkn = h(xkn)