Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampling directly from varied-sized prior is buggy #108

Open
xukai92 opened this issue May 6, 2020 · 0 comments
Open

Sampling directly from varied-sized prior is buggy #108

xukai92 opened this issue May 6, 2020 · 0 comments

Comments

@xukai92
Copy link
Member

xukai92 commented May 6, 2020

MEW:

using Random: AbstractRNG
using Distributions: DiscreteMultivariateDistribution
import Distributions: rand, logpdf

struct DSL <: DiscreteMultivariateDistribution
end

function logpdf(dsl::DSL, dsl_numeric::AbstractVector{Int})
    return sum([log(0.5) * 0.5^i for i in 1:length(dsl_numeric)])
end

function rand(rng::AbstractRNG, dsl::DSL)
    fst = rand(rng, [0, 1])
    dsl_numeric = [fst]
    while rand() < 0.5
        push!(dsl_numeric, rand(rng, [0, 1]))
    end
    return dsl_numeric
end

using Turing

@model function mwe()
    dsl ~ DSL()
end

chain = sample(mwe(), PG(10), 500)

gives

Stacktrace in the failed task:
tried to assign 2 elements to 7 destinations
throw_setindex_mismatch(::Array{Int64,1}, ::Tuple{Int64}) at indices.jl:191
setindex_shape_check at indices.jl:242 [inlined]
setindex! at array.jl:850 [inlined]
setval!(::DynamicPPL.VarInfo{NamedTuple{(:dsl,),Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:dsl},Int64},Array{DSL,1},Array{DynamicPPL.VarName{:dsl},1},Array{Int64,1},Array{Set{DynamicPPL.Selector},1}}}},Float64}, ::Array{Int64,1}, ::DynamicPPL.VarName{:dsl}) at varinfo.jl:284
setindex!(::DynamicPPL.VarInfo{NamedTuple{(:dsl,),Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:dsl},Int64},Array{DSL,1},Array{DynamicPPL.VarName{:dsl},1},Array{Int64,1},Array{Set{DynamicPPL.Selector},1}}}},Float64}, ::Array{Int64,1}, ::DynamicPPL.VarName{:dsl}) at varinfo.jl:939
assume(::DynamicPPL.Sampler{PG{()},Turing.Inference.PGState{DynamicPPL.VarInfo{NamedTuple{(:dsl,),Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:dsl},Int64},Array{DSL,1},Array{DynamicPPL.VarName{:dsl},1},Array{Int64,1},Array{Set{DynamicPPL.Selector},1}}}},Float64},Float64}}, ::DSL, ::DynamicPPL.VarName{:dsl}, ::DynamicPPL.VarInfo{NamedTuple{(:dsl,),Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:dsl},Int64},Array{DSL,1},Array{DynamicPPL.VarName{:dsl},1},Array{Int64,1},Array{Set{DynamicPPL.Selector},1}}}},Float64}) at AdvancedSMC.jl:272
_tilde at context_implementations.jl:39 [inlined]
tilde at context_implementations.jl:18 [inlined]
macro expansion at compiler.jl:348 [inlined]
macro expansion at In[4]:9 [inlined]
##inner_function#340#6 at compiler.jl:493 [inlined]
#_#5 at model.jl:24 [inlined]
Model at model.jl:24 [inlined]
Model at model.jl:23 [inlined]
#3 at container.jl:37 [inlined]
(::Libtask.var"#1#2"{Turing.Core.var"#3#4"{DynamicPPL.Model{var"##inner_function#340#6",NamedTuple{(),Tuple{}},DynamicPPL.ModelGen{(),var"###mwe#348",NamedTuple{(),Tuple{}}},Val{()}},DynamicPPL.Sampler{PG{()},Turing.Inference.PGState{DynamicPPL.VarInfo{NamedTuple{(:dsl,),Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:dsl},Int64},Array{DSL,1},Array{DynamicPPL.VarName{:dsl},1},Array{Int64,1},Array{Set{DynamicPPL.Selector},1}}}},Float64},Float64}},DynamicPPL.VarInfo{NamedTuple{(:dsl,),Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:dsl},Int64},Array{DSL,1},Array{DynamicPPL.VarName{:dsl},1},Array{Int64,1},Array{Set{DynamicPPL.Selector},1}}}},Float64}}})() at taskcopy.jl:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant