11---
22title : " Reduce Sum: A Minimal Example"
3- date : " 12 Nov 2020"
3+ date : " 2 Dec 2020"
44output : html_document
55---
66
@@ -13,7 +13,8 @@ This introduction to `reduce_sum` copies directly from Richard McElreath's
1313
1414## Introduction
1515
16- ** Note:** This has been rewritten to use ` _lupmf ` which requires Cmdstan 2.25.
16+ ** Note:** This has been rewritten to use unnormalized distribution functions
17+ ( ` _lupdf˙/˙_lupmf ` ) which requires Cmdstan 2.25 or newer.
1718
1819Cmdstan 2.23 introduced ` reduce_sum ` , a new way to parallelize the execution of
1920a single Stan chain across multiple cores. This is in addition to the already
@@ -168,16 +169,17 @@ holds, then `reduce_sum` is useful.
168169To use ` reduce_sum ` , a function must be written that can be used to compute
169170arbitrary sections of this sum.
170171
171- Note we used ` binomial_logit_lupmf ` instead of ` binomial_logit_lpmf ` .
172+ Note we are using ` binomial_logit_lupmf ` instead of ` binomial_logit_lpmf ` .
172173This is because we only need this likelihood term up to a proportionality
173174constant for MCMC to work and for some distributions this can make code
174- run noticeably faster. Because of the way that ` _lupmf ` features work,
175- Stan only allows them in the model block or in user-defined probability
176- distribution functions, and for us to use ` binomial_logit_lupmf ` the
177- function we write for ` reduce_sum ` will need to be a probability distribution
178- function (suffixed with ` _lpdf ` or ` _lpmf ` ).
179- If the difference in the normalized and unnormalized functions is not
180- relevant for your application, you can call your ` reduce_sum ` function
175+ run noticeably faster. There is a catch though: Stan only allows ` _lupmf `
176+ in the model block or in user-defined probability distribution functions.
177+ Thus, for us to use ` binomial_logit_lupmf ` the, function we write for
178+ ` reduce_sum ` must be a user-defined probability distribution function
179+ (which means it must be suffixed with ` _lpdf ` or ` _lpmf ` ).
180+
181+ If the difference in the performance of normalized and unnormalized functions
182+ is not relevant for your application, you can call your ` reduce_sum ` function
181183whatever you like.
182184
183185Using the reducer interface defined in
0 commit comments