Open torfjelde opened 9 months ago
@devmotion @yebai Probably of interest
Good idea to get rid of Selector
and Sampler
as indexing objects. It is also probably fine to temporarily break particle Gibbs during the transition -- we can fix PG when the design of the new trace object is more stable.
The problem
Currently, DynamicPPL.jl supports implementation of Gibbs sampling through usages of
Selector
s andgids
, which are effectively ways for each instance ofSampler
to define it's unique "Gibbs ID" and then subsequently which sampler that particular realization present inVarInfo
came from.All of this machinery is complicated and means that samplers outside of DynamicPPL are not compatible without an annoying amount of code needed.
In https://github.com/TuringLang/Turing.jl/pull/2099 we're introducing an alternative approach to a
Gibbs
sampler which makes use of thecondition
functionality to define a sequence of conditionedModel
s, whose random variables are then restricted to only those that a particular sampler needs.This has the following benefits:
Gibbs
on aModel
, simply needs to be able to sample from aModel
(which, thanks toDynamicPPL.LogDensityFunction
is quite easy in most cases).Selector
andgids
since all the variables present in aVarInfo
is supposed to be sampled.VarInfo
are not supposed to be sampled and some are"-convention, we can also remove some of the more unfortunate tilde-implementations, e.g.DynamicPPL.get_and_set_val
, and instead fully adopt the convention that: if we're using aSamplingContext
, things might get resampled, and if we're not using aSamplingContext
, then things are not to be sampled. This will then also remove the need fordel
falgs, etc.Currently the sampler introduced in https://github.com/TuringLang/Turing.jl/pull/2099 does still depend on a small part of this
Selector
-business, but it does so only to stay comaptible with the current DynamicPPL. Once we remove this from DynamicPPL, we can remove the oldGibbs
sampler in Turing.jl, and finally move completely away from this stuff.Things we need to do
Here's some rough things we need to get done (this will be probably change):
Turing.Experimental.Gibbs
on a diverse set of problems to make sure it works as expected.Selector
andgids
.Sampler
to as an indexing object, etc.