Internal Documentation
Documentation for EpiLatentModels.jl
's internal interface.
Contents
Index
EpiAware.EpiLatentModels.ARStep
EpiAware.EpiLatentModels.ARStep
EpiAware.EpiAwareBase.broadcast_n
EpiAware.EpiAwareBase.broadcast_n
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
EpiAware.EpiAwareBase.generate_latent
Internal API
EpiAware.EpiLatentModels.ARStep
— Typestruct ARStep{D<:(AbstractVector{<:Real})} <: AbstractAccumulationStep
The autoregressive (AR) step function struct
Fields
damp_AR::AbstractVector{<:Real}
EpiAware.EpiLatentModels.ARStep
— MethodThe autoregressive (AR) step function for use with accumulate_scan
.
EpiAware.EpiAwareBase.broadcast_n
— Methodbroadcast_n(_::RepeatBlock, n, period) -> Any
A function that returns the length of the latent periods to generate using the RepeatBlock
rule which is equal n divided by the period and rounded up to the nearest integer.
Arguments
rule::RepeatBlock
: The broadcasting rule.n
: The number of samples to generate.period
: The period of the broadcast.
EpiAware.EpiAwareBase.broadcast_n
— Methodbroadcast_n(_::RepeatEach, n, period) -> Any
A function that returns the length of the latent periods to generate using the RepeatEach
rule which is equal to the period.
Arguments
rule::RepeatEach
: The broadcasting rule.n
: The number of samples to generate.period
: The period of the broadcast.
Returns
m
: The length of the latent periods to generate.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(latent_model::AR, n) -> Any
Generate a latent AR series.
Arguments
latent_model::AR
: The AR model.n::Int
: The length of the AR series.
Returns
ar::Vector{Float64}
: The generated AR series.
Notes
- The length of
damp_prior
andinit_prior
must be the same. n
must be longer than the order of the autoregressive process.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(model::BroadcastLatentModel, n) -> Any
Generates latent periods using the specified model
and n
number of samples.
Arguments
model::BroadcastLatentModel
: The broadcast latent model.n::Any
: The number of samples to generate.
Returns
broadcasted_latent
: The generated broadcasted latent periods.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(
latent_models::CombineLatentModels,
n
) -> Any
Generate latent variables using a combination of multiple latent models.
Arguments
latent_models::CombineLatentModels
: An instance of theCombineLatentModels
type representing the collection of latent models.n
: The number of latent variables to generate.
Returns
- The combined latent variables generated from all the models.
Example
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(latent_models::ConcatLatentModels, n) -> Any
Generate latent variables by concatenating multiple latent models.
Arguments
latent_models::ConcatLatentModels
: An instance of theConcatLatentModels
type representing the collection of latent models.n
: The number of latent variables to generate.
Returns
concatenated_latents
: The combined latent variables generated from all the models.latent_aux
: A tuple containing the auxiliary latent variables generated from each individual model.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(latent_model::DiffLatentModel, n) -> Any
Generate a Turing
model for n
-step latent process $Z_t$ using a differenced latent model defined by latent_model
.
Arguments
latent_model::DiffLatentModel
: The differential latent model.n
: The length of the latent variables.
Turing model specifications
Sampled random variables
latent_init
: The initial latent process variables.- Other random variables defined by
model<:AbstractTuringLatentModel
field of the undifferenced model.
Generated quantities
- A tuple containing the generated latent process as its first argument and a
NamedTuple
of sampled auxiliary variables as second argument.
Example usage with DiffLatentModel
model constructor
generate_latent
can be used to construct a Turing
model for the differenced latent process. In this example, the underlying undifferenced process is a RandomWalk
model.
First, we construct a RandomWalk
struct with an initial value prior and a step size standard deviation prior.
using Distributions, EpiAware
rw = RandomWalk(Normal(0.0, 1.0), truncated(Normal(0.0, 0.05), 0.0, Inf))
Then, we can use DiffLatentModel
to construct a DiffLatentModel
for d
-fold differenced process with rw
as the undifferenced latent process.
We have two constructor options for DiffLatentModel
. The first option is to supply a common prior distribution for the initial terms and specify d
as follows:
diff_model = DiffLatentModel(rw, Normal(); d = 2)
Or we can supply a vector of priors for the initial terms and d
is inferred as follows:
diff_model2 = DiffLatentModel(;undiffmodel = rw, init_priors = [Normal(), Normal()])
Then, we can use generate_latent
to construct a Turing model for the differenced latent process generating a length n
process,
# Construct a Turing model
n = 100
difference_mdl = generate_latent(diff_model, n)
Now we can use the Turing
PPL API to sample underlying parameters and generate the unobserved latent process.
#Sample random parameters from prior
θ = rand(difference_mdl)
#Get a sampled latent process as a generated quantity from the model
(Z_t, _) = generated_quantities(difference_mdl, θ)
Z_t
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(latent_model::FixedIntercept, n) -> Any
Generate a latent intercept series with a fixed intercept value.
Arguments
latent_model::FixedIntercept
: The fixed intercept latent model.n
: The number of latent variables to generate.
Returns
latent_vars
: An array of lengthn
filled with the fixed intercept value.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(obs_model::HierarchicalNormal, n) -> Any
function EpiAwareBase.generate_latent(obs_model::HierarchicalNormal, n)
Generate latent variables from the hierarchical normal distribution.
Arguments
obs_model::HierarchicalNormal
: The hierarchical normal distribution model.n
: Number of latent variables to generate.
Returns
η_t
: Generated latent variables.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(latent_model::Intercept, n) -> Any
Generate a latent intercept series.
Arguments
latent_model::Intercept
: The intercept model.n::Int
: The length of the intercept series.
Returns
intercept::Vector{Float64}
: The generated intercept series.
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(latent_model::RandomWalk, n) -> Any
Implement the generate_latent
function for the RandomWalk
model.
Example usage of generate_latent
with RandomWalk
type of latent process model
using Distributions, Turing, EpiAware
# Create a RandomWalk model
rw = RandomWalk(init_prior = Normal(2., 1.),
std_prior = HalfNormal(0.1))
Then, we can use generate_latent
to construct a Turing model for a 10 step random walk.
# Construct a Turing model
rw_model = generate_latent(rw, 10)
Now we can use the Turing
PPL API to sample underlying parameters and generate the unobserved infections.
#Sample random parameters from prior
θ = rand(rw_model)
#Get random walk sample path as a generated quantities from the model
Z_t, _ = generated_quantities(rw_model, θ)
EpiAware.EpiAwareBase.generate_latent
— Methodgenerate_latent(model::TransformLatentModel, n) -> Any
generate_latent(model::TransformLatentModel, n)
Generate latent variables using the specified TransformLatentModel
.
Arguments
model::TransformLatentModel
: TheTransformLatentModel
to generate latent variables from.n
: The number of latent variables to generate.
Returns
- The transformed latent variables.