Skip to content

Instantly share code, notes, and snippets.

@cscherrer
Last active July 2, 2021 20:58
Show Gist options
  • Save cscherrer/d649f7d4477bde4f0843f2492442cf20 to your computer and use it in GitHub Desktop.
Save cscherrer/d649f7d4477bde4f0843f2492442cf20 to your computer and use it in GitHub Desktop.
Simple SIR model in Soss
using Soss
using Distributions
mstep = @model pars,state begin
# Parameters
α = pars.α # Daily transmission rate
βγ = pars.βγ # Daily recovery rate, case fatality rate
# Starting counts
s0 = state.s # Susceptible
i0 = state.i # Infected
r0 = state.r # Recovered
d0 = state.d # Deceased
n = s0 + i0 + r0 # Population
# Transitions between states
si ~ Binomial(s0, α * i0 / n)
ir ~ Multinomial(i0, [β, )
id ~ Binomial(i0 - ir, γ)
# Updated counts
next = ( s = s0 - si
, i = i0 + si - ir - id
, r = r0 + ir
, d = d0 + id
)
end;
m = @model s0 begin
α ~ Uniform()
β ~ Uniform()
γ ~ Uniform()
pars = (α=α, β=β, γ=γ)
x ~ MarkovChain(pars, mstep(pars=pars, state=s0))
end
using CSV
covid = CSV.read("/home/chad/git/covid-19/data/countries-aggregated.csv");
using DataFramesMeta
us = @where(covid, :Country .== "US");
# Some simple data cleaning - each column should be non-decreasing
# Fix decreasing values with geometric mean
for j in [:Confirmed, :Recovered, :Deaths]
for i in 2:(size(us,1) - 1)
if us[i, j] < us[i-1, j]
us[i,j] = round(Int, sqrt(us[i-1,j] * us[i+1,j]))
end
end
end
using DataFrames
df = DataFrame(
:i => us.Confirmed
, :r => us.Recovered
, :d => us.Deaths
)
n = 331000000
df[!, :s] .= n .- df.i .- df.r .- df.d;
df[!, :si] .= 0;
df[:si][2:end] = .-diff(df.s);
df[!, :ir] .= 0;
df[:ir][2:end] = diff(df.r);
df[!, :id] .= 0;
df[:id][2:end] = diff(df.d);
# just the last 30 days
df = df[(end-29):end,:];
using NamedTupleTools
import NamedTupleTools
NamedTupleTools.namedtuple(dfrow::DataFrameRow) = namedtuple(pairs(dfrow).iter.is...)
nts = namedtuple(names(df)).(eachrow(df));
s0 = namedtuple(df[1,:]);
post = dynamicHMC(m(s0=s0),(x=namedtuple.(eachrow(df)),));
ppost=particles(post)
# R₀
ppost.α / (ppost.β + ppost.γ)
# Case fatality rate
ppost.γ / (ppost.β + ppost.γ)
# Implied infection duration
1/(ppost.β + ppost.γ)
@cscherrer
Copy link
Author

data for this is here: git@github.com:datasets/covid-19.git

@alusiani
Copy link

alusiani commented Jun 6, 2020

Hi,

thanks for providing this example. I tried it, on Julia 1.4.2, and I get at the end the following error:

MethodError: no method matching sourceXform(::Type{NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}})
The applicable method may be too new: running in world age 27537, while current world is 28187.
Closest candidates are:
sourceXform(::Any) at /home/lusiani/.julia/packages/Soss/f6YXp/src/primitives/xform.jl:32 (method too new to be called from this world context.)
sourceXform() at /home/lusiani/.julia/packages/Soss/f6YXp/src/primitives/xform.jl:32 (method too new to be called from this world context.)

Stacktrace:
[1] macro expansion at /home/lusiani/.julia/packages/Soss/f6YXp/src/primitives/xform.jl:19 [inlined]
[2] #s43#84(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) at /home/lusiani/.julia/packages/GeneralizedGenerated/4p9fF/src/closure_conv.jl:121
[3] xform at /home/lusiani/.julia/packages/Soss/f6YXp/src/primitives/xform.jl:15 [inlined]
[4] dynamicHMC(::Random._GLOBAL_RNG, ::Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
γ ~ Uniform()
β ~ Uniform()
α ~ Uniform()
pars = (α = α, β = β, γ = γ)
x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)}, ::NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}, ::Int64; method::Function, ad_backend::Val{:ForwardDiff}, reporter::NoProgressReport, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:86
[5] dynamicHMC at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:85 [inlined] (repeats 2 times)
[6] #dynamicHMC#174 at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:131 [inlined]
[7] dynamicHMC(::Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
γ ~ Uniform()
β ~ Uniform()
α ~ Uniform()
pars = (α = α, β = β, γ = γ)
x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)}, ::NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}) at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:131
[8] top-level scope at In[27]:2

