@@ -425,29 +425,34 @@ julia> # Returns all the variables we have conditioned on + their values.
425
425
conditioned(condition(m, x=100.0, m=1.0))
426
426
(x = 100.0, m = 1.0)
427
427
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`.)
429
432
cm = condition(contextualize(m, PrefixContext{:a}(ConditionContext((m=1.0,)))), x=100.0);
430
433
431
434
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
433
438
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.
436
441
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
439
444
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));
442
447
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
448
451
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
451
456
```
452
457
"""
453
458
conditioned (model:: Model ) = conditioned (model. context)
0 commit comments