-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 15-functional-full-model
- Loading branch information
Showing
7 changed files
with
47 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters