Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bernoulli_rng - add signature ints bernoulli_rng(real theta) #3044

Open
mitzimorris opened this issue Apr 10, 2024 · 0 comments
Open

bernoulli_rng - add signature ints bernoulli_rng(real theta) #3044

mitzimorris opened this issue Apr 10, 2024 · 0 comments
Labels
distributions Issues that deal with distribution functions: pdf, pmf, cdf good first issue

Comments

@mitzimorris
Copy link
Member

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

@mitzimorris mitzimorris added the distributions Issues that deal with distribution functions: pdf, pmf, cdf label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributions Issues that deal with distribution functions: pdf, pmf, cdf good first issue
Projects
None yet
Development

No branches or pull requests

2 participants