Skip to content

Commit

Permalink
Merge branch 'main' into latest-analysis2
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 committed Dec 12, 2024
2 parents ecc293c + 173d96e commit c36add2
Show file tree
Hide file tree
Showing 45 changed files with 982 additions and 320 deletions.
2 changes: 1 addition & 1 deletion EpiAware/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EpiAware"
uuid = "b2eeebe4-5992-4301-9193-7ebc9f62c855"
authors = ["Samuel Abbott <[email protected]>", "Samuel Brand <[email protected]>", "Zachary Susswein <[email protected]>"]
version = "0.1.0-DEV"
version = "0.2.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
13 changes: 7 additions & 6 deletions EpiAware/docs/src/showcase/replications/chatzilena-2019/index.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.20.0
# v0.20.3

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -428,8 +428,8 @@ We define the AR(1) process by matching means of `HalfNormal` prior distribution
# ╔═╡ 71a26408-1c26-46cf-bc72-c6ba528dfadd
ar = AR(
damp_priors = [HalfNormal(mean(sampled_AR_damps))],
std_prior = HalfNormal(mean(sampled_AR_stds)),
init_priors = [Normal(0, 0.001)]
init_priors = [Normal(0, 0.001)],
ϵ_t = HierarchicalNormal(std_prior = HalfNormal(mean(sampled_AR_stds)))
)

# ╔═╡ e1ffdaf6-ca2e-405d-8355-0d8848d005b0
Expand Down Expand Up @@ -578,9 +578,10 @@ rand(stochastic_mdl)
initial_guess = [[mean(chn[]),
mean(chn[]),
mean(chn[:S₀]),
mean(ar.std_prior),
mean(ar.init_prior)[1],
mean(ar.damp_prior)[1]]
mean(ar.damp_prior)[1],
mean(ar.ϵ_t.std_prior)
]
zeros(13)]

