@@ -672,14 +672,14 @@ z_k
672
672
.
673
673
$$
674
674
675
- ## Column Stochastic Matrix {#column- stochastic-matrix-transform.section}
675
+ ## Stochastic Matrix {#stochastic-matrix-transform.section}
676
676
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.
681
681
682
- ### Definition of a Column Stochastic Matrix {-}
682
+ ### Definition of a Stochastic Matrix {-}
683
683
684
684
A column stochastic matrix \( X \in \mathbb{R}^{N \times M}\) is defined such
685
685
that for each column \( j\) (where \( 1 \leq j \leq M\) ):
694
694
\sum_{i=1}^N X_{ij} = 1.
695
695
$$
696
696
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
706
699
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
718
700
719
701
$$
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,
721
703
$$
722
704
723
- 4 . The stick sizes \( X _ {ij} \) for \( 1 \leq i < N \) are then calculated recursively by
705
+ and
724
706
725
707
$$
726
- X_{ij} = \left( 1 - \ sum_{i' =1}^{i-1} X_{i'j} \right) z_{ij} .
708
+ \ sum_{j =1}^N X_{ij} = 1 .
727
709
$$
728
710
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).
730
714
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).
734
719
735
720
### Absolute Jacobian Determinant for the Inverse Transform {-}
736
721
742
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).
743
728
$$
744
729
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) :
747
732
748
733
$$
749
734
\left| \det J \right| = \prod_{j=1}^{M} \left| \det J_j \right|.
750
735
$$
751
736
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 {-}
775
738
739
+ For the column and row stochastic matrices the transform is the same
740
+ as simplex, but applied to each column(row).
776
741
777
742
## Unit vector {#unit-vector.section}
778
743
0 commit comments