Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docstrings for all epimodel types and generate_latent_infs plus named arguments for constructors #138

Merged
merged 9 commits into from
Mar 12, 2024
15 changes: 14 additions & 1 deletion EpiAware/src/abstract-types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ abstract type AbstractLatentModel <: AbstractModel end

abstract type AbstractObservationModel <: AbstractModel end

function generate_latent_infs(epi_model::AbstractEpiModel, latent_model)
@doc raw"""
Generate latent infections based on the given epidemiological model and a latent process
path ``Z_t``.

# Arguments
seabbs marked this conversation as resolved.
Show resolved Hide resolved
- `epi_model::DirectInfections`: The epidemiological model used to generate latent infections.
- `Z_t`: The noise term.

# Returns
- An array of generated latent infections.

# Example
"""
function generate_latent_infs(epi_model::AbstractEpiModel, Z_t)
@info "No concrete implementation for `generate_latent_infs` is defined."
return nothing
end
Expand Down
4 changes: 0 additions & 4 deletions EpiAware/src/docstrings.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
@template (FUNCTIONS, METHODS, MACROS) = """
$(TYPEDSIGNATURES)
$(DOCSTRING)

---
## Methods
$(METHODLIST)
"""

@template (TYPES) = """
Expand Down
52 changes: 48 additions & 4 deletions EpiAware/src/epimodels/directinfections.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
struct DirectInfections{S <: Sampleable} <: AbstractEpiModel
@doc raw"
Defines the model for latent infections as a transformation on a sampled latent model.

## Mathematical specification

If ``Z_t`` is a realisation of the latent model, then the latent infections are given by

```math
I_t = g(Z_t).
```

where ``g`` is a transformation function.

## Constructor

`DirectInfections` can be constructed by passing an `EpiData` object and and subtype of
[`Distributions.Sampleable`](https://juliastats.org/Distributions.jl/latest/types/#Sampleable).
seabbs marked this conversation as resolved.
Show resolved Hide resolved
seabbs marked this conversation as resolved.
Show resolved Hide resolved

## Example usage with `generate_latent_infs`

Create a Turing model for the latent infections conditional on the sample path of a white
noise latent process.

```julia
using Distributions, Turing, EpiAware
gen_int = [0.2, 0.3, 0.5]
transformation = exp

# Create an EpiData object
data = EpiData(gen_int, transformation)

# Create a DirectInfections model
direct_inf_model = DirectInfections(data = data, initialisation_prior = Normal())

# Generate latent infections
Z_t = randn(100)
latent_inf = generate_latent_infs(direct_inf_model, Z_t)
```
"
@kwdef struct DirectInfections{S <: Sampleable} <: AbstractEpiModel
"`Epidata`` object."
data::EpiData
SamuelBrand1 marked this conversation as resolved.
Show resolved Hide resolved
initialisation_prior::S
"Prior distribution for the initialisation of the infections. Default is `Normal()`."
initialisation_prior::S = Normal()
end

@model function generate_latent_infs(epi_model::DirectInfections, _It)
"""
Generate latent infections based on the given epidemiological model and noise term.
"""
@model function generate_latent_infs(epi_model::DirectInfections, Z_t)
init_incidence ~ epi_model.initialisation_prior
return epi_model.data.transformation.(init_incidence .+ _It)
return epi_model.data.transformation.(init_incidence .+ Z_t)
end
Loading