Skip to content

Vectorize predictors in categorical(_logit) #3102

Open
@bob-carpenter

Description

@bob-carpenter

Description

As is, the categorical and categorical_logit pdfs allow multiple outputs, but not multiple parameters.

This was requested in docs, but doesn't exist yet: stan-dev/docs#500

Example

Currently:

Available signatures:
(array[] int, vector) => real
  The second argument must be vector but got matrix
(int, vector) => real
  The first argument must be int but got array[] int

What we want is to add the following signature in the usual way (so that each row of the matrix corresponds to an entry of the integer array):

(array[] int, matrix) => real

and maybe

(array[] int, array[] vector) => real

The goal is to support vectorized code that looks like this:

data {
  int<lower=0> K;
  int<lower=0> N;
  int<lower=0> D;
  array[N] int<lower=1, upper=K> y;
  matrix[N, D] x;
}
parameters {
  matrix[D, K] beta;
}
model {
  to_vector(beta) ~ normal(0, 5);
  y ~ categorical_logit(x * beta);
}

Expected Output

Above example compiles.

Current Version:

v4.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions