ERROR: [Turing] MH doesn't support vectorizing assume statement

Hello again.

I am using Turing to re-create Facebook’s Prophet trend model. My model is:

@model Trend(Years, y) = begin
    NumberOfChangepoints ~ DiscreteUniform(1, 5) 
    s = collect(range(Years[1], length=1+NumberOfChangepoints, stop=Years[end]))[2:end]
    k ~ Normal(0., 5.) #Initial Rate
    m ~ Normal(0., 5.) #Initial Intercept
    λ ~ InverseGamma(1.5, 1.) #Diversity Prior
    δ = Vector{Float64}(undef, NumberOfChangepoints) #Correction to initial rate for each changepoint
    δ ~ [Laplace(0., λ)]
    A = repeat(Years', NumberOfChangepoints)'
    A = hcat(Array([A[:, i] .> s[i] for i in 1:NumberOfChangepoints] * 1)...)
    γ = -[s[i]*δ[i] for i in 1:NumberOfChangepoints]
    Slopes = A*δ .+ k
    Intercepts = A*γ .+ m
    Trend = Slopes .* Years .+ Intercepts
    sd ~ InverseGamma(1.5, 1.)
    for i in 1:size(y)[1]
        y[i] ~ Normal(Trend[i], sd)
    end
end

The issue is that I recieve the error

ERROR: [Turing] MH doesn't support vectorizing assume statement

My best guess is that it doesn’t like my δ vector. My sampler is such

chn = Turing.sample(Model, MH(), 10000)[3000:100:end]

since I’m unsure of how to implement PG along with NUTS. Thank you for your help :slight_smile:

What is Model? Your code is not runnable. Please see PSA: make it easier to help you.

Model is

Model = Trend(Years, y)

I am concerned about what that error message means not if the Model is able to run

The error comes from δ ~ [Laplace(0., λ)]. This syntax is not supported for MH. Use a loop instead. Note that this syntax will change soon-ish when https://github.com/TuringLang/Turing.jl/issues/476 is closed.

You can use PG and NUTS together with

sampler = Gibbs(PG(100, :NumberOfChangePoints), NUTS(500, 0.65, :k, :m, :λ, :δ, :sd))
chn = sample(Model, sampler, 10000)

10,000 will probably take a long time to run with this model and sampler pair, so you might consider stepping the number of iterations down a little.