You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/nested_models.md
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,4 +30,43 @@ If we want to chain these `gcv` submodels together into a Hierarchical Gaussian
30
30
end
31
31
```
32
32
33
-
Note that in our invocations of `gcv`, we haven't specified the `y` argument of the Markov Blanket. This is what is being recognized as the missing interface and `GraphPPL` will assign `means[i]` to `y`.
33
+
Note that in our invocations of `gcv`, we haven't specified the `y` argument of the Markov Blanket. This is what is being recognized as the missing interface and `GraphPPL` will assign `means[i]` to `y`.
34
+
35
+
## Multi-output submodels
36
+
37
+
When a submodel produces multiple outputs — multiple interfaces left unspecified on the RHS — you can bind them all on the LHS using a tuple. There are two syntaxes:
38
+
39
+
**Positional:** list outer variables in the same order as the unspecified interfaces appear in the submodel definition.
40
+
41
+
```@example nested-models
42
+
@model function linear_gaussian(x, y, z)
43
+
x ~ Normal(z, 1)
44
+
y ~ Normal(x, 1)
45
+
end
46
+
47
+
@model function outer_positional(c)
48
+
(a, b) ~ linear_gaussian(z = c) # a → interface x, b → interface y (by position)
49
+
end
50
+
```
51
+
52
+
**Named (kwarg-style):** explicitly map each outer variable to its interface name using `name = var` pairs. This is order-independent and recommended when submodel argument order may change.
53
+
54
+
```@example nested-models
55
+
@model function outer_named(my_z)
56
+
(y = my_y, x = my_x) ~ linear_gaussian(z = my_z) # binds by name, regardless of order
57
+
obs ~ Normal(my_x, my_y)
58
+
end
59
+
```
60
+
61
+
Both syntaxes work with indexed variables in loops:
62
+
63
+
```@example nested-models
64
+
@model function chain(z, n)
65
+
for i in 1:n
66
+
(x = xs[i], y = ys[i]) ~ linear_gaussian(z = z)
67
+
end
68
+
end
69
+
```
70
+
71
+
!!! note
72
+
If the same interface name appears on both LHS and RHS, `GraphPPL` raises an error at model-creation time. Similarly, providing a name on the LHS that does not match any of the submodel's interface names is caught with a descriptive error.
0 commit comments