bernoulli_rng - add signature `ints bernoulli_rng(real theta)`
mitzimorris opened this issue · 0 comments
mitzimorris commented
Description
Add implementation of bernoulli_rng
which generates an array of bernoulli outcomes for a single value of theta
.
Example
Currently, it is necessary to use a loop, e.g.
real theta = beta_rng(1, 1);
array[N] int y;
for (n in 1:N) {
y[n] = bernoulli_rng(theta);
}
The vectorized alternative is:
real theta = beta_rng(1, 1);
array[N] int y;
y = bernoulli_rng(rep_array(theta, N_obs));
This is problematic for 2 reasons:
- requires extra memory allocation for the array of
thetas
- not as easy to grok
Expected Output
It would be nice to be able to do the following:
real theta = beta_rng(1, 1);
array[N] int y;
y = bernoulli_rng(rtheta);
Current Version:
v4.8.1