-
Notifications
You must be signed in to change notification settings - Fork 162
Description
What if Distribution were a subtype of GenerativeFunction?
This would simplify implementations of some combinators and DSLs. For example, instead of having separate code to handle @traceing a distribution and generative function, we could only ever trace generative functions--and distributions just have the GFI implemented for them! Likewise, what if I want to have a generative function sample from a poisson 100 times? If we had Distribution <: GenerativeFunction, then we could simply use Map(poisson).
We would need a trace type to store a value from the distribution, for instance
struct DistributionTrace{Dist}
args
val
end
get_args(tr:: DistributionTrace) = tr.args
get_retval(tr:: DistributionTrace) = tr.val
function get_score(tr::DistributionTrace{Dist}) where {Dist}
logpdf(Dist(), tr.val, tr.args...)
end
get_gen_fn(tr::DistributionTrace{Dist}) where {Dist} = Dist()To implement get_choices it seems like we would need a choicemap which has no address, and a single value. I think changing the definition of a choicemap to support this is worth considering; I have opened issue #258 to discuss this. Following my proposal in this issue, we could define
get_choices(tr::DistributionTrace) = ValueChoiceMap(tr.val)I think implementing generate, simulate, update, and regenerate would be pretty straightforward. The internal proposal distribution and the distribution for a Distribution generative function would be the same: the Distribution itself.