Skip to content

Commit e865647

Browse files
authored
Merge pull request #180 from JuliaDynamics/TestGenericEstimate
Test generic estimate
2 parents 8e5732a + ffc3464 commit e865647

File tree

13 files changed

+63
-38
lines changed

13 files changed

+63
-38
lines changed

examples/time_convergence_plot2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function save_coarse_data(prefix, K)
137137
compute_coarse_grid_quantities(f, 4; m = 24) # warm-up for precompilation
138138
for n in 2 .^ K
139139
print("Coarse+fine $n...")
140-
F, C = compute_coarse_grid_quantities(f, n; m = 24)
140+
C, F = compute_coarse_grid_quantities(f, n; m = 24)
141141
serialize("$prefix-$n-coarse.juliaserialize", C)
142142
serialize("$prefix-$n-fine.juliaserialize", F)
143143
println("done.")

src/Basis/IntervalHatBasis.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ end
151151

152152
Base.length(S::AverageZero{HatNP{T}}) where {T} = length(S.basis) - 1
153153

154-
weak_projection_error(B::HatNP) = 0.5 Float64(length(B)-1, RoundDown)
155-
aux_normalized_projection_error(B::HatNP) = 0.5 Float64(length(B)-1, RoundDown)
156-
strong_weak_bound(B::HatNP) = 2.0 Float64(length(B)-1, RoundDown)
154+
weak_projection_error(B::HatNP) = 0.5 Float64(length(B) - 1, RoundDown)
155+
aux_normalized_projection_error(B::HatNP) = 0.5 Float64(length(B) - 1, RoundDown)
156+
strong_weak_bound(B::HatNP) = 2.0 Float64(length(B) - 1, RoundDown)
157157
aux_weak_bound(B::HatNP) = 1.0
158158
weak_by_strong_and_aux_bound(B::HatNP) = (1.0, 1.0)
159159
bound_weak_norm_from_linalg_norm(B::HatNP) = @error "TODO"
@@ -238,7 +238,8 @@ end
238238

239239
function Dual(B::HatNP, D; ϵ = 0.0, max_iter = 100)
240240
@assert is_full_branch(D)
241-
results = collect(HatNPDualBranch(B.p, b, 1:length(B.p)-1; ϵ, max_iter) for b in branches(D))
241+
results =
242+
collect(HatNPDualBranch(B.p, b, 1:length(B.p)-1; ϵ, max_iter) for b in branches(D))
242243
x = vcat((result[1] for result in results)...)
243244
xlabel = vcat((result[2] for result in results)...)
244245
x′ = vcat((result[3] for result in results)...)

src/GenericEstimate.jl

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ end
105105
#
106106
# @deprecate contractmatrix norms_of_powers
107107

108-
"""
109-
This function returns the bound on the weak norm of the discretized operator
110-
"""
111-
function boundnorm(B::Basis, P::AbstractMatrix{Interval{T}}, m) where {T}
112-
W₁, W₂ = bound_weak_norm_from_linalg_norm(B)
113-
α₁ = bound_linalg_norm_L1_from_weak(B)
114-
α₂ = bound_linalg_norm_L∞_from_weak(B)
115-
C, tilde_C = contractmatrix(B, P, m)
116-
return (W₁ / α₁) * C + (W₂ / α₂) * tilde_C
117-
end
108+
# """
109+
# This function returns the bound on the weak norm of the discretized operator
110+
# """
111+
# function boundnorm(B::Basis, P::AbstractMatrix{Interval{T}}, m) where {T}
112+
# W₁, W₂ = bound_weak_norm_from_linalg_norm(B)
113+
# α₁ = bound_linalg_norm_L1_from_weak(B)
114+
# α₂ = bound_linalg_norm_L∞_from_weak(B)
115+
# C, tilde_C = contractmatrix(B, P, m)
116+
# return (W₁ / α₁) * C + (W₂ / α₂) * tilde_C
117+
# end
118+
#
119+
# @deprecate boundnorm
118120

