cscherrer / Soss.jl

Probabilistic programming via source rewriting
https://cscherrer.github.io/Soss.jl/stable/
MIT License
414 stars 30 forks source link

What am I doing wrong? #290

Closed FalkoSp closed 3 years ago

FalkoSp commented 3 years ago

I still try to follow the JuliaCon21 talk.

image

cscherrer commented 3 years ago

Your model doesn't make any random choices. Rather than sampling from a chain, the model is the chain. You need a ~ instead:

julia> m1 = @model begin
       mc1 ~ Chain(Normal(0.0, 1.0)) do x Normal(x, 1.0) end
       return mc1
       end
@model begin
        mc1 ~ Chain(Normal(0.0, 1.0)) do x
                Normal(x, 1.0)
            end
        return mc1
    end

julia> r1 = rand(m1())
Realized{Random._GLOBAL_RNG,UInt64,Chain{ggfunc-function,Normal{(:μ, :σ), Tuple{Float64, Float64}}}}(MeasureTheory.ResettableRNG{Random._GLOBAL_RNG, UInt64}(Random._GLOBAL_RNG(), 0x7f03d16a3be18246), Chain{ggfunc-function,Normal{(:μ, :σ), Tuple{Float64, Float64}}}(function = (x;) -> begin
    (Main).Normal(x, 1.0)
end, Normal{(:μ, :σ), Tuple{Float64, Float64}}((μ = 0.0, σ = 1.0))))

julia> collect(take(r1, 10))
10-element Vector{Any}:
 0.12741258475656037
 1.6417485229031188
 2.516541033750806
 2.8617087554639085
 4.121753061920916
 5.781340260119851
 4.174563930105311
 4.485225714203611
 4.696111390440044
 5.622520863790941
FalkoSp commented 3 years ago

Ah. Stupid mistake. Sorry for bothering and thank you for the answer! Kind greetings!

cscherrer commented 3 years ago

No worries, hope you enjoy the package!