Gen.jl icon indicating copy to clipboard operation
Gen.jl copied to clipboard

Add a dirichlet distribution!

Open serenabooth opened this issue 5 years ago • 4 comments

Ankit Shah and I are trying to use Gen to support a project and would love the addition of a dirichlet distribution

serenabooth avatar Oct 30 '19 19:10 serenabooth

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 (for Gen.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.)

marcoct avatar Oct 31 '19 07:10 marcoct

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.

dpmerrell avatar Oct 31 '19 17:10 dpmerrell

Sounds like using Distributions.jl together with Bijectors.jl could work.

xukai92 avatar Dec 12 '19 23:12 xukai92

Looks like someone is doing this in #225!

ztangent avatar Apr 07 '20 18:04 ztangent

Finally resolved by PR #495! (I also forgot that two different people took a step at this, thank you both!)

ztangent avatar Jan 30 '23 02:01 ztangent

Reopening this because we have not added dirichlet to the Gen docs!

ztangent avatar Mar 14 '24 00:03 ztangent

Resolved by #522.

ztangent avatar Mar 18 '24 20:03 ztangent

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

deoxyribose avatar Mar 28 '24 12:03 deoxyribose