119121
"""
120122
Uses different strategies to compute power norm bounds.
@@ -128,7 +130,7 @@ A vector of length m_extend is returned, such that norms[k] ≥ ||Q_h^k|_{U_h^0}
128130
function powernormbounds(B, D, m, m_extend; Q = DiscretizedOperator(B, D))
129131
normQ = opnormbound(B, weak_norm(B), Q)
130132
trivial_norms = norms_of_powers_trivial(normQ, m)
131-
computed_norms = norms_of_powers(weak_norm(B), m, Q, integral_covector(B))
133+
computed_norms = norms_of_powers(B, weak_norm(B), m, Q, integral_covector(B))
132134

133135
# not interesting at the moment
134136
#(dfly_strongs, dfly_norms) = norms_of_powers_dfly(B, D, m)
@@ -270,7 +272,16 @@ function compute_coarse_grid_quantities(f, n; m = 8)
270272
residualbound(B, weak_norm(B), Q, w), mag(integral_covector(B) * w - 1)
271273
time_norms = @elapsed norms = powernormbounds(B, D, Q = Q, m = m)
272274
time_dfly = @elapsed dfly_coefficients = dfly(strong_norm(B), aux_norm(B), D)
273-
return FineGridQuantities(
275+
return CoarseGridQuantities(
276+
B,
277+
D,
278+
norms,
279+
dfly_coefficients,
280+
time_assembling1,
281+
time_norms,
282+
time_dfly,
283+
),
284+
FineGridQuantities(
274285
B,
275286
D,
276287
normQ,
@@ -279,15 +290,6 @@ function compute_coarse_grid_quantities(f, n; m = 8)
279290
ε₂,
280291
time_assembling1 + time_assembling2,
281292
time_eigen1 + time_eigen2,
282-
),
283-
CoarseGridQuantities(
284-
B,
285-
D,
286-
norms,
287-
dfly_coefficients,
288-
time_assembling1,
289-
time_norms,
290-
time_dfly,
291293
)
292294
end
293295

test/TestBasis/TestBasisIndex.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
include("TestUlam.jl")
2+
include("TestAssembleHat.jl")
3+
include("TestHat.jl")
4+
include("TestHatNP.jl")
5+
include("TestUlam2DSP.jl")
26

37
include("TestFourierCommon.jl")
48
include("TestFourierAdjoint.jl")
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
v = ones(4)
6161
@test RigorousInvariantMeasures.change_of_basis(BU, BH, v) == ones(5)
6262

63-
63+
6464
@test RigorousInvariantMeasures.evaluate_integral(B, 1, Float64) == 0.25
65-
65+
6666
Q = DiscretizedOperator(B, D)
6767

68-
@test Q.L[:, 1] == [0.5; 0.25; 0; 0; 0]
69-
@test Q.L[:, 2] == [0.0; 0.25; 0.5; 0.25; 0]
68+
@test Q.L[:, 1] == [0.5; 0.25; 0; 0; 0]
69+
@test Q.L[:, 2] == [0.0; 0.25; 0.5; 0.25; 0]
7070
@test Q.L[:, 3] == [0.5; 0.25; 0.0; 0.25; 0.5]
7171
@test Q.L[:, 4] == [0; 0.25; 0.5; 0.25; 0.0]
7272
@test Q.L[:, 5] == [0; 0; 0; 0.25; 0.5]

test/TestEstimate.jl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
@testset "Estimator" begin
22
using IntervalArithmetic
33

4-
D = mod1_dynamic(x -> 2 * x)
5-
B = Ulam(32)
6-
P = RigorousInvariantMeasures.assemble(B, D; ϵ = 10^(-15), max_iter = 100, T = Float64)
4+
5+
function twoxexperiment(n)
6+
D = mod1_dynamic(x -> 2 * x)
7+
B = Ulam(32)
8+
Q = DiscretizedOperator(B, D)
9+
return B, D, Q
10+
end
11+
12+
FGQ, CGQ = RigorousInvariantMeasures.compute_coarse_grid_quantities(twoxexperiment, 64)
13+
14+
Q = DiscretizedOperator(CGQ.B, CGQ.D)
15+
norms = powernormbounds(CGQ.B, CGQ.D; Q = Q)
16+
17+
@test norms == CGQ.norms
18+
19+
norms_other = RigorousInvariantMeasures.powernormbounds(CGQ.B, CGQ.D, 8, 16; Q = Q)
20+
@test norms_other == norms
21+
22+
error, times = one_grid_estimate(CGQ, FGQ)
23+
@test error == 0.0
24+
25+
error, times = two_grid_estimate(CGQ, FGQ)
26+
@test error == 0.0
727

828
# C = RigorousInvariantMeasures.boundnorm(B, P, 10)
929

0 commit comments

Comments
 (0)