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: usage/tracking-extra-quantities/index.qmd
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Pkg.instantiate();
15
15
16
16
Often, there are quantities in models that we might be interested in viewing the values of, but which are not random variables in the model that are explicitly drawn from a distribution.
17
17
18
-
As a motivating example, the most natural parameterization for a model might not the most computationally feasible.
18
+
As a motivating example, the most natural parameterization for a model might not be the most computationally feasible.
19
19
Consider the following (efficiently reparametrized) implementation of Neal's funnel [(Neal, 2003)](https://arxiv.org/abs/physics/0009028):
20
20
21
21
```{julia}
@@ -96,9 +96,9 @@ There are some pros and cons of using `returned`, as opposed to `:=`.
96
96
Firstly, `returned` is more flexible, as it allows you to track any type of object; `:=` only works with variables that can be inserted into an `MCMCChains.Chains` object.
97
97
(Notice that `x` is a vector, and in the first case where we used `:=`, reconstructing the vector value of `x` can also be rather annoying as the chain stores each individual element of `x` separately.)
98
98
99
-
However, if used carelessly, `returned` can lead to unnecessary computation.
100
-
For example, in `Neal_return()` above, the `x` and `y` variables are also calculated during the inference process (i.e. the call to `sample()`), but are then thrown away.
101
-
They are then calculated _again_ when `returned()` is called.
99
+
A drawback is that naively using `returned` can lead to unnecessary computation during inference.
100
+
This is because during the sampling process, the return values are also calculated (since they are part of the model function), but then thrown away.
101
+
So, if the extra quantities are expensive to compute, this can be a problem.
102
102
103
103
To avoid this, you will essentially have to create two different models, one for inference and one for post-inference.
104
104
The simplest way of doing this is to add a parameter to the model argument:
0 commit comments