Skip to content

Commit 8370bdb

Browse files
committed
cleanup initial row/col stochastic matrix docs
1 parent a67ed63 commit 8370bdb

File tree

2 files changed

+25
-64
lines changed

2 files changed

+25
-64
lines changed

src/reference-manual/transforms.qmd

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -672,14 +672,14 @@ z_k
672672
.
673673
$$
674674

675-
## Column Stochastic Matrix {#column-stochastic-matrix-transform.section}
675+
## Stochastic Matrix {#stochastic-matrix-transform.section}
676676

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

682-
### Definition of a Column Stochastic Matrix {-}
682+
### Definition of a Stochastic Matrix {-}
683683

684684
A column stochastic matrix \(X \in \mathbb{R}^{N \times M}\) is defined such
685685
that for each column \(j\) (where \(1 \leq j \leq M\)):
@@ -694,43 +694,28 @@ $$
694694
\sum_{i=1}^N X_{ij} = 1.
695695
$$
696696

697-
This definition ensures that each column of the matrix \(X\) lies on the
698-
\(N-1\) dimensional unit simplex, similar to the `simplex[N]` type, but
699-
extended across multiple columns.
700-
701-
### Inverse Transform for Column Stochastic Matrix {-}
702-
703-
The inverse transform for the `column_stochastic_matrix` type is an extension
704-
of the unit simplex inverse transform to multiple columns. The process can be
705-
understood by applying the stick-breaking metaphor independently to each column.
697+
A row stochastic matrix is defined similarly but with the axis flipped such
698+
that
706699

707-
For each column \(j\) of the matrix \(X\), an unconstrained vector \(y_j \in
708-
\mathbb{R}^{N-1}\) is mapped to the column \(X_{\cdot j}\) on the unit simplex
709-
using the following steps:
710-
711-
1. Begin with a stick of unit length.
712-
2. Break off a piece corresponding to each element \(X_{ij}\) of the column
713-
vector, where the size of each piece is determined by an intermediate value
714-
\(z_{ij}\), which is itself derived from the unconstrained
715-
parameter \(y_{ij}\).
716-
3. The intermediate vector \(z_j \in \mathbb{R}^{N-1}\) is
717-
defined elementwise for each \(j\) and for \(1 \leq i < N\) by
718700

719701
$$
720-
z_{ij} = \mathrm{logit}^{-1}\left( y_{ij} + \log\left(\frac{1}{N - i}\right) \right).
702+
X_{ij} \geq 0 \quad \text{for } 1 \leq j \leq N,
721703
$$
722704

723-
4. The stick sizes \(X_{ij}\) for \(1 \leq i < N\) are then calculated recursively by
705+
and
724706

725707
$$
726-
X_{ij} = \left( 1 - \sum_{i'=1}^{i-1} X_{i'j} \right) z_{ij}.
708+
\sum_{j=1}^N X_{ij} = 1.
727709
$$
728710

729-
5. The last element of each column \(X_{Nj}\) is set to the length of the remaining piece of the stick:
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
713+
extended across multiple columns(rows).
730714

731-
$$
732-
X_{Nj} = 1 - \sum_{i=1}^{N-1} X_{ij}.
733-
$$
715+
### Inverse Transform for Stochastic Matrix {-}
716+
717+
For the column and row stochastic matrices the inverse transform is the same
718+
as simplex, but applied to each column(row).
734719

735720
### Absolute Jacobian Determinant for the Inverse Transform {-}
736721

@@ -742,37 +727,17 @@ $$
742727
\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).
743728
$$
744729

745-
Thus, the overall Jacobian determinant for the entire `column_stochastic_matrix`
746-
is the product of the determinants for each column:
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):
747732

748733
$$
749734
\left| \det J \right| = \prod_{j=1}^{M} \left| \det J_j \right|.
750735
$$
751736

752-
### Transform for Column Stochastic Matrix {-}
753-
754-
To transform from a column stochastic matrix \(X\) back to the unconstrained space \(y_j\)
755-
for each column \(j\):
756-
757-
1. The break proportions \(z_{ij}\) are first determined by
758-
759-
$$
760-
z_{ij} = \frac{X_{ij}}{1 - \sum_{i'=1}^{i-1} X_{i'j}}.
761-
$$
762-
763-
2. The corresponding unconstrained parameters \(y_{ij}\) are then computed as
764-
765-
$$
766-
y_{ij} = \mathrm{logit}(z_{ij}) - \log\left(\frac{1}{N - i}\right).
767-
$$
768-
769-
By applying this process to each column \(j\) independently, the entire column
770-
stochastic matrix \(X\) can be transformed to or from the unconstrained space.
771-
772-
This formulation allows the `column_stochastic_matrix[N, M]` type to be used
773-
effectively in models requiring columns of a matrix to be unit simplexes,
774-
such as in multi-category probability models or compositional data analysis.
737+
### Transform for Stochastic Matrix {-}
775738

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

777742
## Unit vector {#unit-vector.section}
778743

src/reference-manual/types.qmd

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,8 @@ row is a 4-simplex, is declared as:
726726
row_stochastic_matrix[3, 4] theta;
727727
```
728728

729-
The `column_stochastic_matrix` type is implemented as a matrix where each
730-
column is individually constrained to be a simplex. This means that each
731-
column must be a valid simplex with non-negative elements that sum to 1.
732-
733-
As with simplexes, `column_stochastic_matrix` variables are subject to
734-
validation, ensuring that each column satisfies the simplex constraints.
729+
As with simplexes, `column(row)_stochastic_matrix` variables are subject to
730+
validation, ensuring that each column(row) satisfies the simplex constraints.
735731
This validation accounts for floating-point imprecision, with checks
736732
performed up to a statically specified accuracy threshold \(\epsilon\).
737733

0 commit comments

Comments
 (0)