stan-dev / stan-dev/math

Allow multivariate distributions to take in matrices

Open
#2,532 24 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Looking at the Stan docs we only accept arrays of vectors and row vectors for the multivariate distributions. What do folks think about allowing matrices as well?

We could restrict the current signatures to accept std::vector<Template> and then add a version that accepts matrices of size ([N, M], [N, M], [M, M]).

Example

This would allow for things in Stan like

data {
 int N;
 int M;
 matrix[N, M] Y;
}

parameters {
  matrix[N, M] Mu;
  matrix[M, M] Sigma;
}

model {
 Y ~ multi_normal(Mu, Sigma);
}

I would personally find this useful for time series models where Y is a matrix of time series and Mu is made in transformed parameters and does the VAR component.

Expected Output

All multivariate distributions support matrix inputs

Current Version:

v4.1.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 with the current signature in stan/math/prim/prob/multi_normal_lpdf.hpp and review the linked Stan documentation for the existing multivariate distribution inputs. Determine the affected distributions and tests, then verify that all multivariate distributions support the proposed matrix inputs.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.