From 30cc60e805303363832f6985bd83e46176e481b6 Mon Sep 17 00:00:00 2001 From: Aldo Date: Fri, 10 May 2024 16:47:18 +0200 Subject: [PATCH] move epsilon.jl test to deterministic, clean deterministic output test --- .../deterministic_ouput_t1_t5.jl | 18 ++++++------ test/deterministic/epsilon.jl | 27 ++++++++++++++++++ test/deterministic/runtests_deterministic.jl | 1 + test/runtests.jl | 2 -- test/utils/epsilon.jl | 28 ------------------- 5 files changed, 36 insertions(+), 40 deletions(-) create mode 100644 test/deterministic/epsilon.jl delete mode 100644 test/utils/epsilon.jl diff --git a/test/deterministic/deterministic_ouput_t1_t5.jl b/test/deterministic/deterministic_ouput_t1_t5.jl index edaf32c..f76f96a 100644 --- a/test/deterministic/deterministic_ouput_t1_t5.jl +++ b/test/deterministic/deterministic_ouput_t1_t5.jl @@ -1,7 +1,6 @@ @testset "time 1 and 5 deterministic" begin dir = @__DIR__ - T = 1 parameters = BeforeIT.AUSTRIA2010Q1.parameters initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions @@ -28,18 +27,17 @@ end end - - T = 4 - parameters = matread(joinpath(dir, "../../data/austria/parameters/2010Q1.mat")) - initial_conditions = matread(joinpath(dir, "../../data/austria/initial_conditions/2010Q1.mat")) + T = 5 + parameters = BeforeIT.AUSTRIA2010Q1.parameters + initial_conditions = BeforeIT.AUSTRIA2010Q1.initial_conditions model = BeforeIT.initialise_model(parameters, initial_conditions, T) data = BeforeIT.initialise_data(model) - for t in 1:T-1 + for t in 1:T BeforeIT.one_epoch!(model; multi_threading = false) BeforeIT.update_data!(data, model) end - output_t5 = matread(joinpath(dir, "../matlab_code/output_t5.mat"))list + output_t5 = matread(joinpath(dir, "../matlab_code/output_t5.mat")) # confront results between julia and matlab code @@ -47,10 +45,10 @@ julia_output = getfield(data, fieldname) matlab_output = output_t5[string(fieldname)] - if length(size(julia_output)) == 1 - @test isapprox(julia_output, matlab_output', rtol = 1e-4) + if length(julia_output) == 6 + @test isapprox(julia_output[2:end], matlab_output', rtol = 1e-4) else - @test isapprox(julia_output, matlab_output, rtol = 1e-5) + @test isapprox(julia_output[2:end, :], matlab_output, rtol = 1e-5) end end diff --git a/test/deterministic/epsilon.jl b/test/deterministic/epsilon.jl new file mode 100644 index 0000000..47c12fb --- /dev/null +++ b/test/deterministic/epsilon.jl @@ -0,0 +1,27 @@ +using BeforeIT +using Test +import Random: randn + + +function randn(n1::Int, n2::Int) + return ones(n1, n2) +end + +# Define a fixed covariance matrix +C = [ + 2.0 0.5 0.3 + 0.5 1.5 0.2 + 0.3 0.2 1.0 +] + +# results from original matlab code with rand = false +expected_eps_Y_EA = 1.4142135623731 +expected_eps_E = 1.52615733054913 +expected_eps_I = 1.29014186522609 + +eps_Y_EA, eps_E, eps_I = BeforeIT.epsilon(C) + + +@test isapprox(eps_Y_EA, expected_eps_Y_EA) +@test isapprox(eps_E, expected_eps_E) +@test isapprox(eps_I, expected_eps_I) diff --git a/test/deterministic/runtests_deterministic.jl b/test/deterministic/runtests_deterministic.jl index 207c22c..067b0f0 100644 --- a/test/deterministic/runtests_deterministic.jl +++ b/test/deterministic/runtests_deterministic.jl @@ -1,4 +1,5 @@ @warn "making the model deterministic all subsequent calls to the model will be deterministic." +include("epsilon.jl") include("make_model_deterministic.jl") include("initialize_deterministic.jl") include("one_epoch_deterministic.jl") diff --git a/test/runtests.jl b/test/runtests.jl index aa345bc..b2f5abe 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,11 +1,9 @@ using BeforeIT, Test #utils -include("utils/epsilon.jl") include("utils/positive.jl") include("utils/randpl.jl") include("utils/nfvar3_and_estimate.jl") - include("utils/estimations.jl") # search_and_matching diff --git a/test/utils/epsilon.jl b/test/utils/epsilon.jl deleted file mode 100644 index 82c9621..0000000 --- a/test/utils/epsilon.jl +++ /dev/null @@ -1,28 +0,0 @@ -using BeforeIT -using Test -import Random: randn - -@testset "test epsilon" begin - function randn(n1::Int, n2::Int) - return ones(n1, n2) - end - - # Define a fixed covariance matrix - C = [ - 2.0 0.5 0.3 - 0.5 1.5 0.2 - 0.3 0.2 1.0 - ] - - # results from original matlab code with rand = false - expected_eps_Y_EA = 1.4142135623731 - expected_eps_E = 1.52615733054913 - expected_eps_I = 1.29014186522609 - - eps_Y_EA, eps_E, eps_I = BeforeIT.epsilon(C) - - - @test isapprox(eps_Y_EA, expected_eps_Y_EA) - @test isapprox(eps_E, expected_eps_E) - @test isapprox(eps_I, expected_eps_I) -end \ No newline at end of file