We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9cf06f1 commit 86fed93Copy full SHA for 86fed93
1 file changed
stan/math/rev/constraint/sum_to_zero_constrain.hpp
@@ -44,14 +44,15 @@ inline auto sum_to_zero_constrain(const T& y) {
44
for (int i = 0; i < N; ++i) {
45
double n = i + 1;
46
47
- double u_adj = arena_z.adj()(i);
48
- sum_u_adj += u_adj;
+ // adjoint of the reverse cumulative sum computed in the forward mode
+ sum_u_adj += arena_z.adj()(i);
49
50
- double v_adj = -arena_z.adj()(i + 1);
+ // adjoint of the offset subtraction
51
+ double v_adj = -arena_z.adj()(i + 1) * n;
52
- double w = (v_adj * n) + sum_u_adj;
53
+ double w_adj = v_adj + sum_u_adj;
54
- arena_y.adj()(i) += w / sqrt(n * (n + 1));
55
+ arena_y.adj()(i) += w_adj / sqrt(n * (n + 1));
56
}
57
});
58
0 commit comments