stan-dev / stan-dev/math

Vectorize predictors in categorical(_logit)

Open
#3,102 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

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: https://github.com/stan-dev/docs/issues/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the categorical and categorical_logit probability-function entry points and their existing vectorization support. Check how signatures for array[] int with vector parameters are defined, then add coverage for the matrix form and verify that the supplied Stan example compiles; the array[] vector form remains optional as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.