@cscherrer
Copy link
Author

Thanks for letting me know about this. I'm having trouble reproducing the error, which version of Soss are you using? Are you able to fit a simple model in Soss? (to check that things are set up properly)

@alusiani
Copy link

alusiani commented Jun 6, 2020

Hi,

I have tried to document a bit better the reported error. I did some modifications to your gist here because as it stands I could not run it. I tried now to go back as close as possible to the original, and I am getting a different error, which appears to be of a different kind, perhaps I am not using the right data. This is my configuration:

Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
OS: Linux (x86_64-redhat-linux)
CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

Packages

CSV 0.6.2
DataFrames 0.21.2
DataFramesMeta 0.5.1
Distributions 0.23.4
IJulia 1.21.2
NamedTupleTools 0.13.4
Soss 0.12.0

I have been able to run the example in the README of the package.

This is my notebook https://gist.github.com/alusiani/57e22a3c6b33b148c021032cda876514 and I use these data https://gist.github.com/alusiani/64387fd0507b0ddfc27bd566b317b4d5.

I was getting the above error when uncommenting "## using DynamicHMC". Now I get the following error:

ArgumentError: Value and slope at step length = 0 must be finite.

Stacktrace:
 [1] (::LineSearches.HagerZhang{Float64,Base.RefValue{Bool}})(::Function, ::LineSearches.var"#ϕdϕ#6"{Optim.ManifoldObjective{NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}},Array{Float64,1},Array{Float64,1},Array{Float64,1}}, ::Float64, ::Float64, ::Float64) at /home/lusiani/.julia/packages/LineSearches/WrsMD/src/hagerzhang.jl:117
 [2] HagerZhang at /home/lusiani/.julia/packages/LineSearches/WrsMD/src/hagerzhang.jl:101 [inlined]
 [3] perform_linesearch!(::Optim.LBFGSState{Array{Float64,1},Array{Array{Float64,1},1},Array{Array{Float64,1},1},Float64,Array{Float64,1}}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#19#21"}, ::Optim.ManifoldObjective{NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}}) at /home/lusiani/.julia/packages/Optim/UkDyx/src/utilities/perform_linesearch.jl:53
 [4] update_state!(::NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}, ::Optim.LBFGSState{Array{Float64,1},Array{Array{Float64,1},1},Array{Array{Float64,1},1},Float64,Array{Float64,1}}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#19#21"}) at /home/lusiani/.julia/packages/Optim/UkDyx/src/multivariate/solvers/first_order/l_bfgs.jl:198
 [5] optimize(::NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}, ::Array{Float64,1}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#19#21"}, ::Optim.Options{Float64,Nothing}, ::Optim.LBFGSState{Array{Float64,1},Array{Array{Float64,1},1},Array{Array{Float64,1},1},Float64,Array{Float64,1}}) at /home/lusiani/.julia/packages/Optim/UkDyx/src/multivariate/optimize/optimize.jl:57
 [6] optimize(::NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}, ::Array{Float64,1}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#19#21"}, ::Optim.Options{Float64,Nothing}) at /home/lusiani/.julia/packages/Optim/UkDyx/src/multivariate/optimize/optimize.jl:33
 [7] warmup at /home/lusiani/.julia/packages/DynamicHMC/83Q9C/src/mcmc.jl:151 [inlined]
 [8] #31 at /home/lusiani/.julia/packages/DynamicHMC/83Q9C/src/mcmc.jl:445 [inlined]
 [9] BottomRF at ./reduce.jl:78 [inlined]
 [10] afoldl(::Base.BottomRF{DynamicHMC.var"#31#32"{DynamicHMC.SamplingLogDensity{Random._GLOBAL_RNG,LogDensityProblems.ForwardDiffLogDensity{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}},ForwardDiff.GradientConfig{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3,Array{ForwardDiff.Dual{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3},1}}},DynamicHMC.NUTS{Val{:generalized}},DynamicHMC.NoProgressReport}}}, ::Tuple{Tuple{},DynamicHMC.WarmupState{DynamicHMC.EvaluatedLogDensity{Array{Float64,1},Float64},DynamicHMC.GaussianKineticEnergy{LinearAlgebra.Diagonal{Float64,Array{Float64,1}},LinearAlgebra.Diagonal{Float64,Array{Float64,1}}},Nothing}}, ::DynamicHMC.FindLocalOptimum{Float64}, ::DynamicHMC.InitialStepsizeSearch, ::DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}}, ::DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}}, ::DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}}, ::DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}}, ::DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}}, ::DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}}, ::DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}}) at ./operators.jl:517
 [11] _foldl_impl at ./tuple.jl:207 [inlined]
 [12] foldl_impl at ./reduce.jl:45 [inlined]
 [13] mapfoldl_impl at ./reduce.jl:41 [inlined]
 [14] #mapfoldl#189 at ./reduce.jl:157 [inlined]
 [15] #foldl#190 at ./reduce.jl:175 [inlined]
 [16] _warmup(::DynamicHMC.SamplingLogDensity{Random._GLOBAL_RNG,LogDensityProblems.ForwardDiffLogDensity{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}},ForwardDiff.GradientConfig{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3,Array{ForwardDiff.Dual{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3},1}}},DynamicHMC.NUTS{Val{:generalized}},DynamicHMC.NoProgressReport}, ::Tuple{DynamicHMC.FindLocalOptimum{Float64},DynamicHMC.InitialStepsizeSearch,DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}}}, ::DynamicHMC.WarmupState{DynamicHMC.EvaluatedLogDensity{Array{Float64,1},Float64},DynamicHMC.GaussianKineticEnergy{LinearAlgebra.Diagonal{Float64,Array{Float64,1}},LinearAlgebra.Diagonal{Float64,Array{Float64,1}}},Nothing}) at /home/lusiani/.julia/packages/DynamicHMC/83Q9C/src/mcmc.jl:443
 [17] mcmc_keep_warmup(::Random._GLOBAL_RNG, ::LogDensityProblems.ForwardDiffLogDensity{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}},ForwardDiff.GradientConfig{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3,Array{ForwardDiff.Dual{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3},1}}}, ::Int64; initialization::Tuple{}, warmup_stages::Tuple{DynamicHMC.FindLocalOptimum{Float64},DynamicHMC.InitialStepsizeSearch,DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}}}, algorithm::DynamicHMC.NUTS{Val{:generalized}}, reporter::DynamicHMC.NoProgressReport) at /home/lusiani/.julia/packages/DynamicHMC/83Q9C/src/mcmc.jl:519
 [18] macro expansion at /home/lusiani/.julia/packages/UnPack/1IjJI/src/UnPack.jl:100 [inlined]
 [19] mcmc_with_warmup(::Random._GLOBAL_RNG, ::LogDensityProblems.ForwardDiffLogDensity{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}},ForwardDiff.GradientConfig{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3,Array{ForwardDiff.Dual{ForwardDiff.Tag{LogDensityProblems.var"#28#29"{LogDensityProblems.TransformedLogDensity{TransformVariables.TransformTuple{NamedTuple{(:γ, :β, :α),Tuple{TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64},TransformVariables.ScaledShiftedLogistic{Float64}}}},Soss.var"#ℓ#171"{typeof(logpdf),Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)},NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}}}},Float64},Float64,3},1}}}, ::Int64; initialization::Tuple{}, warmup_stages::Tuple{DynamicHMC.FindLocalOptimum{Float64},DynamicHMC.InitialStepsizeSearch,DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{LinearAlgebra.Diagonal,DynamicHMC.DualAveraging{Float64}},DynamicHMC.TuningNUTS{Nothing,DynamicHMC.DualAveraging{Float64}}}, algorithm::DynamicHMC.NUTS{Val{:generalized}}, reporter::DynamicHMC.NoProgressReport) at /home/lusiani/.julia/packages/DynamicHMC/83Q9C/src/mcmc.jl:577
 [20] dynamicHMC(::Random._GLOBAL_RNG, ::Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)}, ::NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}, ::Int64; method::Function, ad_backend::Val{:ForwardDiff}, reporter::DynamicHMC.NoProgressReport, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:90
 [21] dynamicHMC at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:85 [inlined] (repeats 2 times)
 [22] #dynamicHMC#174 at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:131 [inlined]
 [23] dynamicHMC(::Soss.JointDistribution{NamedTuple{(:s0,),Tuple{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}}}},NamedTuple{(:s0,),T} where T<:Tuple,TypeEncoding(begin
    γ ~ Uniform()
    β ~ Uniform()
    α ~ Uniform()
    pars = (α = α, β = β, γ = γ)
    x ~ MarkovChain(pars, mstep(pars = pars, state = s0))
end),TypeEncoding(Main)}, ::NamedTuple{(:x,),Tuple{Array{NamedTuple{(:i, :r, :d, :n, :s, :si, :ir, :id),NTuple{8,Int64}},1}}}) at /home/lusiani/.julia/packages/Soss/f6YXp/src/inference/dynamicHMC.jl:131
 [24] top-level scope at In[22]:2

@cscherrer
Copy link
Author

Ok thanks, I'm seeing this error too. I'll look into it.

@cscherrer
Copy link
Author

Ok, think I have it back on track. I get

julia> ppost=particles(post)
(γ = 0.00147 ± 4.4e-6, β = 0.00667 ± 9.3e-6, α = 0.0339 ± 2.1e-5)

@alusiani
Copy link

alusiani commented Jun 7, 2020

Thanks for looking into it. Your updated gist works now also in my setup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment