Skip to content
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

row/col stochastic matrix documentation #807

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

SteveBronder
Copy link
Contributor

Adds docs for row and column stochastic matrix types.

I tried not to repeat myself too much by doing something similar to what Eigen does for csr matrices and csc matrices. I mostly explained the column_stochastic_matrix type and noted the differences for row_stochastic_matrix when necessary. Is that alright?

Submission Checklist

  • Builds locally
  • New functions marked with <<{ since VERSION }>>
    • Is there an example of this in the docs somewhere?
  • Declare copyright holder and open-source license: see below

Summary

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Simons Foundation

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@SteveBronder SteveBronder changed the title start row/col stochastic matrix documentation row/col stochastic matrix documentation Aug 20, 2024
@WardBrian WardBrian linked an issue Aug 20, 2024 that may be closed by this pull request
Copy link
Contributor

@bob-carpenter bob-carpenter left a comment

Choose a reason for hiding this comment

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

Thanks for writing this up. I had a bajillion little detailed comments here---sorry about that in advance.

\sum_{i=1}^N X_{ij} = 1.
$$

A row stochastic matrix is defined similarly but with the axis flipped such
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as easy to say a row stochastic matrix is any matrix whose transpose is a column stochastic matrix.

I would also say in words that a column stochastic matrix has columns that are simplexes, whereas the row version has rows that are simplexes.

I've tried to write matrix subscripts as "i, j" rather than "ij" to allow for multiple-character subscripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, can't believe I forgot to just say what this is in simple terms

@@ -672,6 +672,72 @@ z_k
.
$$

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

The `column_stochastic_matrix[N, M]` and `row_stochastic_matrix[N, M]` type in
Copy link
Contributor

Choose a reason for hiding this comment

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

We've used "col" everywhere else for column. Should this match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed irl, we are wishy washy with col vs column abbreviation, but I like column here so going to keep it

\sum_{j=1}^N X_{ij} = 1.
$$

This definition ensures that each column(row) of the matrix \(X\) lies on the
Copy link
Contributor

Choose a reason for hiding this comment

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

space between column and ( --- this also appears later

Just stick to $X$ to match the rest of our doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I had a reason for why I did that (eigen docs did column(row)), but it looks like they fixed it in their docs so I'll fix it here as well

A stochastic matrix is a matrix where each column, row, or both is a
unit simplex, meaning that each column(row) vector has non-negative
values that sum to 1. For example, a \(3 \times 4\)
column stochastic matrix will look like:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say:

"The following example is a $3 \times 4$ column-stochastic matrix."

Note that it's a period at the end this way and doesn't assert that a column stochastic matrix will look one way or another. Also note that when you use a noun compound like "column stochastic" as an adjective (here modifying "matrix") then it should be hyphenated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also fixed Column-matrix below

\end{bmatrix}
$$

While a row stochastic matrix will look like:
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a complete sentence---it's just a free-floating clause. How about:

"An example of a row-stochastic matrix is the following."

each column represents a probability distribution across a
set of categories, such as in multiple multinomial distributions,
transition matrices in Markov models, or compositional data analysis.
They can also be used in situations where multiple Dirichlet-distributed v
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd drop the Dirichlet comment here. You can just say they can be used whenever you need multiple simplexes of the same dimensionality.

The other big application here is factor models, so you should definitely mention those. The rows in the row stochastic matrix in these models is, for exmaple, is something like the proportion of pollutants being emitted from a factory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added factor model to the examples

ariables are required across different dimensions.

The `column_stochastic_matrix` and `row_stochastic_matrix` types are declared
with full dimensionality. For instance, a matrix `theta` with
Copy link
Contributor

Choose a reason for hiding this comment

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

full dimensionality ---> row and column sizes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

column_stochastic_matrix[3, 4] theta;
```

A matrix `theta` with
Copy link
Contributor

Choose a reason for hiding this comment

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

Too many line breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

row_stochastic_matrix[3, 4] theta;
```

As with simplexes, `column(row)_stochastic_matrix` variables are subject to
Copy link
Contributor

Choose a reason for hiding this comment

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

This is too hard to parse---just repeat, we have tons of space here. That is, separate out column_stochastic_matrix and row_stochastic_matrix.


#### Stability Considerations {-}

In high-dimensional settings or when the matrix has many columns,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear how "high-dimensional" and "has many columns" differ. Is high-dimensional the rows? I'd just say "high-dimensional" here.

Copy link
Contributor

@bob-carpenter bob-carpenter left a comment

Choose a reason for hiding this comment

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

Just a couple cosmetic changes and this is good to go.

the lower-triangular Jacobian matrix. This determinant is calculated as:

$$
\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).
Copy link
Contributor

Choose a reason for hiding this comment

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

J_j is unfortunate notation. We've tried to maintain a convention of using n in 1:N for indexing with lower case matching the name of the upper case bounds. So I'd take this to be J_m for m in 1:M. And similarly, convert the earlier thing to using n.

I've also tried to use commas between indexes everywhere---you're doing this in some places (like z) but not others (like X). Please make this consistently use commas.

### Stochastic Matrices {-}

A stochastic matrix is a matrix where each column, row, or both is a
unit simplex, meaning that each column (row) vector has non-negative
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the "both" description here as we're not providing that functionality for users (at least not yet!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document stochastic matrix transforms
2 participants