stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.57k stars 369 forks source link

multivariate normal integral/cdf function (feature request) #158

Closed noahaskell closed 11 years ago

noahaskell commented 11 years ago

I am (formally) requesting that a multivariate normal integral function be added to Stan. I don't see such a function in the to-do list, and I couldn't find anything about it in the issue report/feature request log, but it would be very useful to have.

For what it's worth, Alan Genz has (from what I can tell) good Fortran code for calculating multivariate normal integrals (I don't know how easy it would be to adapt Fortran code for use in Stan, but I thought I'd at least attempt to be as helpful as I could when asking for a feature like this):

http://www.math.wsu.edu/faculty/genz/software/fort77/mvndstpack.f http://www.math.wsu.edu/faculty/genz/software/fort77/mvnpack.f

The numerical method he developed to calculate multivariate normal and t integrals is described in these papers:

http://www.math.wsu.edu/faculty/genz/papers/mvn.pdf http://www.math.wsu.edu/faculty/genz/papers/bvnt.pdf

He also has an R package called mvtnorm.

Thanks!

bob-carpenter commented 11 years ago

You mean basically the CDF for multivariate normal?

Thanks for the citations. We could code the algorithm in the Genz paper directly in templated C++ and that would work. It would be much more efficient if we could calculate partial derivatives w.r.t. inputs efficiently.

I'm guessing these may have well-understood forms, but Ben or Marcus or Andrew will know.

Having a functional program to work from is always a plus.

(Speaking of integration, we also need the inverse CDFs.)

On 7/22/13 1:32 PM, noahmotion wrote:

I am (formally) requesting that a multivariate normal integral function be added to Stan. I don't see such a function in the to-do list, and I couldn't find anything about it in the issue report/feature request log, but it would be very useful to have.

For what it's worth, Alan Genz has (from what I can tell) good Fortran code for calculating multivariate normal integrals (I don't know how easy it would be to adapt Fortran code for use in Stan, but I thought I'd at least attempt to be as helpful as I could when asking for a feature like this):

http://www.math.wsu.edu/faculty/genz/software/fort77/mvndstpack.f http://www.math.wsu.edu/faculty/genz/software/fort77/mvnpack.f

The numerical method he developed to calculate multivariate normal and t integrals is described in these papers:

http://www.math.wsu.edu/faculty/genz/papers/mvn.pdf http://www.math.wsu.edu/faculty/genz/papers/bvnt.pdf

He also has an R package called mvtnorm.

Thanks!

— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/158.

noahaskell commented 11 years ago

Thanks for the quick response, and yes, I meant the CDF for the multivariate normal density. I'm not sure about the partial derivatives or inverse CDFs, unfortunately, but maybe the papers I linked to will be helpful on those fronts?

noahaskell commented 11 years ago

I just remembered that Tom Wickens' gives the partial derivatives for the bivariate Gaussian CDF in his 1992 J. of Math. Psych. paper (the broader point of which is to describe the Newton-Raphson algorithm for maximum likelihood estimation of the parameters in a multidimensional signal detection/probit model):

http://www.sciencedirect.com/science/article/pii/0022249692900378

bob-carpenter commented 11 years ago

Moved to to-do list with notes.