Skip to content

Commit d819287

Browse files
committed
update naming to be row and column stochastic matrices
1 parent dbe4416 commit d819287

12 files changed

+96
-115
lines changed

stan/math/prim/fun.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,8 @@
315315
#include <stan/math/prim/fun/select.hpp>
316316
#include <stan/math/prim/fun/sign.hpp>
317317
#include <stan/math/prim/fun/signbit.hpp>
318-
#include <stan/math/prim/fun/simplex_column_constrain.hpp>
319-
#include <stan/math/prim/fun/simplex_column_free.hpp>
320318
#include <stan/math/prim/fun/simplex_constrain.hpp>
321319
#include <stan/math/prim/fun/simplex_free.hpp>
322-
#include <stan/math/prim/fun/simplex_row_constrain.hpp>
323-
#include <stan/math/prim/fun/simplex_row_free.hpp>
324320
#include <stan/math/prim/fun/sin.hpp>
325321
#include <stan/math/prim/fun/singular_values.hpp>
326322
#include <stan/math/prim/fun/sinh.hpp>
@@ -338,6 +334,10 @@
338334
#include <stan/math/prim/fun/squared_distance.hpp>
339335
#include <stan/math/prim/fun/stan_print.hpp>
340336
#include <stan/math/prim/fun/step.hpp>
337+
#include <stan/math/prim/fun/stochastic_column_constrain.hpp>
338+
#include <stan/math/prim/fun/stochastic_column_free.hpp>
339+
#include <stan/math/prim/fun/stochastic_row_constrain.hpp>
340+
#include <stan/math/prim/fun/stochastic_row_free.hpp>
341341
#include <stan/math/prim/fun/sub_col.hpp>
342342
#include <stan/math/prim/fun/sub_row.hpp>
343343
#include <stan/math/prim/fun/subtract.hpp>

