Skip to content

Commit

Permalink
Add drawing from regime-switching priors. Fix bug in regimes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwilliam77 committed Nov 20, 2020
1 parent 7895d6d commit dac0c18
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
38 changes: 25 additions & 13 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,13 @@ function rand_regime_switching(p::Vector{AbstractParameter{Float64}})
for (i, para) in enumerate(p)
draw[i] = if para.fixed
para.value
elseif (haskey(para.regimes, :prior) ? haskey(para.regimes[:prior], 1) : false)
# Resample until all prior draws are within the value bounds
prio = rand(regime_prior(para, 1).value)
while !(para.valuebounds[1] < prio < para.valuebounds[2])
prio = rand(regime_prior(para, 1).value)
end
prio
else
# Resample until all prior draws are within the value bounds
prio = rand(para.prior.value)
Expand All @@ -1212,22 +1219,27 @@ function rand_regime_switching(p::Vector{AbstractParameter{Float64}})
end
end
for para in p
if !isempty(para.regimes)
if haskey(para.regimes, :value)
for regime in keys(para.regimes[:value])
if regime != 1
one_draw = if para.fixed
para.value
else
# Resample until all prior draws are within the value bounds
if haskey(para.regimes, :value)
for regime in keys(para.regimes[:value])
if regime != 1
one_draw = if para.fixed
para.value
elseif (haskey(para.regimes, :prior) ? haskey(para.regimes[:prior], regime) : false)
# Resample until all prior draws are within the value bounds
prio = rand(regime_prior(para, regime).value)
while !(para.valuebounds[1] < prio < para.valuebounds[2])
prio = rand(regime_prior(para, regime).value)
end
prio
else
# Resample until all prior draws are within the value bounds
prio = rand(para.prior.value)
while !(para.valuebounds[1] < prio < para.valuebounds[2])
prio = rand(para.prior.value)
while !(para.valuebounds[1] < prio < para.valuebounds[2])
prio = rand(para.prior.value)
end
prio
end
push!(draw, one_draw)
prio
end
push!(draw, one_draw)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/regimes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ function toggle_regime!(p::Parameter{S}, i::Int64) where S <: Real
elseif field == :transform
p.transform = p.regimes[:transform][i]
elseif field == :prior
p.prior = p.regimes[:transform][i]
p.prior = p.regimes[:prior][i]
elseif field == :fixed
p.transform = p.regimes[:transform][i]
p.transform = p.regimes[:fixed][i]
end
elseif haskey(p.regimes, field) && !haskey(p.regimes[field], i)
error("Regime $i for field $field not found")
Expand Down

0 comments on commit dac0c18

Please sign in to comment.