Skip to content

Commit 8129eb9

Browse files
Merge pull request #864 from stan-dev/exposed-transforms
Document built-in transformation functions
2 parents a6099b2 + 949aa23 commit 8129eb9

7 files changed

Lines changed: 796 additions & 6 deletions

File tree

src/_quarto.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ website:
212212
- functions-reference/mixed_operations.qmd
213213
- functions-reference/compound_arithmetic_and_assignment.qmd
214214
- functions-reference/higher-order_functions.qmd
215+
- functions-reference/transform_functions.qmd
215216
- functions-reference/deprecated_functions.qmd
216217
- functions-reference/removed_functions.qmd
217218
- functions-reference/conventions_for_probability_functions.qmd

src/functions-reference/_quarto.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ book:
4747
- mixed_operations.qmd
4848
- compound_arithmetic_and_assignment.qmd
4949
- higher-order_functions.qmd
50+
- transform_functions.qmd
5051
- deprecated_functions.qmd
5152
- removed_functions.qmd
5253
- conventions_for_probability_functions.qmd

src/functions-reference/functions_index.qmd

Lines changed: 225 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions-reference/transform_functions.qmd

Lines changed: 553 additions & 0 deletions
Large diffs are not rendered by default.

src/reference-manual/statements.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ For example, here is a program which recreates the existing
378378

379379
```stan
380380
functions {
381-
real upper_bound_jacobian(real x, real ub) {
381+
real my_upper_bound_jacobian(real x, real ub) {
382382
jacobian += x;
383383
return ub - exp(x);
384384
}
@@ -390,7 +390,7 @@ parameters {
390390
real b_raw;
391391
}
392392
transformed parameters {
393-
real b = upper_bound_jacobian(b_raw, ub);
393+
real b = my_upper_bound_jacobian(b_raw, ub);
394394
}
395395
model {
396396
// use b as if it was declared `real<upper=ub> b;` in parameters

src/reference-manual/transforms.qmd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This chapter provides a definition of the transforms used for each
1717
type of variable. For examples of how to declare and define these
1818
variables in a Stan program, see section
1919
[Variable declaration](types.qmd#variable-declaration.section).
20+
To directly access the functional form of these transformations
21+
from inside the Stan language, see [Variable Transformation Functions](https://mc-stan.org/docs/functions-reference/transform_functions.html)
22+
in the _Functions Reference_.
2023

2124
Stan converts models to C++ classes which define probability
2225
functions with support on all of $\mathbb{R}^K$, where $K$ is the number
@@ -459,6 +462,13 @@ p_Y(y)
459462
$$
460463

461464

465+
## Positive ordered vector
466+
467+
Placeholder.
468+
469+
The positive ordered transformation is defined in the same style
470+
as the ordered transformation above, but with the first element being
471+
exponentiated to ensure positivity.
462472

463473
## Zero sum vector
464474

@@ -753,7 +763,7 @@ $$
753763

754764
## Stochastic Matrix {#stochastic-matrix-transform.section}
755765

756-
The `column_stochastic_matrix[N, M]` and `row_stochastic_matrix[N, M]` type in
766+
The `column_stochastic_matrix[N, M]` and `row_stochastic_matrix[M, N]` type in
757767
Stan represents an $N \times M$ matrix where each column (row) is a unit simplex
758768
of dimension $N$. In other words, each column (row) of the matrix is a vector
759769
constrained to have non-negative entries that sum to one.

src/stan-users-guide/user-functions.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ change of variables for arbitrary parameters.
296296
For example, this function recreates the built-in
297297
`<upper=x>` transform on real numbers:
298298
```stan
299-
real upper_bound_jacobian(real x, real ub) {
299+
real my_upper_bound_jacobian(real x, real ub) {
300300
jacobian += x;
301301
return ub - exp(x);
302302
}
@@ -306,7 +306,7 @@ It can be used as a replacement for `real<lower=ub>` as follows:
306306

307307
```stan
308308
functions {
309-
// upper_bound_jacobian as above
309+
// my_upper_bound_jacobian as above
310310
}
311311
data {
312312
real ub;
@@ -315,7 +315,7 @@ parameters {
315315
real b_raw;
316316
}
317317
transformed parameters {
318-
real b = upper_bound_jacobian(b_raw, ub);
318+
real b = my_upper_bound_jacobian(b_raw, ub);
319319
}
320320
model {
321321
b ~ lognormal(0, 1);

0 commit comments

Comments
 (0)