Skip to content

Commit

Permalink
Issue 408: ARMA and ARIMA models (#438)
Browse files Browse the repository at this point in the history
* draft MA method

* draft MA methd

* use IDD for epsilon in all models

* add MA benchmark

* Add docs and  tests for IDD

* make episilon_t a arg of the latent model constructors

* improve MA correctness

* fully import EpiAwareUtils

* add a test for IDD

* add tests for MA.jl

* add doc tests and unit tests + start on helper fn

* more updatres to AR appraoc

* chase down partial arg changes

* clean up AR

* clean up and add arma and arima helpers

* Contributions towards Arma/Arima models (#531)

* Patch: Switch to fork of benchmarkCI (#520)

* patch to fork of benchmarkCI

* put fork version of BenchmarkCI in [sources]

* swap order

* add EpiAware [source]

* fix path

* rm benchmarkCI from project

* Patch fix: add `Manifest.toml` to benchmarking (#524)

* trigger

* Update benchmark.yaml

* Update benchmark.yaml

* commit benchmark Manifest

* try alternate approach

* Update benchmark.yaml

* Update EpiMethod.jl

* Update benchmark.yaml

* change baseline to origin/main

* remove trigger

* rm other trigger

* Issue 465: Add an infection generating model for ODE problems (#510)

* CompatHelper: bump compat for Turing to 0.35 for package EpiAware, (drop existing compat) (#516)

* CompatHelper: bump compat for Turing to 0.35 for package EpiAware, (drop existing compat)

* Update Project.toml

* fix Project.toml

---------

Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: Sam Abbott <[email protected]>
Co-authored-by: Samuel Brand <[email protected]>
Co-authored-by: Samuel Brand <[email protected]>

* CompatHelper: bump compat for DynamicPPL to 0.30 for package EpiAware, (drop existing compat) (#528)

Co-authored-by: CompatHelper Julia <[email protected]>

* rename IDD -> IID

* rename test file

* Issue 529: Create null Latent model (#530)

* Null Latent model

* Null Latent model

* fix doctest

* fix generate_epiaware unit tests

New usage of RW

* fix turing method test

underlying std of step size changed name

* fix broadcast test

Underlying std param changed name

* fix HN unit test

Default std prior had changed

* fix AR unit tests

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: Sam Abbott <[email protected]>

* revert define_ namming

* clean out repeated utils from merge

* fix MA tests

* fix RW tests - feel made about RandomWalk vs AR naming

* fix remaining unit tests that aren't doctests

* update latent recovery test

* try and fix doctests automatically

* update all doctests to output nothing - this is awful

* add doctests for arima and arma

* fix doctest

* clean up deps

* update replication studies

* add interface tests for combination functions and add benchmarks

* add some basic theoretical properties tests

* name change IDD -> IID benchmarks

* moving all the constructors because this PR is too contained

* catch missing using

* update iid benchmark:

* update extraction

* remove old param namme from case study

* get the dot

* get the dot

* fix initial guess point for MAP opt

* Update index.jl

* add a compile time branch for HN

* add a compile time branch for HN

* update test

* add a new constructor to get old default behaviour

* update docs

* update docs - using the structs for priors is very brittle

* reorder prior plots

---------

Co-authored-by: Samuel Brand <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: Samuel Brand <[email protected]>
  • Loading branch information
5 people authored Dec 12, 2024
1 parent 8dc444f commit d7b7b3b
Show file tree
Hide file tree
Showing 42 changed files with 977 additions and 318 deletions.
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 d7b7b3b

Please sign in to comment.