stan/math/prim/fun/simplex_column_constrain.hpp renamed to stan/math/prim/fun/stochastic_column_constrain.hpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ namespace stan {
1414
namespace math {
1515

1616
/**
17-
* Return a matrix with columns as simplex vectors.
18-
* A simplex is a vector containing values greater than or equal
19-
* to 0 that sum to 1. A vector with (K-1) unconstrained values
20-
* will produce a simplex of size K.
17+
* Return a column stochastic matrix.
2118
*
2219
* The transform is based on a centered stick-breaking process.
2320
*
@@ -27,8 +24,7 @@ namespace math {
2724
*/
2825
template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
2926
require_not_st_var<Mat>* = nullptr>
30-
inline plain_type_t<Mat> simplex_column_constrain(const Mat& y) {
31-
// cut & paste simplex_column_constrain(Eigen::Matrix, T) w/o Jacobian
27+
inline plain_type_t<Mat> stochastic_column_constrain(const Mat& y) {
3228
auto&& y_ref = to_ref(y);
3329
const Eigen::Index M = y_ref.cols();
3430
plain_type_t<Mat> ret(y_ref.rows() + 1, M);
@@ -39,7 +35,7 @@ inline plain_type_t<Mat> simplex_column_constrain(const Mat& y) {
3935
}
4036

4137
/**
42-
* Return a matrix with columns as simplex vectors
38+
* Return a column stochastic matrix
4339
* and increment the specified log probability reference with
4440
* the log absolute Jacobian determinant of the transform.
4541
*
@@ -49,11 +45,11 @@ inline plain_type_t<Mat> simplex_column_constrain(const Mat& y) {
4945
* @tparam Mat type of the Matrix
5046
* @param y Free Matrix input of dimensionality (K - 1, M)
5147
* @param lp Log probability reference to increment.
52-
* @return Matrix with simplex columns of dimensionality (K, M)
48+
* @return Matrix with stochastic columns of dimensionality (K, M)
5349
*/
5450
template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
5551
require_not_st_var<Mat>* = nullptr>
56-
inline plain_type_t<Mat> simplex_column_constrain(const Mat& y,
52+
inline plain_type_t<Mat> stochastic_column_constrain(const Mat& y,
5753
value_type_t<Mat>& lp) {
5854
auto&& y_ref = to_ref(y);
5955
const Eigen::Index M = y_ref.cols();
@@ -65,7 +61,7 @@ inline plain_type_t<Mat> simplex_column_constrain(const Mat& y,
6561
}
6662

6763
/**
68-
* Return a matrix with columns as simplex vectors. If the
64+
* Return a column stochastic matrix. If the
6965
* `Jacobian` parameter is `true`, the log density accumulator is incremented
7066
* with the log absolute Jacobian determinant of the transform. All of the
7167
* transforms are specified with their Jacobians in the *Stan Reference Manual*
@@ -79,17 +75,17 @@ inline plain_type_t<Mat> simplex_column_constrain(const Mat& y,
7975
* @return Matrix with simplex columns of dimensionality (K, M).
8076
*/
8177
template <bool Jacobian, typename Mat, require_not_std_vector_t<Mat>* = nullptr>
82-
inline plain_type_t<Mat> simplex_column_constrain(const Mat& y,
78+
inline plain_type_t<Mat> stochastic_column_constrain(const Mat& y,
8379
return_type_t<Mat>& lp) {
8480
if (Jacobian) {
85-
return simplex_column_constrain(y, lp);
81+
return stochastic_column_constrain(y, lp);
8682
} else {
87-
return simplex_column_constrain(y);
83+
return stochastic_column_constrain(y);
8884
}
8985
}
9086

9187
/**
92-
* Return a standard vector of matrices with columns as simplex vectors. If the
88+
* Return a vector of column stochastic matrices. If the
9389
* `Jacobian` parameter is `true`, the log density accumulator is incremented
9490
* with the log absolute Jacobian determinant of the transform. All of the
9591
* transforms are specified with their Jacobians in the *Stan Reference Manual*
@@ -106,9 +102,9 @@ inline plain_type_t<Mat> simplex_column_constrain(const Mat& y,
106102
* dimensionality (K, M).
107103
*/
108104
template <bool Jacobian, typename T, require_std_vector_t<T>* = nullptr>
109-
inline auto simplex_column_constrain(const T& y, return_type_t<T>& lp) {
105+
inline auto stochastic_column_constrain(const T& y, return_type_t<T>& lp) {
110106
return apply_vector_unary<T>::apply(
111-
y, [&lp](auto&& v) { return simplex_column_constrain<Jacobian>(v, lp); });
107+
y, [&lp](auto&& v) { return stochastic_column_constrain<Jacobian>(v, lp); });
112108
}
113109

114110
} // namespace math

stan/math/prim/fun/simplex_column_free.hpp renamed to stan/math/prim/fun/stochastic_column_free.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_PRIM_FUN_SIMPLEX_COLUMN_FREE_HPP
2-
#define STAN_MATH_PRIM_FUN_SIMPLEX_COLUMN_FREE_HPP
1+
#ifndef STAN_MATH_PRIM_FUN_STOCHASTIC_COLUMN_FREE_HPP
2+
#define STAN_MATH_PRIM_FUN_STOCHASTIC_COLUMN_FREE_HPP
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
@@ -10,16 +10,16 @@ namespace math {
1010

1111
/**
1212
* Return an unconstrained matrix that when transformed produces
13-
* the specified columnwise simplex matrix. It applies to a simplex of
13+
* the specified columnwise stochastic matrix. It applies to a stochastic matrix of
1414
* dimensionality (N, K) and produces an unconstrained vector of dimensionality
1515
* (N - 1, K).
1616
*
1717
* @tparam Mat type of the Matrix
18-
* @param y Columnwise simplex matrix input of dimensionality (N, K)
18+
* @param y Columnwise stochastic matrix input of dimensionality (N, K)
1919
*/
2020
template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
2121
require_not_st_var<Mat>* = nullptr>
22-
inline plain_type_t<Mat> simplex_column_free(const Mat& y) {
22+
inline plain_type_t<Mat> stochastic_column_free(const Mat& y) {
2323
auto&& y_ref = to_ref(y);
2424
const Eigen::Index M = y_ref.cols();
2525
plain_type_t<Mat> ret(y_ref.rows() - 1, M);
@@ -34,12 +34,12 @@ inline plain_type_t<Mat> simplex_column_free(const Mat& y) {
3434
*
3535
* @tparam T A standard vector with inner type inheriting from
3636
* `Eigen::DenseBase` with compile time dynamic rows and dynamic rows
37-
* @param[in] y vector of columnwise simplex matrix of size (N, K)
37+
* @param[in] y vector of columnwise stochastic matrix of size (N, K)
3838
*/
3939
template <typename T, require_std_vector_t<T>* = nullptr>
40-
inline auto simplex_column_free(const T& y) {
40+
inline auto stochastic_column_free(const T& y) {
4141
return apply_vector_unary<T>::apply(
42-
y, [](auto&& v) { return simplex_column_free(v); });
42+
y, [](auto&& v) { return stochastic_column_free(v); });
4343
}
4444

4545
} // namespace math

stan/math/prim/fun/simplex_row_constrain.hpp renamed to stan/math/prim/fun/stochastic_row_constrain.hpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_PRIM_FUN_SIMPLEX_ROW_CONSTRAIN_HPP
2-
#define STAN_MATH_PRIM_FUN_SIMPLEX_ROW_CONSTRAIN_HPP
1+
#ifndef STAN_MATH_PRIM_FUN_STOCHASTIC_ROW_CONSTRAIN_HPP
2+
#define STAN_MATH_PRIM_FUN_STOCHASTIC_ROW_CONSTRAIN_HPP
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
@@ -14,10 +14,7 @@ namespace stan {
1414
namespace math {
1515

1616
/**
17-
* Return the simplex corresponding to the specified free vector.
18-
* A simplex is a vector containing values greater than or equal
19-
* to 0 that sum to 1. A vector with (K-1) unconstrained values
20-
* will produce a simplex of size K.
17+
* Return a row stochastic matrix.
2118
*
2219
* The transform is based on a centered stick-breaking process.
2320
*
@@ -27,7 +24,7 @@ namespace math {
2724
*/
2825
template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
2926
require_not_st_var<Mat>* = nullptr>
30-
inline plain_type_t<Mat> simplex_row_constrain(const Mat& y) {
27+
inline plain_type_t<Mat> stochastic_row_constrain(const Mat& y) {
3128
auto&& y_ref = to_ref(y);
3229
const Eigen::Index N = y_ref.rows();
3330
int Km1 = y_ref.cols();
@@ -44,10 +41,7 @@ inline plain_type_t<Mat> simplex_row_constrain(const Mat& y) {
4441
}
4542

4643
/**
47-
* Return a matrix with simplex rows corresponding to the specified free matrix
48-
* and increment the specified log probability reference with
49-
* the log absolute Jacobian determinant of the transform.
50-
*
44+
* Return a row stochastic matrix.
5145
* The simplex transform is defined through a centered
5246
* stick-breaking process.
5347
*
@@ -58,7 +52,7 @@ inline plain_type_t<Mat> simplex_row_constrain(const Mat& y) {
5852
*/
5953
template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
6054
require_not_st_var<Mat>* = nullptr>
61-
inline plain_type_t<Mat> simplex_row_constrain(const Mat& y,
55+
inline plain_type_t<Mat> stochastic_row_constrain(const Mat& y,
6256
value_type_t<Mat>& lp) {
6357
auto&& y_ref = to_ref(y);
6458
const Eigen::Index N = y_ref.rows();
@@ -80,7 +74,7 @@ inline plain_type_t<Mat> simplex_row_constrain(const Mat& y,
8074
}
8175

8276
/**
83-
* Return a matrix with simplex rows corresponding to the specified free matrix.
77+
* Return a row stochastic matrix.
8478
* If the `Jacobian` parameter is `true`, the log density accumulator is
8579
* incremented with the log absolute Jacobian determinant of the transform. All
8680
* of the transforms are specified with their Jacobians in the *Stan Reference
@@ -96,18 +90,18 @@ inline plain_type_t<Mat> simplex_row_constrain(const Mat& y,
9690
* @return Matrix with simplexes along the rows of dimensionality (N, K).
9791
*/
9892
template <bool Jacobian, typename Mat, require_not_std_vector_t<Mat>* = nullptr>
99-
inline plain_type_t<Mat> simplex_row_constrain(const Mat& y,
93+
inline plain_type_t<Mat> stochastic_row_constrain(const Mat& y,
10094
return_type_t<Mat>& lp) {
10195
if (Jacobian) {
102-
return simplex_row_constrain(y, lp);
96+
return stochastic_row_constrain(y, lp);
10397
} else {
104-
return simplex_row_constrain(y);
98+
return stochastic_row_constrain(y);
10599
}
106100
}
107101

108102
/**
109-
* Return the simplex corresponding to the specified free vector. If the
110-
* `Jacobian` parameter is `true`, the log density accumulator is incremented
103+
* Return a row stochastic matrix.
104+
* If the `Jacobian` parameter is `true`, the log density accumulator is incremented
111105
* with the log absolute Jacobian determinant of the transform. All of the
112106
* transforms are specified with their Jacobians in the *Stan Reference Manual*
113107
* chapter Constraint Transforms.
@@ -122,9 +116,9 @@ inline plain_type_t<Mat> simplex_row_constrain(const Mat& y,
122116
* @return vector of matrices with simplex rows of dimensionality (N, K)
123117
*/
124118
template <bool Jacobian, typename T, require_std_vector_t<T>* = nullptr>
125-
inline auto simplex_row_constrain(const T& y, return_type_t<T>& lp) {
119+
inline auto stochastic_row_constrain(const T& y, return_type_t<T>& lp) {
126120
return apply_vector_unary<T>::apply(
127-
y, [&lp](auto&& v) { return simplex_row_constrain<Jacobian>(v, lp); });
121+
y, [&lp](auto&& v) { return stochastic_row_constrain<Jacobian>(v, lp); });
128122
}
129123

130124
} // namespace math

stan/math/prim/fun/simplex_row_free.hpp renamed to stan/math/prim/fun/stochastic_row_free.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_PRIM_FUN_SIMPLEX_ROW_FREE_HPP
2-
#define STAN_MATH_PRIM_FUN_SIMPLEX_ROW_FREE_HPP
1+
#ifndef STAN_MATH_PRIM_FUN_STOCHASTIC_ROW_FREE_HPP
2+
#define STAN_MATH_PRIM_FUN_STOCHASTIC_ROW_FREE_HPP
33

44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/fun/Eigen.hpp>
@@ -18,7 +18,7 @@ namespace math {
1818
*/
1919
template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
2020
require_not_st_var<Mat>* = nullptr>
21-
inline plain_type_t<Mat> simplex_row_free(const Mat& y) {
21+
inline plain_type_t<Mat> stochastic_row_free(const Mat& y) {
2222
auto&& y_ref = to_ref(y);
2323
const Eigen::Index N = y_ref.rows();
2424
plain_type_t<Mat> ret(N, y_ref.cols() - 1);
@@ -36,9 +36,9 @@ inline plain_type_t<Mat> simplex_row_free(const Mat& y) {
3636
* @param[in] y vector of rowwise simplex matrices each of size (N, K)
3737
*/
3838
template <typename T, require_std_vector_t<T>* = nullptr>
39-
inline auto simplex_row_free(const T& y) {
39+
inline auto stochastic_row_free(const T& y) {
4040
return apply_vector_unary<T>::apply(
41-
y, [](auto&& v) { return simplex_row_free(v); });
41+
y, [](auto&& v) { return stochastic_row_free(v); });
4242
}
4343

4444
} // namespace math

stan/math/rev/fun.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@
160160
#include <stan/math/rev/fun/rows_dot_product.hpp>
161161
#include <stan/math/rev/fun/rows_dot_self.hpp>
162162
#include <stan/math/rev/fun/sd.hpp>
163-
#include <stan/math/rev/fun/simplex_column_constrain.hpp>
164163
#include <stan/math/rev/fun/simplex_constrain.hpp>
165-
#include <stan/math/rev/fun/simplex_row_constrain.hpp>
166164
#include <stan/math/rev/fun/sin.hpp>
167165
#include <stan/math/rev/fun/singular_values.hpp>
166+
#include <stan/math/rev/fun/stochastic_column_constrain.hpp>
167+
#include <stan/math/rev/fun/stochastic_row_constrain.hpp>
168168
#include <stan/math/rev/fun/svd.hpp>
169169
#include <stan/math/rev/fun/svd_U.hpp>
170170
#include <stan/math/rev/fun/svd_V.hpp>

stan/math/rev/fun/simplex_column_constrain.hpp renamed to stan/math/rev/fun/stochastic_column_constrain.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_REV_FUN_SIMPLEX_COLUMN_CONSTRAIN_HPP
2-
#define STAN_MATH_REV_FUN_SIMPLEX_COLUMN_CONSTRAIN_HPP
1+
#ifndef STAN_MATH_REV_FUN_STOCHASTIC_COLUMN_CONSTRAIN_HPP
2+
#define STAN_MATH_REV_FUN_STOCHASTIC_COLUMN_CONSTRAIN_HPP
33

44
#include <stan/math/rev/meta.hpp>
55
#include <stan/math/rev/core/reverse_pass_callback.hpp>
@@ -16,19 +16,15 @@ namespace stan {
1616
namespace math {
1717

1818
/**
19-
* Return a matrix with columns as simplex vectors.
20-
* A simplex is a vector containing values greater than or equal
21-
* to 0 that sum to 1. A matrix (K-1, M) unconstrained values
22-
* will produce a matrix of simplex vectors of size (K, M).
23-
*
19+
* Return a column stochastic matrix.
2420
* The transform is based on a centered stick-breaking process.
2521
*
2622
* @tparam T Type of matrix to constrain
2723
* @param y Free matrix input of dimensionality (K - 1, M)
2824
* @return matrix of column simplexes of dimensionality (K, M)
2925
*/
3026
template <typename T, require_rev_matrix_t<T>* = nullptr>
31-
inline plain_type_t<T> simplex_column_constrain(const T& y) {
27+
inline plain_type_t<T> stochastic_column_constrain(const T& y) {
3228
using ret_type = plain_type_t<T>;
3329
const Eigen::Index N = y.rows();
3430
const Eigen::Index M = y.cols();
@@ -71,7 +67,7 @@ inline plain_type_t<T> simplex_column_constrain(const T& y) {
7167
}
7268

7369
/**
74-
* Return a matrix with columns as simplex vectors
70+
* Return a column stochastic matrix
7571
* and increment the specified log probability reference with
7672
* the log absolute Jacobian determinant of the transform.
7773
*
@@ -81,10 +77,10 @@ inline plain_type_t<T> simplex_column_constrain(const T& y) {
8177
* @tparam T type of the matrix to constrain
8278
* @param y Free matrix input of dimensionality N, K.
8379
* @param lp Log probability reference to increment.
84-
* @return Matrix of simplex columns of dimensionality (N + 1, K).
80+
* @return Matrix of stochastic columns of dimensionality (N + 1, K).
8581
*/
8682
template <typename T, require_rev_matrix_t<T>* = nullptr>
87-
inline plain_type_t<T> simplex_column_constrain(const T& y,
83+
inline plain_type_t<T> stochastic_column_constrain(const T& y,
8884
scalar_type_t<T>& lp) {
8985
using ret_type = plain_type_t<T>;
9086
const Eigen::Index N = y.rows();

stan/math/rev/fun/simplex_row_constrain.hpp renamed to stan/math/rev/fun/stochastic_row_constrain.hpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef STAN_MATH_REV_FUN_SIMPLEX_ROW_CONSTRAIN_HPP
2-
#define STAN_MATH_REV_FUN_SIMPLEX_ROW_CONSTRAIN_HPP
1+
#ifndef STAN_MATH_REV_FUN_STOCHASTIC_ROW_CONSTRAIN_HPP
2+
#define STAN_MATH_REV_FUN_STOCHASTIC_ROW_CONSTRAIN_HPP
33

44
#include <stan/math/rev/meta.hpp>
55
#include <stan/math/rev/core/reverse_pass_callback.hpp>
@@ -16,19 +16,14 @@ namespace stan {
1616
namespace math {
1717

1818
/**
19-
* Return a matrix of simplex columns corresponding to the specified free
20-
* matrix. A simplex is a vector containing values greater than or equal to 0
21-
* that sum to 1. A matrix with (N, K - 1) unconstrained values will produce a
22-
* matrix with simplexes on the rows of size (N, K).
23-
*
24-
* The transform is based on a centered stick-breaking process.
19+
* Return a row stochastic matrix.
2520
*
2621
* @tparam T Type of matrix to constrain
2722
* @param y Free vector input of dimensionality (N, K - 1)
2823
* @return Matrix with Simplexes along the rows of dimensionality (N, K)
2924
*/
3025
template <typename T, require_rev_matrix_t<T>* = nullptr>
31-
inline plain_type_t<T> simplex_row_constrain(const T& y) {
26+
inline plain_type_t<T> stochastic_row_constrain(const T& y) {
3227
using ret_type = plain_type_t<T>;
3328
const Eigen::Index N = y.rows();
3429
const Eigen::Index M = y.cols();
@@ -68,7 +63,7 @@ inline plain_type_t<T> simplex_row_constrain(const T& y) {
6863
}
6964

7065
/**
71-
* Return a matrix of simplex columns corresponding to the specified free matrix
66+
* Return a row stochastic matrix
7267
* and increment the specified log probability reference with
7368
* the log absolute Jacobian determinant of the transform.
7469
*
@@ -81,7 +76,7 @@ inline plain_type_t<T> simplex_row_constrain(const T& y) {
8176
* @return Matrix with simplexes along the rows of dimensionality (N, K + 1).
8277
*/
8378
template <typename T, require_rev_matrix_t<T>* = nullptr>
84-
inline plain_type_t<T> simplex_row_constrain(const T& y, scalar_type_t<T>& lp) {
79+
inline plain_type_t<T> stochastic_row_constrain(const T& y, scalar_type_t<T>& lp) {
8580
using ret_type = plain_type_t<T>;
8681
const Eigen::Index N = y.rows();
8782
const Eigen::Index M = y.cols();

0 commit comments

Comments
 (0)