# ╔═╡ 685221ea-f268-4ddc-937f-e7620d065c28
Expand Down Expand Up @@ -611,7 +612,7 @@ chn2 = sample(
describe(chn2)

# ╔═╡ 37a016d8-8384-41c9-abdd-23e88b1f988d
pairplot(chn2[[, , :S₀, Symbol(mdl_prefix * ".σ_AR"),
pairplot(chn2[[, , :S₀, Symbol(mdl_prefix * ".std"),
Symbol(mdl_prefix * ".ar_init[1]"), Symbol(mdl_prefix * ".damp_AR[1]")]])

# ╔═╡ 7df5d669-d3a2-4a66-83c3-f8618e39bec6
Expand Down
20 changes: 10 additions & 10 deletions EpiAware/docs/src/showcase/replications/mishra-2020/index.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.20.0
# v0.20.3

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -114,10 +114,10 @@ In _Mishra et al_ the standard deviation of the _stationary distribution_ of $Z_

# ╔═╡ c88bbbd6-0101-4c04-97c9-c5887ef23999
ar = AR(
damp_priors = reverse([truncated(Normal(0.8, 0.05), 0, 1),
truncated(Normal(0.1, 0.05), 0, 1)]),
std_prior = HalfNormal(0.5),
init_priors = [Normal(-1.0, 0.1), Normal(-1.0, 0.5)]
damp_priors = [truncated(Normal(0.1, 0.05), 0, 1),
truncated(Normal(0.8, 0.05), 0, 1)],
init_priors = [Normal(-1.0, 0.1), Normal(-1.0, 0.5)],
ϵ_t = HierarchicalNormal(std_prior = HalfNormal(0.5))
)

# ╔═╡ 31ee2757-0409-45df-b193-60c552797a3d
Expand Down Expand Up @@ -561,11 +561,11 @@ let
sub_chn = inference_results.samples[inference_results.samples.name_map.parameters[[1:5;
end]]]
fig = pairplot(sub_chn)
lines!(fig[1, 1], ar.std_prior, label = "Prior")
lines!(fig[2, 2], ar.init_prior.v[1], label = "Prior")
lines!(fig[3, 3], ar.init_prior.v[2], label = "Prior")
lines!(fig[4, 4], ar.damp_prior.v[1], label = "Prior")
lines!(fig[5, 5], ar.damp_prior.v[2], label = "Prior")
lines!(fig[1, 1], ar.init_prior.v[1], label = "Prior")
lines!(fig[2, 2], ar.init_prior.v[2], label = "Prior")
lines!(fig[3, 3], ar.damp_prior.v[1], label = "Prior")
lines!(fig[4, 4], ar.damp_prior.v[2], label = "Prior")
lines!(fig[5, 5], ar.ϵ_t.std_prior, label = "Prior")
lines!(fig[6, 6], epi.initialisation_prior, label = "Prior")

fig
Expand Down
43 changes: 28 additions & 15 deletions EpiAware/src/EpiAwareUtils/HalfNormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,62 @@ Create a half-normal prior distribution with the specified mean.
# Examples:
```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
using EpiAware, Distributions
hn = HalfNormal(1.0)
nothing
# output
EpiAware.EpiAwareUtils.HalfNormal{Float64}(μ=1.0)
```
# filter out all the values that are less than 0
```jldoctest HalfNormal; filter = r\"\b\d+(\.\d+)?\b\" => \"*\"
```jldoctest HalfNormal; output = false
rand(hn)
nothing
# output
0.4508533245229199
```
```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
cdf(hn, 2)
nothing
# output
0.8894596502772643
```
```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
quantile(hn, 0.5)
nothing
# output
0.8453475393951495
```
```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
logpdf(hn, 2)
nothing
# output
-3.1111166111445083
```
```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
mean(hn)
nothing
# output
1.0
```
```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
var(hn)
nothing
# output
0.5707963267948966
```
"
struct HalfNormal{T <: Real} <: ContinuousUnivariateDistribution
Expand Down
30 changes: 20 additions & 10 deletions EpiAware/src/EpiAwareUtils/SafeNegativeBinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ parameterisation is useful for specifying the distribution in a way that is easi
# Examples:
```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
using EpiAware, Distributions
bigμ = exp(48.0) #Large value of μ
Expand All @@ -37,32 +37,42 @@ bigμ = exp(48.0) #Large value of μ
p = bigμ / σ²
r = bigμ * p / (1 - p)
d = SafeNegativeBinomial(r, p)
nothing
# output
EpiAware.EpiAwareUtils.SafeNegativeBinomial{Float64}(r=20.0, p=2.85032816548187e-20)
```
```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
cdf(d, 100)
nothing
# output
0.0
```
```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
logpdf(d, 100)
nothing
# output
-850.1397180331871
```
```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
mean(d)
nothing
# output
7.016735912097631e20
```
```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
var(d)
nothing
# output
2.4617291430060293e40
```
"
struct SafeNegativeBinomial{T <: Real} <: SafeDiscreteUnivariateDistribution
Expand Down
30 changes: 20 additions & 10 deletions EpiAware/src/EpiAwareUtils/SafePoisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,47 @@ when the mean is too large.
# Examples:
```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
using EpiAware, Distributions
bigλ = exp(48.0) #Large value of λ
d = SafePoisson(bigλ)
nothing
# output
EpiAware.EpiAwareUtils.SafePoisson{Float64}(λ=7.016735912097631e20)
```
```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
cdf(d, 2)
nothing
# output
0.0
```
```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
logpdf(d, 100)
nothing
# output
-7.016735912097631e20
```
```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
mean(d)
nothing
# output
7.016735912097631e20
```
```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
var(d)
nothing
# output
7.016735912097631e20
```
"
struct SafePoisson{T <: Real} <: SafeDiscreteUnivariateDistribution
Expand Down
55 changes: 12 additions & 43 deletions EpiAware/src/EpiAwareUtils/censored_pmf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,17 @@ Raises:
# Examples
```jldoctest filter
```jldoctest; output = false
using Distributions
using EpiAware.EpiAwareUtils
dist = Exponential(1.0)
censored_pmf(dist, Val(:single_censored); D = 10) |>
p -> round.(p, digits=3)
censored_pmf(dist, Val(:single_censored); D = 10)
nothing
# output
10-element Vector{Float64}:
0.393
0.383
0.141
0.052
0.019
0.007
0.003
0.001
0.0
0.0
```
"
function censored_pmf(dist::Distribution,
Expand Down Expand Up @@ -122,28 +112,17 @@ to nearest multiple of `Δd`.
# Examples
```jldoctest filter
```jldoctest filter; output = false
using Distributions
using EpiAware.EpiAwareUtils
dist = Exponential(1.0)
censored_cdf(dist; D = 10) |>
p -> round.(p, digits=3)
censored_cdf(dist; D = 10)
nothing
# output
11-element Vector{Float64}:
0.0
0.368
0.767
0.914
0.969
0.988
0.996
0.998
0.999
1.0
1.0
```
"
function censored_cdf(dist::Distribution; Δd = 1.0, D = nothing, upper = 0.999)
Expand Down Expand Up @@ -184,27 +163,17 @@ to nearest multiple of `Δd`.
# Examples
```jldoctest filter
```jldoctest filter; output = false
using Distributions
using EpiAware.EpiAwareUtils
dist = Exponential(1.0)
censored_pmf(dist; D = 10) |>
p -> round.(p, digits=3)
censored_pmf(dist; D = 10)
nothing
# output
10-element Vector{Float64}:
0.368
0.4
0.147
0.054
0.02
0.007
0.003
0.001
0.0
0.0
```
"
function censored_pmf(dist::Distribution; Δd = 1.0, D = nothing, upper = 0.99)
Expand Down
Loading

0 comments on commit c36add2

Please sign in to comment.