hyunjimoon / hyunjimoon/DataInDM

Parallelize loglik computation using reduce_sum

Open
#12 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
3
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Write a new function in a for loop fashion so that loglik computation can be parallelized (using `+`'s associative). New component for `function block`, change `~` to `+=` for model and gq block
```
//function
real partial_sum_lpmf(int[] slice_n_redcards,
int start, int end,
int[] n_games,
vector rating,
vector beta) {
return binomial_logit_lupmf(slice_n_redcards |
n_games[start:end],
beta[1] + beta[2] * rating[start:end]);
}
// model
...
target += reduce_sum(partial_sum_lupmf, n_redcards, grainsize,
n_games, rating, beta);
```

Ref
Start from Sebastian's [Gelblog](https://statmodeling.stat.columbia.edu/2020/05/05/easy-within-chain-parallelisation-in-stan/) intro.
1. A [case study](https://mc-stan.org/users/documentation/case-studies/reduce_sum_tutorial.html) which adapts Richard McElreath’s intro to map_rect for reduce_sum
2. User manual introduction to reduce_sum parallelism with a simple example as well: [23.1 Reduce-Sum](https://mc-stan.org/docs/2_23/stan-users-guide/reduce-sum.html)
3. Function reference: [9.4 Reduce-Sum Function](https://mc-stan.org/docs/2_23/functions-reference/functions-reduce.html)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.