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

Request for vector return from normal_cdf given vector arguments #2468

Open
adkinsty opened this issue Apr 11, 2021 · 7 comments
Open

Request for vector return from normal_cdf given vector arguments #2468

adkinsty opened this issue Apr 11, 2021 · 7 comments

Comments

@adkinsty
Copy link

I wish to execute the normal CDF on vector inputs to obtain a vector of cumulative probabilities. However, I am getting a dimension mismatch error. The error says the return on the right-hand side is of type “real”. The Stan documentation says that the cdf function accepts “reals” arguments and has “reals” returns. I thought this psuedotype “reals” included vectors yet it appears to be returning a scalar.

Example code:

vector[N] mu;
vector[N] sigma;
vector[N] x;
vector[N] phi;

phi = normal_cdf(x, mu, sigma);

Example error:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Dimension mismatch in assignment; variable name = phi, type = vector; right-hand side type = real.
Illegal statement beginning with non-void expression parsed as
  phi
@SteveBronder
Copy link
Collaborator

Yes all the lpdf and cdf functions return back a scalar. A real in the stan language is a scalar

It would be nice to have a vlpdf style function that returned a vector but we haven't had time to implement it

@spinkney
Copy link
Collaborator

This would be nice to have for all the copula stuff as well. As the copulas use the marginal cdfs evaluated at each data point.

@wds15
Copy link
Contributor

wds15 commented Apr 12, 2021

But I think there would not really be a performance gain..so these functions can live in Stan language is what I would think.

@spinkney
Copy link
Collaborator

But I think there would not really be a performance gain..so these functions can live in Stan language is what I would think.

+1 ^

also, the row/col-wise framework proposed by @andrjohns would solve this issue.

@wlandau
Copy link

wlandau commented Jan 25, 2023

This feature would really help when we need access to individual observation-level log likelihoods but still want to take advantage of the vectorization in the _lpdf functions. Example: https://arxiv.org/abs/2209.09190

@hansvancalster
Copy link

It would also help in case of interval censoring. See this comment: paul-buerkner/brms#1657 (comment)

@SteveBronder
Copy link
Collaborator

I have a PR that examples how we can do this. The main thing is it's a huge rewrite of our distributions that would be a lot of elbow grease effort. It would be nice to have a Stan hackathon to go through the distributions with people and do this split up over several people. We also need a test suite change so that all these are tested for vector returns

#2751

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

6 participants