Skip to content

Commit

Permalink
chase down partial arg changes
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Oct 11, 2024
1 parent 939ca74 commit 0fee831
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion EpiAware/src/EpiLatentModels/models/HierarchicalNormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rand(mdl)
mean::R = 0.0
std_prior::D = truncated(Normal(0, 1), 0, Inf)

function HierarchicalNormal(std_prior::D)
function HierarchicalNormal(std_prior::Sampleable)
return HierarchicalNormal(; mean = 0.0, std_prior = std_prior)
end
end
Expand Down
24 changes: 11 additions & 13 deletions EpiAware/src/EpiLatentModels/models/MA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ The moving average (MA) model struct.
# Constructors
- `MA(θ::Distribution, σ::Distribution; q::Int = 1, ϵ::AbstractTuringLatentModel = IDD(Normal()))`: Constructs an MA model with the specified prior distributions.
- `MA(; θ::Vector{C} = [truncated(Normal(0.0, 0.05), -1, 1)], σ::Distribution = HalfNormal(0.1), ϵ::AbstractTuringLatentModel = HierarchicalNormal) where {C <: Distribution}`: Constructs an MA model with the specified prior distributions.
- `MA(; θ::Vector{C} = [truncated(Normal(0.0, 0.05), -1, 1)], ϵ::AbstractTuringLatentModel = HierarchicalNormal) where {C <: Distribution}`: Constructs an MA model with the specified prior distributions.
- `MA(θ::Distribution, q::Int, ϵ_t::AbstractTuringLatentModel)`: Constructs an MA model with the specified prior distributions and order.
# Parameters
- `θ`: Prior distribution for the MA coefficients. For MA(q), this should be a vector of q distributions or a multivariate distribution of dimension q.
- `q`: Order of the MA model, i.e., the number of lagged error terms.
- `ϵ_t`: Distribution of the error term, typically standard normal.
- `ϵ_t`: Distribution of the error term, typically standard normal. Defaults to `IDD(Normal())`.
# Examples
Expand Down Expand Up @@ -44,26 +44,24 @@ struct MA{C <: Sampleable, S <: Sampleable, Q <: Int, E <: AbstractTuringLatentM
"Prior distribution for the error term."
ϵ_t::E

function MA::Distribution, σ::Distribution;
q::Int = 1, ϵ::AbstractTuringLatentModel = IDD(Normal()))
function MA::Distribution;
q::Int = 1, ϵ_t::AbstractTuringLatentModel = HierarchicalNormal(HalfNormal(0.1)))
θ_priors = fill(θ, q)
return MA(; θ_priors = θ_priors, σ = σ, ϵ = ϵ)
return MA(; θ_priors = θ_priors, ϵ_t = ϵ_t)
end

function MA(; θ_priors::Vector{C} = [truncated(Normal(0.0, 0.05), -1, 1)],
σ::Distribution = HalfNormal(0.1),
ϵ::AbstractTuringLatentModel = IDD(Normal())) where {C <: Distribution}
ϵ_t::AbstractTuringLatentModel = HierarchicalNormal(HalfNormal(0.1))) where {C <:
Distribution}
q = length(θ_priors)
θ = _expand_dist(θ_priors)
return MA(θ, q, ϵ)
return MA(θ, q, ϵ_t)
end

function MA::Distribution, q::Int, ϵ::AbstractTuringLatentModel)
function MA::Distribution, q::Int, ϵ_t::AbstractTuringLatentModel)
@assert q>0 "q must be greater than 0"
@assert q==length(θ) "q must be equal to the length of θ"
new{typeof(θ), typeof(σ), typeof(q), typeof(ϵ)}(
θ, q, ϵ
)
new{typeof(θ), typeof(q), typeof(ϵ_t)}(θ, q, ϵ_t)
end
end

Expand All @@ -85,7 +83,7 @@ Generate a latent MA series.
q = latent_model.q
@assert n>q "n must be longer than order of the moving average process"
θ ~ latent_model.θ
@submodel ϵ_t = generate_latent(latent_model.ϵ, n)
@submodel ϵ_t = generate_latent(latent_model.ϵ_t, n)

ma = accumulate_scan(
MAStep(θ),
Expand Down

0 comments on commit 0fee831

Please sign in to comment.