11---
22title : " Reduce Sum: A Minimal Example"
3- date : " 16 June 2020"
3+ date : " 12 Nov 2020"
44output : html_document
55---
66
@@ -159,7 +159,7 @@ for(n in 1:N) {
159159
160160Now it is clear that the calculation is the sum (up to a
161161proportionality constant) of a number of conditionally independent
162- Bernoulli log probability statements. So whenever we need to calculate
162+ Bernoulli log probability statements. Whenever we need to calculate
163163a large sum where each term is independent of all others and associativity
164164holds, then ` reduce_sum ` is useful.
165165
@@ -171,9 +171,9 @@ This is because we only need this likelihood term up to a proportionality
171171constant for MCMC to work and for some distributions this can make code
172172run noticeably faster. Because of the way that ` _lupmf ` features work,
173173Stan only allows them in the model block or in user-defined probability
174- distribution functions, and so the function we write for ` reduce_sum `
175- will need to be a probability distribution function (suffixed with
176- ` _lpdf ` or ` _lpmf ` ) for us to use ` binomial_logit_lupmf ` on the inside .
174+ distribution functions, and for us to use ` binomial_logit_lupmf ` the
175+ function we write for ` reduce_sum ` will need to be a probability distribution
176+ function (suffixed with ` _lpdf ` or ` _lpmf ` ).
177177If the difference in the normalized and unnormalized functions is not
178178relevant for your application, you can call your ` reduce_sum ` function
179179whatever you like.
@@ -216,11 +216,11 @@ target += partial_sum_lupmf(n_redcards[1:M], 1, M, n_games, rating, beta) // Sum
216216target += partial_sum_lupmf(n_redcards[(M + 1):N], M + 1, N, n_games, rating, beta); // Sum terms M + 1 to N
217217```
218218
219- By passing ` partial_sum_lupmf ` to ` reduce_sum ` , we allow Stan to
219+ By passing ` partial_sum_lupmf ` to ` reduce_sum ` , we tell Stan to
220220automatically break up these calculations and do them in parallel.
221221
222222Notice the difference in how ` n_redcards ` is split in half (to reflect
223- which terms of the sum are being accumulated) and the rest of the arguments
223+ which terms of the sum are being accumulated) and the rest of the arguments
224224(` n_games ` , ` x ` , and ` beta ` ) are left alone. This distinction is important
225225and more fully described in the User's Guide section on
226226[ Reduce-sum] ( https://mc-stan.org/docs/2_23/stan-users-guide/reduce-sum.html ) .
0 commit comments