Skip to content

Commit a4e5a84

Browse files
committed
Hopefully more robust convergence estimation
1 parent bcdd9a4 commit a4e5a84

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ ArnoldiMethod = "ec485272-7323-5ecc-a04f-4719b315124d"
3737
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
3838
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
3939
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
40+
RollingFunctions = "b0e4dd01-7b14-53d8-9b45-175a3e362653"
4041
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4142
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
4243

4344
[targets]
44-
test = ["Test", "ArnoldiMethod", "PrettyTables", "Random", "ProgressMeter", "UnicodePlots"]
45+
test = ["Test", "ArnoldiMethod", "PrettyTables", "Random", "RollingFunctions", "ProgressMeter", "UnicodePlots"]

test/derivative_accuracy_utils.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ using PrettyTables
55
using ProgressMeter
66
using UnicodePlots
77

8+
using RollingFunctions
9+
810
function test_derivatives(R::AbstractQuasiMatrix,
911
f::Function, g::Function, h::Function)
1012
r = axes(R,1)
@@ -38,18 +40,31 @@ function test_derivatives(R::AbstractQuasiMatrix,
3840
R,fv,gv,hv,hv′,δgv,δhv,δhv′
3941
end
4042

43+
function estimate_convergence_rate(ρ, ϵ)
44+
i = findall(!iszero, ϵ)
45+
x = log10.(ρ[i])
46+
y = log10.(abs.(ϵ[i]))
47+
48+
f = (x,y) -> ([x ones(length(x))] \ y)[1]
49+
50+
# Find all slopes for consecutive groups of three errors
51+
slopes = rolling(f, x, y, 3)
52+
e = findfirst(s -> s < 0, slopes)
53+
if e !== nothing && e > 5
54+
slopes = slopes[1:max(1,e-1)]
55+
end
56+
57+
maximum(slopes)
58+
end
59+
4160
function error_slopes(hs, ϵ, names, verbosity=0)
4261
loghs = log10.(hs)
4362
logϵ = log10.(abs.(ϵ))
4463
n = size(logϵ,2)
4564

4665
slopes = zeros(n)
4766
for j = 1:n
48-
# To avoid the effect of round-off errors on the order
49-
# estimation.
50-
i = argmin(abs.(ϵ[:,j]))
51-
52-
slopes[j] = ([loghs[1:i] ones(i)] \ logϵ[1:i,j])[1]
67+
slopes[j] = estimate_convergence_rate(hs, ϵ[:,j])
5368
end
5469

5570
if verbosity > 0

test/fedvr/derivatives.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ end
163163
# The convergence rate should be order - 1 (polynomial order =
164164
# polynomial degree + 1), but since the error slope fitting is a
165165
# bit error prone, we require that it is greater than order - 2.5.
166-
@test_broken all(slopes[:,1] .> oo .- 2.5)
166+
@test all(slopes[:,1] .> oo .- 2.5)
167167
@test all(slopes[:,1] .> oo .- 3.5)
168168
# Since the approximation to h is calculated by computing ∇∇f, we
169169
# lose one order extra, compared to ∇²f.
170-
@test_broken all(slopes[:,2] .> oo .- 3.5)
170+
@test all(slopes[:,2] .> oo .- 3.5)
171171
@test all(slopes[:,2] .> oo .- 4.5)
172-
@test_broken all(slopes[:,3] .> oo .- 2.5)
172+
@test all(slopes[:,3] .> oo .- 2.5)
173173
@test all(slopes[:,3] .> oo .- 4.0)
174174
end

0 commit comments

Comments
 (0)