Skip to content

Commit daaec34

Browse files
committed
Respond to comments
1 parent 19fb70a commit daaec34

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

knitr/reduce-sum/logistic1.stan

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ functions {
55
vector rating,
66
vector beta) {
77
return binomial_logit_lupmf(slice_n_redcards |
8-
n_games[start:end],
9-
beta[1] + beta[2] * rating[start:end]);
8+
n_games[start:end],
9+
beta[1] + beta[2] * rating[start:end]);
1010
}
1111
}
1212
data {
13-
int N;
14-
int n_redcards[N];
15-
int n_games[N];
13+
int<lower=0> N;
14+
int<lower=0> n_redcards[N];
15+
int<lower=0> n_games[N];
1616
vector[N] rating;
17+
int<lower=1> grainsize;
1718
}
1819
parameters {
1920
vector[2] beta;
2021
}
2122
model {
22-
int grainsize = 1;
23-
2423
beta[1] ~ normal(0, 10);
2524
beta[2] ~ normal(0, 1);
2625

knitr/reduce-sum/reduce_sum_tutorial.Rmd

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Reduce Sum: A Minimal Example"
3-
date: "12 Nov 2020"
3+
date: "2 Dec 2020"
44
output: 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

1819
Cmdstan 2.23 introduced `reduce_sum`, a new way to parallelize the execution of
1920
a single Stan chain across multiple cores. This is in addition to the already
@@ -168,16 +169,17 @@ holds, then `reduce_sum` is useful.
168169
To use `reduce_sum`, a function must be written that can be used to compute
169170
arbitrary 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`.
172173
This is because we only need this likelihood term up to a proportionality
173174
constant 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
181183
whatever you like.
182184

183185
Using the reducer interface defined in

0 commit comments

Comments
 (0)