-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
SteveBronder
wants to merge
3
commits into
master
Choose a base branch
from
feature/row-stochastic-matrix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -673,6 +673,83 @@ iterations, and in either case, with less dispersed parameter | |
initialization or custom initialization if there are informative | ||
priors for some parameters. | ||
|
||
### 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!). |
||
values that sum to 1. The following example is a \(3 \times 4\) | ||
column-stochastic matrix. | ||
|
||
$$ | ||
\begin{bmatrix} | ||
0.2 & 0.5 & 0.1 & 0.3 \\ | ||
0.3 & 0.3 & 0.6 & 0.4 \\ | ||
0.5 & 0.2 & 0.3 & 0.3 | ||
\end{bmatrix} | ||
$$ | ||
|
||
An example of a \(3 \times 4\) row-stochastic matrix is the following. | ||
|
||
$$ | ||
\begin{bmatrix} | ||
0.2 & 0.5 & 0.1 & 0.2 \\ | ||
0.2 & 0.1 & 0.6 & 0.1 \\ | ||
0.5 & 0.2 & 0.2 & 0.1 | ||
\end{bmatrix} | ||
$$ | ||
|
||
|
||
In the examples above, each column (or row) sums to 1, making the matrices | ||
valid `column_stochastic_matrix` and `row_stochastic_matrix` types. | ||
|
||
bob-carpenter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Column-stochastic matrices are often used in models where | ||
each column represents a probability distribution across a | ||
set of categories such as in multiple multinomial distributions, | ||
factor models, transition matrices in Markov models, | ||
or compositional data analysis. | ||
They can also be used in situations where you need multiple simplexes | ||
of the same dimensionality. | ||
|
||
The `column_stochastic_matrix` and `row_stochastic_matrix` types are declared | ||
with row and column sizes. For instance, a matrix `theta` with | ||
3 rows and 4 columns, where each | ||
column is a 3-simplex, is declared like a matrix with 3 rows and 4 columns. | ||
|
||
```stan | ||
column_stochastic_matrix[3, 4] theta; | ||
``` | ||
|
||
A matrix `theta` with 3 rows and 4 columns, where each row is a 4-simplex, | ||
is similarly declared as a matrix with 3 rows and 4 columns. | ||
|
||
```stan | ||
row_stochastic_matrix[3, 4] theta; | ||
``` | ||
|
||
As with simplexes, `column_stochastic_matrix` and `row_stochastic_matrix` | ||
variables are subject to validation, ensuring that each column (row) | ||
satisfies the simplex constraints. This validation accounts for | ||
floating-point imprecision, with checks performed up to a statically | ||
specified accuracy threshold \(\epsilon\). | ||
|
||
#### Stability Considerations {-} | ||
|
||
In high-dimensional settings, `column_stochastic_matrix` and `row_stochastic_matrix` | ||
types may require careful tuning of the inference | ||
algorithms. To ensure stability: | ||
|
||
- **Smaller Step Sizes:** In samplers like Hamiltonian Monte Carlo (HMC), | ||
smaller step sizes can help maintain stability, especially in high dimensions. | ||
- **Higher Target Acceptance Rates:** Setting higher target acceptance | ||
rates can improve the robustness of the sampling process. | ||
- **Longer Warmup Periods:** Increasing the warmup period allows the sampler | ||
to better explore the parameter space before the actual sampling begins. | ||
- **Tighter Optimization Tolerances:** For optimization-based inference, | ||
tighter tolerances with more iterations can yield more accurate results. | ||
- **Custom Initialization:** If prior information about the parameters is | ||
available, custom initialization or less dispersed initialization can lead | ||
to more efficient inference. | ||
|
||
### Unit vectors {-} | ||
|
||
A unit vector is a vector with a norm of one. For instance, $[0.5, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.