1
- # assume
1
+ """
2
+ tilde_assume!!(context, right::Distribution, vn, vi)
3
+
4
+ Handle assumed variables, e.g., `x ~ Normal()` (where `x` does occur in the model inputs),
5
+ accumulate the log probability, and return the sampled value and updated `vi`.
6
+
7
+ tilde_assume!!(context, right::DynamicPPL.Submodel, vn, vi)
8
+
9
+ Evaluate the submodel with the given context.
10
+ """
2
11
function tilde_assume!! (context:: AbstractContext , right:: Distribution , vn, vi)
3
12
return tilde_assume!! (childcontext (context), right, vn, vi)
4
13
end
@@ -22,24 +31,23 @@ function tilde_assume!!(context::PrefixContext, right::Distribution, vn, vi)
22
31
new_vn, new_context = prefix_and_strip_contexts (context, vn)
23
32
return tilde_assume!! (new_context, right, new_vn, vi)
24
33
end
34
+ function tilde_assume!! (context:: AbstractContext , right:: DynamicPPL.Submodel , vn, vi)
35
+ return _evaluate!! (right, vi, context, vn)
36
+ end
25
37
26
38
"""
27
- tilde_assume !!(context, right, vn, vi)
39
+ tilde_observe !!(context, right::Distribution, left , vn, vi)
28
40
29
- Handle assumed variables, e.g., `x ~ Normal()` (where `x` does occur in the model inputs),
30
- accumulate the log probability, and return the sampled value and updated `vi`.
31
- """
32
- function tilde_assume!! (context, right:: DynamicPPL.Submodel , vn, vi)
33
- return _evaluate!! (right, vi, context, vn)
34
- end
41
+ Handle observed variables, e.g., `x ~ Normal()` (where `x` does occur in the model inputs),
42
+ accumulate the log probability, and return the observed value and updated `vi`.
35
43
36
- # observe
37
- function tilde_observe!! (context:: AbstractContext , right, left, vn, vi)
44
+ Falls back to `tilde_observe!!(context, right, left, vi)` ignoring the information about
45
+ variable name and indices; if needed, these can be accessed through this function, though.
46
+ """
47
+ function tilde_observe!! (context:: AbstractContext , right:: Distribution , left, vn, vi)
38
48
return tilde_observe!! (childcontext (context), right, left, vn, vi)
39
49
end
40
-
41
- # `PrefixContext`
42
- function tilde_observe!! (context:: PrefixContext , right, left, vn, vi)
50
+ function tilde_observe!! (context:: PrefixContext , right:: Distribution , left, vn, vi)
43
51
# In the observe case, unlike assume, `vn` may be `nothing` if the LHS is a literal
44
52
# value. For the need for prefix_and_strip_contexts rather than just prefix, see the
45
53
# comment in `tilde_assume!!`.
@@ -50,21 +58,10 @@ function tilde_observe!!(context::PrefixContext, right, left, vn, vi)
50
58
end
51
59
return tilde_observe!! (new_context, right, left, new_vn, vi)
52
60
end
53
-
54
- """
55
- tilde_observe!!(context, right, left, vn, vi)
56
-
57
- Handle observed variables, e.g., `x ~ Normal()` (where `x` does occur in the model inputs),
58
- accumulate the log probability, and return the observed value and updated `vi`.
59
-
60
- Falls back to `tilde_observe!!(context, right, left, vi)` ignoring the information about variable name
61
- and indices; if needed, these can be accessed through this function, though.
62
- """
63
61
function tilde_observe!! (:: DefaultContext , right:: Distribution , left, vn, vi)
64
62
vi = accumulate_observe!! (vi, right, left, vn)
65
63
return left, vi
66
64
end
67
-
68
- function tilde_observe!! (:: DefaultContext , :: DynamicPPL.Submodel , left, vn, vi)
65
+ function tilde_observe!! (:: AbstractContext , :: DynamicPPL.Submodel , left, vn, vi)
69
66
throw (ArgumentError (" `x ~ to_submodel(...)` is not supported when `x` is observed" ))
70
67
end
0 commit comments