Skip to content

Commit ced224b

Browse files
committed
Clarify extra computation in returned()
1 parent 1a6d726 commit ced224b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

usage/tracking-extra-quantities/index.qmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Pkg.instantiate();
1515

1616
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.
1717

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.
1919
Consider the following (efficiently reparametrized) implementation of Neal's funnel [(Neal, 2003)](https://arxiv.org/abs/physics/0009028):
2020

2121
```{julia}
@@ -96,9 +96,9 @@ There are some pros and cons of using `returned`, as opposed to `:=`.
9696
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.
9797
(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.)
9898

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.
102102

103103
To avoid this, you will essentially have to create two different models, one for inference and one for post-inference.
104104
The simplest way of doing this is to add a parameter to the model argument:

0 commit comments

Comments
 (0)