Skip to content

Commit

Permalink
move epsilon.jl test to deterministic, clean deterministic output test
Browse files Browse the repository at this point in the history
  • Loading branch information
AldoGl committed May 10, 2024
1 parent 07abfbb commit 30cc60e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
18 changes: 8 additions & 10 deletions test/deterministic/deterministic_ouput_t1_t5.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,29 +27,28 @@
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

for fieldname in fieldnames(typeof(data))
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

Expand Down
27 changes: 27 additions & 0 deletions test/deterministic/epsilon.jl
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions test/deterministic/runtests_deterministic.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 0 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 0 additions & 28 deletions test/utils/epsilon.jl

This file was deleted.

0 comments on commit 30cc60e

Please sign in to comment.