Skip to content

Commit

Permalink
Merge branch 'main' into 15-functional-full-model
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 authored Feb 12, 2024
2 parents 2e6a14b + 4b33059 commit 0489715
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-EpiAware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
version: '1.10.0'
- name: Run unit tests for EpiAware
run: julia --project=EpiAware -e 'using Pkg; Pkg.test()'
run: julia --project=EpiAware -e 'using Pkg; Pkg.test(coverage = true)'
13 changes: 12 additions & 1 deletion EpiAware/test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "4e801d137527f7d9f5c027430e922fb6b4f9c643"
project_hash = "0b01aa91e53bb772f02a49192dfa1019eaa23f4b"

[[deps.ADTypes]]
git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245"
Expand Down Expand Up @@ -1263,6 +1263,17 @@ version = "0.1.7"
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.TestItemRunner]]
deps = ["Pkg", "TOML", "Test", "TestItems", "UUIDs"]
git-tree-sha1 = "7351f1f7389e048ce974b2c176513b817c94b15f"
uuid = "f8b46487-2199-4994-9208-9a1283c18c0a"
version = "0.2.2"

[[deps.TestItems]]
git-tree-sha1 = "8621ba2637b49748e2dc43ba3d84340be2938022"
uuid = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
version = "0.1.1"

[[deps.Tracker]]
deps = ["Adapt", "DiffRules", "ForwardDiff", "Functors", "LinearAlgebra", "LogExpFunctions", "MacroTools", "NNlib", "NaNMath", "Optimisers", "Printf", "Random", "Requires", "SpecialFunctions", "Statistics"]
git-tree-sha1 = "5c942be30a85ac75d14e9e527b55504031e1bbd3"
Expand Down
2 changes: 2 additions & 0 deletions EpiAware/test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
10 changes: 2 additions & 8 deletions EpiAware/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using Test
using EpiAware
using Distributions
using LinearAlgebra
using Turing, DynamicPPL
using TestItemRunner

include("test_utilities.jl")
include("test_epimodel.jl")
include("test_latent-processes.jl")
@run_package_tests
25 changes: 3 additions & 22 deletions EpiAware/test/test_epimodel.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@

@testset "EpiModel constructor" begin
gen_int = [0.2, 0.3, 0.5]
delay_int = [0.1, 0.4, 0.5]
cluster_coeff = 0.8
time_horizon = 10

model = EpiModel(gen_int, delay_int, cluster_coeff, time_horizon)

@test length(model.gen_int) == 3
@test length(model.delay_int) == 3
@test model.cluster_coeff == 0.8
@test model.len_gen_int == 3
@test model.len_delay_int == 3

@test sum(model.gen_int) 1
@test sum(model.delay_int) 1

@test size(model.delay_kernel) == (time_horizon, time_horizon)
end

@testset "EpiModel constructor" begin
@testitem "EpiModel constructor" begin
gen_int = [0.2, 0.3, 0.5]
delay_int = [0.1, 0.4, 0.5]
cluster_coeff = 0.8
Expand All @@ -39,7 +19,8 @@ end
@test size(model.delay_kernel) == (time_horizon, time_horizon)
end

@testset "EpiModel function" begin
@testitem "EpiModel function" begin
using LinearAlgebra
recent_incidence = [10, 20, 30]
Rt = 1.5

Expand Down
46 changes: 21 additions & 25 deletions EpiAware/test/test_latent-processes.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@

@testitem "Testing random_walk against theoretical properties" begin
using DynamicPPL, Turing
n = 5
model = random_walk(n)
fixed_model = fix(model, (σ²_RW = 1.0,)) #Fixing the standard deviation of the random walk process
n_samples = 1000
samples_day_5 =
sample(fixed_model, Prior(), n_samples) |>
chn -> mapreduce(vcat, generated_quantities(fixed_model, chn)) do gen
gen[1][5] #Extracting day 5 samples
end
#Check statistics are within 5 sigma
#Theoretically, after 5 steps distribution is N(0, var = 5)
theoretical_std_of_empiral_mean = sqrt(5 / n_samples)
@test mean(samples_day_5) < 5 * theoretical_std_of_empiral_mean &&
mean(samples_day_5) > -5 * theoretical_std_of_empiral_mean

@testset "Testing random_walk function" begin
# Test case 1: Testing against theoretical properties
@testset "Test case 1" begin
n = 5
model = random_walk(n)
fixed_model = fix(model, (σ²_RW = 1.0,)) #Fixing the standard deviation of the random walk process
n_samples = 1000
samples_day_5 =
sample(fixed_model, Prior(), n_samples) |>
chn -> mapreduce(vcat, generated_quantities(fixed_model, chn)) do gen
gen[1][5] #Extracting day 5 samples
end
#Check statistics are within 5 sigma
#Theoretically, after 5 steps distribution is N(0, var = 5)
theoretical_std_of_empiral_mean = sqrt(5 / n_samples)
@test mean(samples_day_5) < 5 * theoretical_std_of_empiral_mean &&
mean(samples_day_5) > -5 * theoretical_std_of_empiral_mean
#Theoretically, after 5 steps distribution is N(0, var = 5)

#Theoretically, after 5 steps distribution is N(0, var = 5)
theoretical_std_of_empiral_var = std(Chisq(5)) / sqrt(n_samples)

theoretical_std_of_empiral_var = std(Chisq(5)) / sqrt(n_samples)

@info "var = $(var(samples_day_5)); theoretical_std_of_empiral_var = $(theoretical_std_of_empiral_var)"
@test (var(samples_day_5) - 5) < 5 * theoretical_std_of_empiral_var &&
(var(samples_day_5) - 5) > -5 * theoretical_std_of_empiral_var

end
@info "var = $(var(samples_day_5)); theoretical_std_of_empiral_var = $(theoretical_std_of_empiral_var)"
@test (var(samples_day_5) - 5) < 5 * theoretical_std_of_empiral_var &&
(var(samples_day_5) - 5) > -5 * theoretical_std_of_empiral_var

end
10 changes: 6 additions & 4 deletions EpiAware/test/test_utilities.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Testing scan function with addition" begin
@testitem "Testing scan function with addition" begin
# Test case 1: Testing with addition function
function add(a, b)
return a + b, a + b
Expand All @@ -12,7 +12,7 @@
@test carry == expected_carry
end

@testset "Testing scan function with multiplication" begin
@testitem "Testing scan function with multiplication" begin
# Test case 2: Testing with multiplication function
function multiply(a, b)
return a * b, a * b
Expand All @@ -27,7 +27,8 @@ end
@test carry == expected_carry
end

@testset "Testing create_discrete_pmf function" begin
@testitem "Testing create_discrete_pmf function" begin
using Distributions
# Test case 1: Testing with a non-negative distribution
@testset "Test case 1" begin
dist = Normal()
Expand Down Expand Up @@ -79,7 +80,8 @@ end
end

end
@testset "Testing growth_rate_to_reproductive_ratio function" begin

@testitem"Testing growth_rate_to_reproductive_ratio function" begin
#Test that zero exp growth rate imples R0 = 1
@testset "Test case 1" begin
r = 0
Expand Down

0 comments on commit 0489715

Please sign in to comment.