Skip to content

Commit 8ab47f7

Browse files
committed
Fix doctest
1 parent 2d6de8c commit 8ab47f7

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/model.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -425,29 +425,34 @@ julia> # Returns all the variables we have conditioned on + their values.
425425
conditioned(condition(m, x=100.0, m=1.0))
426426
(x = 100.0, m = 1.0)
427427
428-
julia> # Nested ones also work (note that `PrefixContext` does nothing to the result).
428+
julia> # Nested ones also work.
429+
# (Note that `PrefixContext` also prefixes the variables of any
430+
# ConditionContext that is _inside_ it; because of this, the type of the
431+
# container has to be broadened to a `Dict`.)
429432
cm = condition(contextualize(m, PrefixContext{:a}(ConditionContext((m=1.0,)))), x=100.0);
430433
431434
julia> conditioned(cm)
432-
(x = 100.0, m = 1.0)
435+
Dict{VarName, Any} with 2 entries:
436+
a.m => 1.0
437+
x => 100.0
433438
434-
julia> # Since we conditioned on `m`, not `a.m` as it will appear after prefixed,
435-
# `a.m` is treated as a random variable.
439+
julia> # Since we conditioned on `a.m`, it is not treated as a random variable.
440+
# However, `a.x` will still be a random variable.
436441
keys(VarInfo(cm))
437-
1-element Vector{VarName{:a, Accessors.PropertyLens{:m}}}:
438-
a.m
442+
1-element Vector{VarName{:a, Accessors.PropertyLens{:x}}}:
443+
a.x
439444
440-
julia> # If we instead condition on `a.m`, `m` in the model will be considered an observation.
441-
cm = condition(contextualize(m, PrefixContext{:a}(ConditionContext(Dict(@varname(a.m) => 1.0)))), x=100.0);
445+
julia> # We can also condition on `a.m` _outside_ of the PrefixContext:
446+
cm = condition(contextualize(m, PrefixContext{:a}(DefaultContext())), (@varname(a.m) => 1.0));
442447
443-
julia> conditioned(cm)[@varname(x)]
444-
100.0
445-
446-
julia> conditioned(cm)[@varname(a.m)]
447-
1.0
448+
julia> conditioned(cm)
449+
Dict{VarName{:a, Accessors.PropertyLens{:m}}, Float64} with 1 entry:
450+
a.m => 1.0
448451
449-
julia> keys(VarInfo(cm)) # No variables are sampled
450-
VarName[]
452+
julia> # Now `a.x` will be sampled.
453+
keys(VarInfo(cm))
454+
1-element Vector{VarName{:a, Accessors.PropertyLens{:x}}}:
455+
a.x
451456
```
452457
"""
453458
conditioned(model::Model) = conditioned(model.context)

0 commit comments

Comments
 (0)