https://github.com/probcomp/gendistributions.jl
Use Distributions.jl distributions from within Gen
https://github.com/probcomp/gendistributions.jl
Last synced: 7 months ago
JSON representation
Use Distributions.jl distributions from within Gen
- Host: GitHub
- URL: https://github.com/probcomp/gendistributions.jl
- Owner: probcomp
- Created: 2021-01-20T22:46:36.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-20T22:51:06.000Z (about 5 years ago)
- Last Synced: 2025-06-06T21:08:52.051Z (10 months ago)
- Language: Julia
- Size: 5.86 KB
- Stars: 5
- Watchers: 5
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GenDistributions.jl
This package implements a lightweight compatibility layer for using
distributions from [Distributions.jl](https://github.com/JuliaStats/Distributions.jl) in
[Gen.jl](https://github.com/probcomp/Gen).
```julia
using GenDistributions
using Distributions
using Gen
# Arguments are:
# * A function taking parameters to Distributions.jl distributions
# * A tuple of Bools indicating whether Zygote should differentiate the logpdf
# function w.r.t. each parameter
# * A Bool indicating whether Zygote should differentiate the logpdf w.r.t.
# the sampled value
# * The output Julia type of the distribution.
# E.g.:
const dirichlet = DistributionsBacked(alpha -> Dirichlet(alpha), (true,), true, Vector{Float64})
const flip = DistributionsBacked(p -> Bernoulli(p), (true,), false, Bool)
# Using within Gen:
@gen function pick()
x ~ dirichlet(ones(10))
y ~ categorical(x)
return (x, y)
end
```