In probabilistic programming, we use a a lot of distributions. In some settings, it’s important for it to be very easy to define new distributions, and to reason about them.
The current type of a Distribution
or Sampleable
is
help?> Sampleable
search: Sampleable
Sampleable{F<:VariateForm,S<:ValueSupport}
Sampleable is any type able to produce random values. Parametrized by a
VariateForm defining the dimension of samples and a ValueSupport defining the
domain of possibly sampled values. Any Sampleable implements the Base.rand
method.
First we have to say whether a returned value is Univariate
, Multivariate
, or Matrixvariate
. Then we have to say whether it’s Discrete
or Continuous
.
But all of this information is available from the type of the result. Why not just Sampleable{T}
? Then…
-
sample(::Sampleable{T})
returns a value of typeT
-
Sampleable{Int}
is clearly univariate discrete -
Sampleable{Vector{Float}}
is multivariate continuous
In the current setup, say I want a distribution over trees. Then I have to define a new Treevariate
type, and decide whether my trees will be continuous or discrete, or what that even means. Sampleable{Tree{MoreParams}}
would do this just fine.
In practice, the heavy weight of implementing all of this often leads me to sidestep Distributions entirely. For example, in Soss I have an EqualMix
combinator that gives a mixture model with equal-weight components. I define it as
struct EqualMix{T}
components::Vector{T}
end
and add some methods, and it works just fine. If I could tell it T
should be a Distribution, that would be better. But the current setup doesn’t seem to me to map well to the domain.
Am I missing something? What’s the big benefit of the current approach?