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

Vectorize multinomial_lpmf #3100

Open
jachymb opened this issue Aug 3, 2024 · 0 comments
Open

Vectorize multinomial_lpmf #3100

jachymb opened this issue Aug 3, 2024 · 0 comments

Comments

@jachymb
Copy link

jachymb commented Aug 3, 2024

Currently, there is only this signature:
real multinomial_lpmf(array[] int y | vector theta) (the vector is actually a simplex but this is probably for efficiency?)

I wish there was a vectorized variant with the following signature (or compatible):

real multinomial_lpmf(array[ , ] int y | array[] simplex theta)

and probably

real multinomial_lpmf(array[ , ] int y | simplex theta) (assume all have same parameters)

it feels awkward to write for cycle for something most other distributions implement.

sample code where I use it to estimate mean product rating:

data {
  int<lower=1> N;  // num products
  array[N, 5] int<lower=0> ratings;
}
parameters {
  vector<lower=0>[5] alpha;
  array[N] simplex[5] d;
}
model {
  d ~ dirichlet(alpha);  // for all d[i]
  for (i in 1:N) {  // unlike dirichlet, multinomial not vectorized
    ratings[i] ~ multinomial(d[i]);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant