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

Dot-tilde (.~) broadcasting not supported in Turing models #1360

Closed
NMUrban opened this issue Jun 2, 2020 · 6 comments
Closed

Dot-tilde (.~) broadcasting not supported in Turing models #1360

NMUrban opened this issue Jun 2, 2020 · 6 comments

Comments

@NMUrban
Copy link

NMUrban commented Jun 2, 2020

It appears that broadcasting the ~ operator does not work. For example:

z = randn(10000)

@model dottilde(y) = begin
    μ ~ Normal(0,1)
    σ ~ Gamma(1,1)
    y .~ Normal(μ,σ)
end

q = vi(dottilde(z), ADVI(1,2000))

results in an error:

MethodError: no method matching dot_tilde(::DynamicPPL.DefaultContext, ::DynamicPPL.SampleFromPrior, ::Normal{Float64}, ::Array{Float64,1}, ::Array{Float64,1}, ::DynamicPPL.ThreadSafeVarInfo{DynamicPPL.VarInfo{DynamicPPL.Metadata{Dict{DynamicPPL.VarName,Int64},Array{Distribution,1},Array{DynamicPPL.VarName,1},Array{Real,1},Array{Set{DynamicPPL.Selector},1}},Float64},Array{Base.RefValue{Float64},1}})

The code works if you replace y .~ Normal(μ,σ) with y ~ filldist(Normal(μ,σ), length(y)).

@theogf
Copy link
Member

theogf commented Jul 23, 2020

I think this issue is more relevant to Turing.jl, I will be moving the issue there.

@theogf theogf transferred this issue from TuringLang/AdvancedVI.jl Jul 23, 2020
@krishvishal
Copy link

Try y .~ Normal.(μ,σ) instead of y .~ Normal(μ,σ)

@devmotion
Copy link
Member

Looks like a duplicate of TuringLang/DynamicPPL.jl#137 and should be fixed by TuringLang/DynamicPPL.jl#147.

@krishvishal
Copy link

@devmotion I've been using y .~ Normal.(μ,σ), can you tell me if this is correct?

@devmotion
Copy link
Member

In the example above it shouldn't make any difference since μ and σ are just scalars. Of course, if that's not the case and, e.g., μ would be a vector with different values for each output, then one has to use y .~ Normal.(μ, σ).

So I think both versions are "correct" in some way, but personally I would use y .~ Normal(μ, σ) in the example above (which currently unfortunately requires the bugfix mentioned above).

@devmotion
Copy link
Member

Fixed in Turing 0.14 (which includes TuringLang/DynamicPPL.jl#147).

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

4 participants