Skip to content

SMC sampling with Julia 1.1 produces samples with 0 variance for discrete RVs! #39

@trappmartin

Description

@trappmartin

I observed this behaviour a few times already. At first I thought I couldn't reproduce the issue but now I figured out the corner case and here is a MWE.

using Turing
using LinearAlgebra
using StatsFuns: logistic

x = vcat(randn(100,3), randn(100,3).+2)
y = vcat(zeros(100), ones(100))

@model lr_nuts(x, y, σ) = begin

    N,D = size(x)

    α ~ Normal(0, σ)
    β ~ MvNormal(zeros(D), ones(D)*σ)

    p = Vector{Float64}(undef, D)
    s = Vector{Bool}(undef, D)
    for d = 1:D
        p[d] ~ Beta(1/2, 1/2)
        s[d] ~ Bernoulli(p[d])
    end

    for n = 1:N
        y[n] ~ Bernoulli(logistic(dot(x[n,s], β[s]) + α))
    end
end

chn = sample(lr_nuts(x,y,sqrt(10)), SMC(1000));

This code produces a chain with variance in the discrete RV's s if I'm using Julia 1.0.4. If I'm using Julia 1.1 instead, the variance for all discrete RV's (s) is zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions