cscherrer / Soss.jl

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

importance sampling #214

Closed cscherrer closed 3 years ago

cscherrer commented 3 years ago

I got importance sampling working. Here's a little example:

julia> importanceSample(p(),q(μ=0.0, σ=0.5), (y=y,))
Weighted(-7.45008.4
,(x = -0.5199557318297471,)

julia> p = @model begin
           x ~ Normal()
           y ~ Normal(x,1) |> iid(5)
       end;

julia> q = @model μ,σ begin
           x ~ Normal(μ,σ)
       end;

julia> y = rand(p()).y;

julia> importanceSample(p(),q(μ=0.0, σ=0.5), (y=y,))
Weighted(-7.13971.4
,(x = -0.12280566635062592,)

This can be used on its own or as part of variational inference