Skip to content

Vectorize multinomial_lpmf #3100

@jachymb

Description

@jachymb

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]);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions