In Gen, a Distribution{T}
is a specific kind of generative function that stores a single
value in its ChoiceMap
. That value is also the return value of the Distribution.
Gen provides default implementations of the GFI for new subtypes of Distribution{T}
(like Normal
)
that implement the distribution interface (random
, logpdf
, is_discrete
, and other
methods for gradient-based inference).
GenSP introduces a new subtype SPDistribution{T} <: Distribution{T}
. Users can declare
new subtypes of SPDistribution{T}
and instead of implementing random
and logpdf
,
implement random_weighted
and estimate_logpdf
.
GenSP exposes a new library for inference. It works a lot like Gen's inference library, with the following key differences:
-
In GenSP, inference algorithms are themselves generative functions. In particular, GenSP's inference algorithms are
SPDistribution{ChoiceMap}
s that take as input aTarget
posterior and produce as output aChoiceMap
approximately sampled from the posterior. (Target
is a struct type that GenSP exposes, wrapping together a generative function, arguments to it, and aChoiceMap
of observations.) Because inference algorithms areSPDistribution
s, they can estimate their own output densities. -
Instead of proposal generative functions, GenSP inference methods accept proposal distributions -- distributions over
ChoiceMap
s containing the unconstrained choices of the target. Such distributions can be obtained from generative functions by using theChoiceMapDistribution
combinator. That combinator can also be used to marginalize auxiliary variables from proposals, by selecting only the choices meant to serve as the proposal.
New distributions can be created by marginalizing generative functions:
Marginal{T}(gen_fn, inf_alg, addr)
-- the marginal distribution of the choice at addressaddr
ingen_fn
.ChoiceMapDistribution(gen_fn, selection=AllSelection(), inf_alg=default_importance(1))
-- the marginal distribution ofselection
undergen_fn
.