Skip to content

Commit

Permalink
update to use parameters.jl and drop p calc in struct as don't work w…
Browse files Browse the repository at this point in the history
…ith having defaults
  • Loading branch information
seabbs committed Mar 14, 2024
1 parent 4cd8307 commit 3142f20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
2 changes: 2 additions & 0 deletions EpiAware/src/EpiAware.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ export make_epi_aware

include("docstrings.jl")
include("make_epi_aware.jl")

end
24 changes: 7 additions & 17 deletions EpiAware/src/EpiLatentModels/autoregressive.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
@kwdef struct AR{D <: Priors, S <: Distribution, I <: Priors, P <: Int}
"""A distribution representing the prior distribution of the damping factors."""
damp_prior::D = [truncated(Normal(0.0, 0.05), 0.0, 1)]

"""A distribution representing the prior distribution of the variance."""
var_prior::S = truncated(Normal(0.0, 0.05), 0.0, Inf)

"""A distribution representing the prior distribution of the initial values."""
@with_kw struct AR{D <: Priors, S <: Distribution, I <: Priors} <: AbstractLatentModel
damp_prior::D = truncated(Normal(0.0, 0.05), 0.0, 1)
std_prior::S = truncated(Normal(0.0, 0.05), 0.0, Inf)
init_prior::I = Normal()

"""
The order of the AR process, determined by the length of `damp_prior`.
"""
p::P = length(damp_prior)
@assert length(damp_prior)==length(init_prior) "damp_prior and init_prior must have the same length"
end

@model function generate_latent(latent_model::AR, n)
p = latent_model.p
p = length(damp_prior)
ϵ_t ~ MvNormal(ones(n - p))
σ²_AR ~ latent_model.var_prior
σ_AR ~ latent_model.std_prior
ar_init ~ latent_model.init_prior
damp_AR ~ latent_model.damp_prior
σ_AR = sqrt(σ²_AR)

@assert n>p "n must be longer than latent_model.p"
@assert n>p "n must be longer than order of the autoregressive process"

# Initialize the AR series with the initial values
ar = Vector{Float64}(undef, n)
Expand Down

0 comments on commit 3142f20

Please sign in to comment.