Skip to content

Commit 31903c2

Browse files
committed
Implement tilde_assume!! for Sampleable / pointwise contexts
1 parent d066a8c commit 31903c2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/pointwise_logdensities.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ function _pointwise_tilde_observe(
146146
end
147147
end
148148

149+
# Note on submodels (penelopeysm)
150+
#
151+
# We don't need to overload tilde_observe!! for Sampleables (yet), because it
152+
# is currently not possible to evaluate a model with a Sampleable on the RHS
153+
# of an observe statement.
154+
#
155+
# Note that calling tilde_assume!! on a Sampleable does not necessarily imply
156+
# that there are no observe statements inside the Sampleable. There could well
157+
# be likelihood terms in there, which must be included in the returned logp.
158+
# See e.g. the `demo_dot_assume_observe_submodel` demo model.
159+
#
160+
# This is handled by passing the same context to rand_like!!, which figures out
161+
# which terms to include using the context, and also mutates the context and vi
162+
# appropriately. Thus, we don't need to check against _include_prior(context)
163+
# here.
164+
function tilde_assume!!(context::PointwiseLogdensityContext, right::Sampleable, vn, vi)
165+
value, vi = DynamicPPL.rand_like!!(right, context, vi)
166+
return value, vi
167+
end
168+
149169
function tilde_assume!!(context::PointwiseLogdensityContext, right, vn, vi)
150170
!_include_prior(context) && return (tilde_assume!!(context.context, right, vn, vi))
151171
value, logp, vi = tilde_assume(context.context, right, vn, vi)

0 commit comments

Comments
 (0)