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/api.md
+30-8Lines changed: 30 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,12 +14,6 @@ These statements are rewritten by `@model` as calls of [internal functions](@ref
14
14
@model
15
15
```
16
16
17
-
One can nest models and call another model inside the model function with [`@submodel`](@ref).
18
-
19
-
```@docs
20
-
@submodel
21
-
```
22
-
23
17
### Type
24
18
25
19
A [`Model`](@ref) can be created by calling the model function, as defined by [`@model`](@ref).
@@ -110,6 +104,34 @@ Similarly, we can [`unfix`](@ref) variables, i.e. return them to their original
110
104
unfix
111
105
```
112
106
107
+
## Models within models
108
+
109
+
One can include models and call another model inside the model function with `left ~ to_submodel(model)`.
110
+
111
+
```@docs
112
+
to_submodel
113
+
```
114
+
115
+
Note that a `[to_submodel](@ref)` is only sampleable; one cannot compute `logpdf` for its realizations.
116
+
117
+
In the past, one would instead embed sub-models using [`@submodel`](@ref), which has been deprecated since the introduction of [`to_submodel(model)`](@ref)
118
+
119
+
```@docs
120
+
@submodel
121
+
```
122
+
123
+
In the context of including models within models, it's also useful to prefix the variables in sub-models to avoid variable names clashing:
124
+
125
+
```@docs
126
+
prefix
127
+
```
128
+
129
+
Under the hood, [`to_submodel`](@ref) makes use of the following method to indicate that the model it's wrapping is a model over its return-values rather than something else
130
+
131
+
```@docs
132
+
returned(::Model)
133
+
```
134
+
113
135
## Utilities
114
136
115
137
It is possible to manually increase (or decrease) the accumulated log density from within a model function.
@@ -118,10 +140,10 @@ It is possible to manually increase (or decrease) the accumulated log density fr
118
140
@addlogprob!
119
141
```
120
142
121
-
Return values of the model function for a collection of samples can be obtained with [`generated_quantities`](@ref).
143
+
Return values of the model function for a collection of samples can be obtained with [`returned(model, chain)`](@ref).
122
144
123
145
```@docs
124
-
generated_quantities
146
+
returned(::DynamicPPL.Model, ::NamedTuple)
125
147
```
126
148
127
149
For a chain of samples, one can compute the pointwise log-likelihoods of each observed random variable with [`pointwise_loglikelihoods`](@ref). Similarly, the log-densities of the priors using
0 commit comments