Skip to content

Commit 25460e9

Browse files
committed
Docstrings
1 parent 86fed93 commit 25460e9

2 files changed

Lines changed: 57 additions & 24 deletions

File tree

stan/math/prim/constraint/sum_to_zero_constrain.hpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ namespace math {
1414
* Return a vector with sum zero corresponding to the specified
1515
* free vector.
1616
*
17-
* The sum-to-zero transform is defined using the inverse of the
18-
* isometric log ratio transform (ILR)
17+
* The sum-to-zero transform is defined using a modified version of the
18+
* the inverse of the isometric log ratio transform (ILR).
19+
* See:
20+
* Egozcue, Juan Jose; Pawlowsky-Glahn, Vera; Mateu-Figueras, Gloria;
21+
* Barcelo-Vidal, Carles (2003), "Isometric logratio transformations for
22+
* compositional data analysis", Mathematical Geology, 35 (3): 279–300,
23+
* doi:10.1023/A:1023818214614, S2CID 122844634
24+
*
25+
* This is a linear transform, with no Jacobian.
1926
*
2027
* @tparam Vec type of the vector
2128
* @param y Free vector input of dimensionality K - 1.
@@ -26,7 +33,7 @@ template <typename Vec, require_eigen_col_vector_t<Vec>* = nullptr,
2633
inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y) {
2734
const auto N = y.size();
2835

29-
plain_type_t<Vec> z = Eigen::VectorXd::Zero(N+1);
36+
plain_type_t<Vec> z = Eigen::VectorXd::Zero(N + 1);
3037
if (unlikely(N == 0)) {
3138
return z;
3239
}
@@ -36,10 +43,10 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y) {
3643
typename plain_type_t<Vec>::Scalar sum_w(0);
3744
for (int i = N; i > 0; --i) {
3845
double n = i;
39-
auto w = y_ref(i-1) * inv_sqrt(n * (n + 1));
46+
auto w = y_ref(i - 1) * inv_sqrt(n * (n + 1));
4047
sum_w += w;
4148

42-
z.coeffRef(i-1) += sum_w;
49+
z.coeffRef(i - 1) += sum_w;
4350
z.coeffRef(i) -= w * n;
4451
}
4552

@@ -50,10 +57,15 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y) {
5057
* Return a vector with sum zero corresponding to the specified
5158
* free vector.
5259
*
53-
* The sum-to-zero transform is defined such that the first K-1
54-
* elements are unconstrained and the last element is the negative
55-
* sum of those elements. This is a linear transform, with no
56-
* Jacobian.
60+
* The sum-to-zero transform is defined using a modified version of the
61+
* the inverse of the isometric log ratio transform (ILR).
62+
* See:
63+
* Egozcue, Juan Jose; Pawlowsky-Glahn, Vera; Mateu-Figueras, Gloria;
64+
* Barcelo-Vidal, Carles (2003), "Isometric logratio transformations for
65+
* compositional data analysis", Mathematical Geology, 35 (3): 279–300,
66+
* doi:10.1023/A:1023818214614, S2CID 122844634
67+
*
68+
* This is a linear transform, with no Jacobian.
5769
*
5870
* @tparam Vec type of the vector
5971
* @param y Free vector input of dimensionality K - 1.
@@ -71,10 +83,15 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y,
7183
* Return a vector with sum zero corresponding to the specified
7284
* free vector.
7385
*
74-
* The sum-to-zero transform is defined such that the first K-1
75-
* elements are unconstrained and the last element is the negative
76-
* sum of those elements. This is a linear transform, with no
77-
* Jacobian.
86+
* The sum-to-zero transform is defined using a modified version of the
87+
* the inverse of the isometric log ratio transform (ILR).
88+
* See:
89+
* Egozcue, Juan Jose; Pawlowsky-Glahn, Vera; Mateu-Figueras, Gloria;
90+
* Barcelo-Vidal, Carles (2003), "Isometric logratio transformations for
91+
* compositional data analysis", Mathematical Geology, 35 (3): 279–300,
92+
* doi:10.1023/A:1023818214614, S2CID 122844634
93+
*
94+
* This is a linear transform, with no Jacobian.
7895
*
7996
* @tparam Jacobian unused
8097
* @tparam Vec A type inheriting from `Eigen::DenseBase` or a `var_value` with
@@ -94,10 +111,15 @@ inline plain_type_t<Vec> sum_to_zero_constrain(const Vec& y,
94111
* Return a vector with sum zero corresponding to the specified
95112
* free vector.
96113
*
97-
* The sum-to-zero transform is defined such that the first K-1
98-
* elements are unconstrained and the last element is the negative
99-
* sum of those elements. This is a linear transform, with no
100-
* Jacobian.
114+
* The sum-to-zero transform is defined using a modified version of the
115+
* the inverse of the isometric log ratio transform (ILR).
116+
* See:
117+
* Egozcue, Juan Jose; Pawlowsky-Glahn, Vera; Mateu-Figueras, Gloria;
118+
* Barcelo-Vidal, Carles (2003), "Isometric logratio transformations for
119+
* compositional data analysis", Mathematical Geology, 35 (3): 279–300,
120+
* doi:10.1023/A:1023818214614, S2CID 122844634
121+
*
122+
* This is a linear transform, with no Jacobian.
101123
*
102124
* @tparam Jacobian unused
103125
* @tparam Vec A standard vector with inner type inheriting from

stan/math/rev/constraint/sum_to_zero_constrain.hpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ namespace math {
2020
* Return a vector with sum zero corresponding to the specified
2121
* free vector.
2222
*
23-
* The sum-to-zero transform is defined such that the first K-1
24-
* elements are unconstrained and the last element is the negative
25-
* sum of those elements.
23+
* The sum-to-zero transform is defined using a modified version of the
24+
* the inverse of the isometric log ratio transform (ILR).
25+
* See:
26+
* Egozcue, Juan Jose; Pawlowsky-Glahn, Vera; Mateu-Figueras, Gloria;
27+
* Barcelo-Vidal, Carles (2003), "Isometric logratio transformations for
28+
* compositional data analysis", Mathematical Geology, 35 (3): 279–300,
29+
* doi:10.1023/A:1023818214614, S2CID 122844634
30+
*
31+
* This is a linear transform, with no Jacobian.
2632
*
2733
* @tparam T type of the vector
2834
* @param y Free vector input of dimensionality K - 1.
@@ -63,10 +69,15 @@ inline auto sum_to_zero_constrain(const T& y) {
6369
* Return a vector with sum zero corresponding to the specified
6470
* free vector.
6571
*
66-
* The sum-to-zero transform is defined such that the first K-1
67-
* elements are unconstrained and the last element is the negative
68-
* sum of those elements. This is a linear transform, with no
69-
* Jacobian.
72+
* The sum-to-zero transform is defined using a modified version of the
73+
* the inverse of the isometric log ratio transform (ILR).
74+
* See:
75+
* Egozcue, Juan Jose; Pawlowsky-Glahn, Vera; Mateu-Figueras, Gloria;
76+
* Barcelo-Vidal, Carles (2003), "Isometric logratio transformations for
77+
* compositional data analysis", Mathematical Geology, 35 (3): 279–300,
78+
* doi:10.1023/A:1023818214614, S2CID 122844634
79+
*
80+
* This is a linear transform, with no Jacobian.
7081
*
7182
* @tparam Vec type of the vector
7283
* @param y Free vector input of dimensionality K - 1.

0 commit comments

Comments
 (0)