Gen.jl
Gen.jl copied to clipboard
Add a dirichlet distribution!
Ankit Shah and I are trying to use Gen to support a project and would love the addition of a dirichlet distribution
Thanks for using Gen! :)
This should be pretty straightforward. Some notes:
- Distributions.jl has a Dirichlet distribution, from which we can use sampling (for
Gen.random
) and logpdf (forGen.logpdf
). -
Gen.logpdf_grad
could support gradient with respect to concentration vector. -
Gen.logpdf_grad
could also support gradient with respect to the probability vector, although some care would be required when using these gradients, since the output is constrained to the simplex. This is an example of a random choice with a non-standard base measure, and it might make sense to introduce a Simplex data type to make that explicit. (However, making automatic differentiation interact well with custom data types requires more work, and might wait until the AD refactoring mentioned in https://github.com/probcomp/Gen/issues/128.)
What do people think about using an unconstrained parameterization?
The unconstrained parameter may be less intuitive, but probably more practical for gradient-based inference techniques.
Sounds like using Distributions.jl together with Bijectors.jl could work.
Looks like someone is doing this in #225!
Finally resolved by PR #495! (I also forgot that two different people took a step at this, thank you both!)
Reopening this because we have not added dirichlet
to the Gen docs!
Resolved by #522.
Hello,
the type declaration was
struct Dirichlet <: Distribution{Float64} end
which threw a conversion error when tracing; I made a PR which changes it to
struct Dirichlet <: Distribution{Vector{Float64}} end
in #524