Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions approaches/composable-turing-models.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,28 @@ page-layout: full
:::

```{.julia .code-overflow-scroll}
using ComposableTuringIDModels, Distributions, Turing

# Renewal infections with an inline prior model
data = IDData(gen_distribution = Gamma(1.4, 1 / 0.38))

model = IDModel(
Renewal(data;
rt = AR(; ϵ_t = HierarchicalNormal(
std_prior = HalfNormal(0.1))),
initialisation_prior = Normal(log(1.0), 1.0)),

# Multiple observation layers:
# delay → ascertainment → negative-binomial noise
LatentDelay(
Ascertainment(
NegativeBinomialError(),
Intercept(Normal(log(0.4), 0.1))),
truncated(Normal(5.0, 2.0), 0.0, Inf)))

# Fit to case data with Turing's NUTS
using ComposableTuringIDModels, Distributions, Turing, Mooncake
using ADTypes: AutoMooncake

# Renewal infections with an autoregressive log-R_t prior
renewal = Renewal(;
generation_time = Gamma(1.4, 1 / 0.38),
rt = AR(; ϵ_t = HierarchicalNormal(std = HalfNormal(0.1))),
initialisation = Normal(log(1.0), 1.0))

# Observation layers: delay → ascertainment → negative-binomial noise
obs = LatentDelay(
Ascertainment(
NegativeBinomialError(),
Intercept(Normal(log(0.4), 0.1))),
truncated(Normal(5.0, 2.0), 0.0, Inf))

model = IDModel(renewal, obs)

# Fit to case data with Turing's NUTS (Mooncake AD)
chain = sample(as_turing_model(model, cases, length(cases)),
NUTS(), MCMCThreads(), 1_000, 2)
NUTS(0.95; adtype = AutoMooncake(; config = nothing)),
MCMCThreads(), 100, 2)
```

:::
Expand Down
14 changes: 5 additions & 9 deletions approaches/composed-distributions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ The model does not change, only the delays each case supplies.
### Censoring and modifiers compose as leaves

Real line-list delays are rarely clean, and the corrections are part of the model rather than a preprocessing step.
[CensoredDistributions.jl](https://censoreddistributions.epiaware.org/) supplies censoring leaves for primary-event censoring, interval censoring, and truncation.
[CensoredDistributions.jl](https://censoreddistributions.epiaware.org/dev/) supplies censoring leaves for primary-event censoring, interval censoring, and truncation.
[ModifiedDistributions.jl](https://modifieddistributions.epiaware.org/dev/) supplies modifier leaves that rescale, weight, or transform a delay.
Both are leaves like any other, so they slot into the tree and the composers peel through them to reach the free delay underneath.

Expand Down Expand Up @@ -187,18 +187,14 @@ Nothing is recomputed in separate post-processing that could drift from the mode
- [ModifiedDistributions.jl](https://modifieddistributions.epiaware.org/dev/) lets you
rescale, weight, or otherwise transform individual leaves without changing the
tree structure.
- [CensoredDistributions.jl](https://censoreddistributions.epiaware.org/) adds
- [CensoredDistributions.jl](https://censoreddistributions.epiaware.org/dev/) adds
the censoring layer for real line-list data.
- [LoweredDistributions.jl](https://lowereddistributions.epiaware.org/dev/) lowers
the same tree onto a phase-type chain or a CTMC, the bridge to compartmental
models.
- Fitting outside Turing, or fitting a plain struct alongside a tree?
[DistributionsInference.jl](https://github.com/EpiAware/DistributionsInference.jl)
hosts the PPL-neutral log-density and readback that `as_logdensity` and
`as_turing` build on: `distribution_priors` assembles priors the same way
`param_priors` does for a tree, and `distribution_params` reads a fitted
chain back to the estimated values by name, whatever fittable object it
came from.
- [DistributionsInference.jl](https://github.com/EpiAware/DistributionsInference.jl)
assembles PPL-neutral priors and reads a fitted chain back by name, for
fitting the tree (or any fittable struct) outside Turing.
- Ready to fit a full model with infection dynamics? See the
[composable Turing models approach](composable-turing-models.qmd).

Expand Down
14 changes: 11 additions & 3 deletions packages/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Status reflects where a package sits in its release cycle rather than a judgemen
<td class="data-name">
<a href="https://composableturingidmodels.epiaware.org/dev/">ComposableTuringIDModels.jl</a>
<a class="data-gh" href="https://github.com/EpiAware/ComposableTuringIDModels.jl" aria-label="ComposableTuringIDModels.jl on GitHub"><i class="bi bi-github"></i></a>
<span class="status-pill status-experimental">experimental</span>
<span class="status-pill status-maturing">maturing</span>
</td>
<td>Assemble infectious disease models from interchangeable infection and observation parts as a single Turing model. The package that ties the ecosystem together.</td>
</tr>
Expand All @@ -46,13 +46,13 @@ Status reflects where a package sits in its release cycle rather than a judgemen
<a class="data-gh" href="https://github.com/EpiAware/CensoredDistributions.jl" aria-label="CensoredDistributions.jl on GitHub"><i class="bi bi-github"></i></a>
<span class="status-pill status-maturing">maturing</span>
</td>
<td>Handle the interval censoring and truncation biases common in epidemiological delay data, wrapping any Distributions.jl distribution.</td>
<td>Handle the interval censoring and truncation biases common in epidemiological delay data, wrapping any Distributions.jl distribution, and convolve series of censored delays with <code>convolve_series</code>.</td>
</tr>
<tr data-category="distributions">
<td class="data-name">
<a href="https://composeddistributions.epiaware.org/dev/">ComposedDistributions.jl</a>
<a class="data-gh" href="https://github.com/EpiAware/ComposedDistributions.jl" aria-label="ComposedDistributions.jl on GitHub"><i class="bi bi-github"></i></a>
<span class="status-pill status-experimental">experimental</span>
<span class="status-pill status-maturing">maturing</span>
</td>
<td>Join the delays in a case's history into a single distribution that can simulate a case or be fitted to observed ones.</td>
</tr>
Expand All @@ -72,6 +72,14 @@ Status reflects where a package sits in its release cycle rather than a judgemen
</td>
<td>Rescale, weight, modify hazards, or transform a distribution, while keeping the full Distributions.jl interface.</td>
</tr>
<tr data-category="distributions">
<td class="data-name">
<a href="https://reparameteriseddistributions.epiaware.org/dev/">ReparameterisedDistributions.jl</a>
<a class="data-gh" href="https://github.com/EpiAware/ReparameterisedDistributions.jl" aria-label="ReparameterisedDistributions.jl on GitHub"><i class="bi bi-github"></i></a>
<span class="status-pill status-maturing">maturing</span>
</td>
<td>Express the same distribution under a different, equivalent parameterisation, so a model can be fitted in whatever form is most convenient and read back in your own.</td>
</tr>
<tr data-category="distributions">
<td class="data-name">
<a href="https://lowereddistributions.epiaware.org/dev/">LoweredDistributions.jl</a>
Expand Down
Loading