@@ -177,13 +177,15 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
177177 # Fall back to the default behavior.
178178 DynamicPPL. tilde_assume (child_context, right, vn, vi)
179179 elseif has_conditioned_gibbs (context, vn)
180- # Short-circuit the tilde assume if `vn` is present in `context`.
181- # TODO (mhauru) Fix accumulation here. In this branch anything that gets
182- # accumulated just gets discarded with `_`.
183- value, _ = DynamicPPL. tilde_assume (
184- child_context, right, vn, get_global_varinfo (context)
185- )
186- value, vi
180+ # This branch means that a different sampler is supposed to handle this
181+ # variable. From the perspective of this sampler, this variable is
182+ # conditioned on, so we can just treat it as an observation.
183+ # The only catch is that the value that we need is to be obtained from
184+ # the global VarInfo (since the local VarInfo has no knowledge of it).
185+ # Note that tilde_observe!! will trigger resampling in particle methods
186+ # for variables that are handled by other Gibbs component samplers.
187+ val = get_conditioned_gibbs (context, vn)
188+ DynamicPPL. tilde_observe!! (child_context, right, val, vn, vi)
187189 else
188190 # If the varname has not been conditioned on, nor is it a target variable, its
189191 # presumably a new variable that should be sampled from its prior. We need to add
@@ -210,13 +212,25 @@ function DynamicPPL.tilde_assume(
210212 vn, child_context = DynamicPPL. prefix_and_strip_contexts (child_context, vn)
211213
212214 return if is_target_varname (context, vn)
215+ # This branch means that that `sampler` is supposed to handle
216+ # this variable. We can thus use its default behaviour, with
217+ # the 'local' sampler-specific VarInfo.
213218 DynamicPPL. tilde_assume (rng, child_context, sampler, right, vn, vi)
214219 elseif has_conditioned_gibbs (context, vn)
215- value, _ = DynamicPPL. tilde_assume (
216- child_context, right, vn, get_global_varinfo (context)
217- )
218- value, vi
220+ # This branch means that a different sampler is supposed to handle this
221+ # variable. From the perspective of this sampler, this variable is
222+ # conditioned on, so we can just treat it as an observation.
223+ # The only catch is that the value that we need is to be obtained from
224+ # the global VarInfo (since the local VarInfo has no knowledge of it).
225+ # Note that tilde_observe!! will trigger resampling in particle methods
226+ # for variables that are handled by other Gibbs component samplers.
227+ val = get_conditioned_gibbs (context, vn)
228+ DynamicPPL. tilde_observe!! (child_context, right, val, vn, vi)
219229 else
230+ # If the varname has not been conditioned on, nor is it a target variable, its
231+ # presumably a new variable that should be sampled from its prior. We need to add
232+ # this new variable to the global `varinfo` of the context, but not to the local one
233+ # being used by the current sampler.
220234 value, new_global_vi = DynamicPPL. tilde_assume (
221235 rng,
222236 child_context,
0 commit comments