@@ -177,13 +177,15 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
177
177
# Fall back to the default behavior.
178
178
DynamicPPL. tilde_assume (child_context, right, vn, vi)
179
179
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)
187
189
else
188
190
# If the varname has not been conditioned on, nor is it a target variable, its
189
191
# presumably a new variable that should be sampled from its prior. We need to add
@@ -210,13 +212,25 @@ function DynamicPPL.tilde_assume(
210
212
vn, child_context = DynamicPPL. prefix_and_strip_contexts (child_context, vn)
211
213
212
214
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.
213
218
DynamicPPL. tilde_assume (rng, child_context, sampler, right, vn, vi)
214
219
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)
219
229
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.
220
234
value, new_global_vi = DynamicPPL. tilde_assume (
221
235
rng,
222
236
child_context,
0 commit comments