Skip to content

Commit 13988b5

Browse files
committed
Remove tilde_assume as well
1 parent 707bc4e commit 13988b5

File tree

6 files changed

+22
-27
lines changed

6 files changed

+22
-27
lines changed

docs/src/api.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Part of the API of DynamicPPL is defined in the more lightweight interface packa
88

99
A core component of DynamicPPL is the [`@model`](@ref) macro.
1010
It can be used to define probabilistic models in an intuitive way by specifying random variables and their distributions with `~` statements.
11-
These statements are rewritten by `@model` as calls of [internal functions](@ref model_internal) for sampling the variables and computing their log densities.
11+
These statements are rewritten by `@model` as calls of internal functions for sampling the variables and computing their log densities.
1212

1313
```@docs
1414
@model
@@ -344,6 +344,13 @@ Base.empty!
344344
SimpleVarInfo
345345
```
346346

347+
### Tilde-pipeline
348+
349+
```@docs
350+
tilde_assume!!
351+
tilde_observe!!
352+
```
353+
347354
### Accumulators
348355

349356
The subtypes of [`AbstractVarInfo`](@ref) store the cumulative log prior and log likelihood, and sometimes other variables that change during executing, in what are called accumulators.
@@ -515,9 +522,3 @@ There is also the _experimental_ [`DynamicPPL.Experimental.determine_suitable_va
515522
DynamicPPL.Experimental.determine_suitable_varinfo
516523
DynamicPPL.Experimental.is_suitable_varinfo
517524
```
518-
519-
### [Model-Internal Functions](@id model_internal)
520-
521-
```@docs
522-
tilde_assume
523-
```

src/DynamicPPL.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ export AbstractVarInfo,
104104
DefaultContext,
105105
PrefixContext,
106106
ConditionContext,
107-
assume,
108-
tilde_assume,
107+
# Tilde pipeline
108+
tilde_assume!!,
109+
tilde_observe!!,
109110
# Initialisation
110111
InitContext,
111112
AbstractInitStrategy,

src/context_implementations.jl

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
# assume
2-
function tilde_assume(context::AbstractContext, args...)
3-
return tilde_assume(childcontext(context), args...)
2+
function tilde_assume!!(context::AbstractContext, right::Distribution, vn, vi)
3+
return tilde_assume!!(childcontext(context), right, vn, vi)
44
end
5-
function tilde_assume(::DefaultContext, right, vn, vi)
5+
function tilde_assume!!(::DefaultContext, right::Distribution, vn, vi)
66
y = getindex_internal(vi, vn)
77
f = from_maybe_linked_internal_transform(vi, vn, right)
88
x, inv_logjac = with_logabsdet_jacobian(f, y)
99
vi = accumulate_assume!!(vi, x, -inv_logjac, vn, right)
1010
return x, vi
1111
end
12-
function tilde_assume(context::PrefixContext, right, vn, vi)
12+
function tilde_assume!!(context::PrefixContext, right::Distribution, vn, vi)
1313
# Note that we can't use something like this here:
1414
# new_vn = prefix(context, vn)
15-
# return tilde_assume(childcontext(context), right, new_vn, vi)
15+
# return tilde_assume!!(childcontext(context), right, new_vn, vi)
1616
# This is because `prefix` applies _all_ prefixes in a given context to a
1717
# variable name. Thus, if we had two levels of nested prefixes e.g.
1818
# `PrefixContext{:a}(PrefixContext{:b}(DefaultContext()))`, then the
1919
# first call would apply the prefix `a.b._`, and the recursive call
2020
# would apply the prefix `b._`, resulting in `b.a.b._`.
2121
# This is why we need a special function, `prefix_and_strip_contexts`.
2222
new_vn, new_context = prefix_and_strip_contexts(context, vn)
23-
return tilde_assume(new_context, right, new_vn, vi)
23+
return tilde_assume!!(new_context, right, new_vn, vi)
2424
end
2525

2626
"""
2727
tilde_assume!!(context, right, vn, vi)
2828
2929
Handle assumed variables, e.g., `x ~ Normal()` (where `x` does occur in the model inputs),
3030
accumulate the log probability, and return the sampled value and updated `vi`.
31-
32-
By default, calls `tilde_assume(context, right, vn, vi)` and accumulates the log
33-
probability of `vi` with the returned value.
3431
"""
35-
function tilde_assume!!(context, right, vn, vi)
36-
return if right isa DynamicPPL.Submodel
37-
_evaluate!!(right, vi, context, vn)
38-
else
39-
tilde_assume(context, right, vn, vi)
40-
end
32+
function tilde_assume!!(context, right::DynamicPPL.Submodel, vn, vi)
33+
return _evaluate!!(right, vi, context, vn)
4134
end
4235

4336
# observe

src/contexts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PrefixContexts removed.
185185
186186
NOTE: This does _not_ modify any variables in any `ConditionContext` and
187187
`FixedContext` that may be present in the context stack. This is because this
188-
function is only used in `tilde_assume`, which is lower in the tilde-pipeline
188+
function is only used in `tilde_assume!!`, which is lower in the tilde-pipeline
189189
than `contextual_isassumption` and `contextual_isfixed` (the functions which
190190
actually use the `ConditionContext` and `FixedContext` values). Thus, by this
191191
time, any `ConditionContext`s and `FixedContext`s present have already served

src/contexts/init.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct InitContext{R<:Random.AbstractRNG,S<:AbstractInitStrategy} <: AbstractCon
134134
end
135135
NodeTrait(::InitContext) = IsLeaf()
136136

137-
function tilde_assume(
137+
function tilde_assume!!(
138138
ctx::InitContext, dist::Distribution, vn::VarName, vi::AbstractVarInfo
139139
)
140140
in_varinfo = haskey(vi, vn)

src/transforming.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ how to do the transformation, used by e.g. `SimpleVarInfo`.
1212
struct DynamicTransformationContext{isinverse} <: AbstractContext end
1313
NodeTrait(::DynamicTransformationContext) = IsLeaf()
1414

15-
function tilde_assume(
15+
function tilde_assume!!(
1616
::DynamicTransformationContext{isinverse}, right, vn, vi
1717
) where {isinverse}
1818
# vi[vn, right] always provides the value in unlinked space.

0 commit comments

Comments
 (0)