cscherrer / Soss.jl

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

No more Soss.predict() methods for densities from Distributions.jl #294

Closed paschermayr closed 3 years ago

paschermayr commented 3 years ago

Hi Chad,

There seems to be no more Soss.predict() methods for densities from Distributions.jl, and hence the logdensity function does not work anymore for a Soss model defined via Dists. MWE:

using MeasureTheory, Soss #Soss v0.20.2, MeasureTheory v0.10.3

dat = randn(100)
m = Soss.@model n begin
    μ ~ Dists.Normal()
    σ ~ Dists.Exponential()
    data ~ Dists.Normal(μ, σ) |> iid(n)
    return (; data)
end
mod = m( (; n = length(dat) ) )
post = mod | (data = dat,)

logdensity( mod( (μ = 1., σ = 2., data = dat) ) ) #MethodError: no method matching predict(::Distributions.Exponential{Float64}
logdensity( post( (μ = 1., σ = 2.) ) ) #MethodError: no method matching predict(::Distributions.Exponential{Float64}
sourceLogdensity( post( (μ = 1., σ = 2.) ) )
methods(Soss.predict)

The same code works if Dists is replaced with MeasureTheory.

I would like to replace Distributions.jl with MeasureTheory.jl anyway, but DistributionAD.jl and Bijectors.jl are still made for Distributions.jl, would it be possible to keep support for Distributions.jl for now (if it is not too much work)?

cscherrer commented 3 years ago

Hi Patrick,

Thanks for letting me know about this, it seems to be a mistake introduced when I made MeasureTheory the main dependency. I think it should be a quick fix. We'll also need tests for this, and your MWE could be a good fit for this.

cscherrer commented 3 years ago

Hi @paschermayr , a small update fixed your example, which I've adapted to use as a test. I've triggered a new release, which should be available shortly. Thanks again for letting me know about this :)

paschermayr commented 3 years ago

Thank you too!