Skip to content

Issue/870 affine xform clarification #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/quarto-config
2 changes: 1 addition & 1 deletion src/reference-manual/transforms.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ $$

The default value for the offset $\mu$ is $0$ and for the multiplier $\sigma$ is
$1$ in case not both are specified.

For a container variable, the affine transform is applied to each element of that variable.

### Affine inverse transform {-}

Expand Down
21 changes: 21 additions & 0 deletions src/reference-manual/types.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,27 @@ model {
}
```

For a container variable, the affine transform is applied to each element of that variable.
As an example, the non-centered parameterization of Neal's Funnel in the
[Stan User's Guide reparameterization section](https://mc-stan.org/docs/stan-users-guide/reparameterization.html),
$$
p(y,x) = \textsf{normal}(y \mid 0,3) \times \prod_{n=1}^9
\textsf{normal}(x_n \mid 0,\exp(y/2)).
$$
can be written as:

```stan
parameters {
real<multiplier=3> y;
vector<multiplier=exp(y/2)>[9] x;
}
model {
y ~ std_normal();
x ~ std_normal();
}
```
where the affine transform is applied to every element of vector `x`.

### Expressions as bounds and offset/multiplier {-}

Bounds (and offset and multiplier)
Expand Down
30 changes: 20 additions & 10 deletions src/stan-users-guide/efficiency-tuning.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ funnel's neck is particularly sharp because of the exponential
function applied to $y$. A plot of the log marginal density of $y$
and the first dimension $x_1$ is shown in the following plot.



The funnel can be implemented directly in Stan as follows.

```stan
Expand Down Expand Up @@ -327,14 +325,26 @@ model {
```

In this second model, the parameters `x_raw` and `y_raw` are
sampled as independent standard normals, which is easy for Stan. These
are then transformed into samples from the funnel. In this case, the
same transform may be used to define Monte Carlo samples directly
based on independent standard normal samples; Markov chain Monte Carlo
methods are not necessary. If such a reparameterization were used in
Stan code, it is useful to provide a comment indicating what the
distribution for the parameter implies for the distribution of the
transformed parameter.
sampled as independent standard normals, which is easy for Stan,
and then transformed into samples from the funnel.
When this reparameterization is used in Stan code, a comment indicating what the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although they are technically reparameterizations under the hood, I think we should stick to calling them transforms. The terminology is confusing if you have any suggestions---the problem is that with the affine transform there is no constraining or unconstraining. The domain and range of the transform function are the same---it's just a bijection over the whole real number line.

distribution for the parameter implies for the distribution of the transformed parameter
will improve readibility and maintainability.

As of Stan release v2.19.0, this program can be written using Stan's
[affinely transformed real type](https://mc-stan.org/docs/reference-manual/types.html#affine-transform.section).
The affine transform on the vector `x` is applied to each element of `x`.

```stan
parameters {
real<multiplier=3> y;
vector<multiplier=exp(y/2)>[9] x;
}
model {
y ~ std_normal(); // implies y ~ normal(0, 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue as above.

x ~ std_normal(); // implies x ~ normal(0, exp(y/2))
}
```

### Reparameterizing the Cauchy {-}

Expand Down