Skip to content

Commit 84af3f8

Browse files
committed
update with @bob-carpenter review comments
1 parent 8370bdb commit 84af3f8

File tree

2 files changed

+55
-54
lines changed

2 files changed

+55
-54
lines changed

src/reference-manual/transforms.qmd

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ constrained to be ordered, positive ordered, or simplexes. Matrices
1515
may be constrained to be correlation matrices or covariance matrices.
1616
This chapter provides a definition of the transforms used for each
1717
type of variable. For examples of how to declare and define these
18-
variables in a Stan program, see section
18+
variables in a Stan program, see section
1919
[Variable declaration](types.qmd#variable-declaration.section).
2020

2121
Stan converts models to C++ classes which define probability
@@ -39,7 +39,7 @@ the exact arithmetic:
3939
rounded to the boundary. This may cause unexpected warnings or
4040
errors, if in other parts of the code the boundary value is
4141
invalid. For example, we may observe floating-point value 0 for
42-
a variance parameter that has been declared to be larger than 0.
42+
a variance parameter that has been declared to be larger than 0.
4343
See more about [Floating point Arithmetic in Stan user's guide](../stan-users-guide/floating-point.qmd)).
4444
- CmdStan stores the output to CSV files with 6 significant digits
4545
accuracy by default, but the constraints are checked with 8
@@ -674,61 +674,61 @@ $$
674674

675675
## Stochastic Matrix {#stochastic-matrix-transform.section}
676676

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

682682
### Definition of a Stochastic Matrix {-}
683683

684-
A column stochastic matrix \(X \in \mathbb{R}^{N \times M}\) is defined such
685-
that for each column \(j\) (where \(1 \leq j \leq M\)):
684+
A column stochastic matrix \(X \in \mathbb{R}^{N \times M}\) is defined such
685+
that each column is a simplex. For column \(j\) (where \(1 \leq j \leq M\)):
686686

687687
$$
688-
X_{ij} \geq 0 \quad \text{for } 1 \leq i \leq N,
688+
X_{i, j} \geq 0 \quad \text{for } 1 \leq i \leq N,
689689
$$
690690

691691
and
692692

693693
$$
694-
\sum_{i=1}^N X_{ij} = 1.
694+
\sum_{i=1}^N X_{i, j} = 1.
695695
$$
696696

697-
A row stochastic matrix is defined similarly but with the axis flipped such
698-
that
697+
A row stochastic matrix is any matrix whose transpose is a column stochastic matrix
698+
(i.e. the rows of the matrix are simplexes)
699699

700700

701701
$$
702-
X_{ij} \geq 0 \quad \text{for } 1 \leq j \leq N,
702+
X_{i, j} \geq 0 \quad \text{for } 1 \leq j \leq N,
703703
$$
704704

705705
and
706706

707707
$$
708-
\sum_{j=1}^N X_{ij} = 1.
708+
\sum_{j=1}^N X_{i, j} = 1.
709709
$$
710710

711-
This definition ensures that each column(row) of the matrix \(X\) lies on the
712-
\(N-1\) dimensional unit simplex, similar to the `simplex[N]` type, but
711+
This definition ensures that each column (row) of the matrix \(X\) lies on the
712+
\(N-1\) dimensional unit simplex, similar to the `simplex[N]` type, but
713713
extended across multiple columns(rows).
714714

715715
### Inverse Transform for Stochastic Matrix {-}
716716

717717
For the column and row stochastic matrices the inverse transform is the same
718-
as simplex, but applied to each column(row).
718+
as simplex, but applied to each column (row).
719719

720720
### Absolute Jacobian Determinant for the Inverse Transform {-}
721721

722-
The Jacobian determinant of the inverse transform for each column \(j\) in
723-
the matrix is given by the product of the diagonal entries \(J_{i,i,j}\) of
722+
The Jacobian determinant of the inverse transform for each column \(j\) in
723+
the matrix is given by the product of the diagonal entries \(J_{i,i,j}\) of
724724
the lower-triangular Jacobian matrix. This determinant is calculated as:
725725

726726
$$
727-
\left| \det J_j \right| = \prod_{i=1}^{N-1} \left( z_{ij} (1 - z_{ij}) \left( 1 - \sum_{i'=1}^{i-1} X_{i'j} \right) \right).
727+
\left| \det J_j \right| = \prod_{i=1}^{N-1} \left( z_{i, j} (1 - z_{i, j}) \left( 1 - \sum_{i'=1}^{i-1} X_{i'j} \right) \right).
728728
$$
729729

730-
Thus, the overall Jacobian determinant for the entire `column_stochastic_matrix` and `row_stochastic_matrix`
731-
is the product of the determinants for each column(row):
730+
Thus, the overall Jacobian determinant for the entire `column_stochastic_matrix` and `row_stochastic_matrix`
731+
is the product of the determinants for each column (row):
732732

733733
$$
734734
\left| \det J \right| = \prod_{j=1}^{M} \left| \det J_j \right|.
@@ -737,7 +737,7 @@ $$
737737
### Transform for Stochastic Matrix {-}
738738

739739
For the column and row stochastic matrices the transform is the same
740-
as simplex, but applied to each column(row).
740+
as simplex, but applied to each column (row).
741741

742742
## Unit vector {#unit-vector.section}
743743

src/reference-manual/types.qmd

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,10 @@ priors for some parameters.
675675

676676
### Stochastic Matrices {-}
677677

678-
A stochastic matrix is a matrix where each column, row, or both is a
679-
unit simplex, meaning that each column(row) vector has non-negative
680-
values that sum to 1. For example, a \(3 \times 4\)
681-
column stochastic matrix will look like:
678+
A stochastic matrix is a matrix where each column, row, or both is a
679+
unit simplex, meaning that each column (row) vector has non-negative
680+
values that sum to 1. The following example is a \(3 \times 4\)
681+
column-stochastic matrix.
682682

683683
$$
684684
\begin{bmatrix}
@@ -688,7 +688,7 @@ $$
688688
\end{bmatrix}
689689
$$
690690

691-
While a row stochastic matrix will look like:
691+
An example of a \(3 \times 4\) row-stochastic matrix is the following.
692692

693693
$$
694694
\begin{bmatrix}
@@ -699,54 +699,55 @@ $$
699699
$$
700700

701701

702-
In this example, each column(row) sums to 1, making the matrix a
703-
valid `column_stochastic_matrix` and `row_stochastic_matrix`.
702+
In the examples above, each column (or row) sums to 1, making the matrices
703+
valid `column_stochastic_matrix` and `row_stochastic_matrix` types.
704704

705-
Column stochastic matrices are often used in models where
706-
each column represents a probability distribution across a
707-
set of categories, such as in multiple multinomial distributions,
708-
transition matrices in Markov models, or compositional data analysis.
709-
They can also be used in situations where multiple Dirichlet-distributed v
710-
ariables are required across different dimensions.
705+
Column-stochastic matrices are often used in models where
706+
each column represents a probability distribution across a
707+
set of categories such as in multiple multinomial distributions,
708+
factor models, transition matrices in Markov models,
709+
or compositional data analysis.
710+
They can also be used in situations where you need multiple simplexes
711+
of the same dimensionality.
711712

712-
The `column_stochastic_matrix` and `row_stochastic_matrix` types are declared
713-
with full dimensionality. For instance, a matrix `theta` with
714-
3 rows and 4 columns, where each
715-
column is a 3-simplex, is declared as:
713+
The `column_stochastic_matrix` and `row_stochastic_matrix` types are declared
714+
with row and column sizes. For instance, a matrix `theta` with
715+
3 rows and 4 columns, where each
716+
column is a 3-simplex, is declared like a matrix with 3 rows and 4 columns.
716717

717718
```stan
718719
column_stochastic_matrix[3, 4] theta;
719720
```
720721

721-
A matrix `theta` with
722-
3 rows and 4 columns, where each
723-
row is a 4-simplex, is declared as:
722+
A matrix `theta` with 3 rows and 4 columns, where each row is a 4-simplex,
723+
is similarly declared as a matrix with 3 rows and 4 columns.
724724

725725
```stan
726726
row_stochastic_matrix[3, 4] theta;
727727
```
728728

729-
As with simplexes, `column(row)_stochastic_matrix` variables are subject to
730-
validation, ensuring that each column(row) satisfies the simplex constraints.
731-
This validation accounts for floating-point imprecision, with checks
732-
performed up to a statically specified accuracy threshold \(\epsilon\).
729+
As with simplexes, `column_stochastic_matrix` and `row_stochastic_matrix`
730+
variables are subject to validation, ensuring that each column (row)
731+
satisfies the simplex constraints. This validation accounts for
732+
floating-point imprecision, with checks performed up to a statically
733+
specified accuracy threshold \(\epsilon\).
733734

734735
#### Stability Considerations {-}
735736

736-
In high-dimensional settings or when the matrix has many columns,
737-
`column_stochastic_matrix` types may require careful tuning of the inference
737+
In high-dimensional settings, `column_stochastic_matrix` and `row_stochastic_matrix`
738+
types may require careful tuning of the inference
738739
algorithms. To ensure stability:
739740

740-
- **Smaller Step Sizes:** In samplers like Hamiltonian Monte Carlo (HMC),
741+
- **Smaller Step Sizes:** In samplers like Hamiltonian Monte Carlo (HMC),
741742
smaller step sizes can help maintain stability, especially in high dimensions.
742-
- **Higher Target Acceptance Rates:** Setting higher target acceptance
743+
- **Higher Target Acceptance Rates:** Setting higher target acceptance
743744
rates can improve the robustness of the sampling process.
744-
- **Longer Warmup Periods:** Increasing the warmup period allows the sampler
745+
- **Longer Warmup Periods:** Increasing the warmup period allows the sampler
745746
to better explore the parameter space before the actual sampling begins.
746-
- **Tighter Optimization Tolerances:** For optimization-based inference,
747+
- **Tighter Optimization Tolerances:** For optimization-based inference,
747748
tighter tolerances with more iterations can yield more accurate results.
748-
- **Custom Initialization:** If prior information about the parameters is
749-
available, custom initialization or less dispersed initialization can lead
749+
- **Custom Initialization:** If prior information about the parameters is
750+
available, custom initialization or less dispersed initialization can lead
750751
to more efficient inference.
751752

752753
### Unit vectors {-}

0 commit comments

Comments
 (0)