用Java计算多元正态CDF [英] Compute the multivariate normal CDF in Java

查看:297
本文介绍了用Java计算多元正态CDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道一个可靠,准确的库来计算Java中的多元正态(MVN)CDF吗?我正在寻找类似 MATLAB的mvncdf函数之类的东西.我需要能够做到尺寸最大为10或更大.大多数统计资料/数学库没有此功能.能够计算对数概率是一个加分.

Does anyone know of a reliable, accurate library to compute the multivariate normal (MVN) CDF in Java? I'm looking for something like MATLAB's mvncdf function. I need to be able to do it for dimensions of up to 10 or more. Most statistics/math libraries don't have this functionality. Being able to compute the log probability is a plus.

此帖子中,似乎没有为其他一些语言提到的免费实现.虽然直接的Java实现可能会摇摇欲坠,但我会接受其他不需要许可证的语言(例如,不需要MATLAB或IMSL)的实现,并且可以用最少的开销从Java轻松调用它.

From this post, there doesn't seem to be a free implementation mentioned for some other languages. While a straight-java implementation would rock, I would accept implementations in other languages that don't require licenses (not MATLAB or IMSL, for example) and can be called easily from Java with minimal overhead.

(此问题是在StackExchange数学上发表文章,我试图在其中计算正态随机变量排序的可能性...如果您有兴趣尝试使用其他数学方法直接解决问题,请务必进行检查. )

(This question is a derivative of a post on StackExchange math where I am trying to compute a probability of an ordering of normal random variables...if you're interested in trying to solve the problem directly using other mathematical methods, please do check it out.)

推荐答案

进行了一些额外的研究之后,似乎以下是最合理的方法.

After doing some additional research, it seems that the following is the most reasonable way to go.

多元正态CDF的计算并非易事(特别是对于大尺寸而言),并且已经有几篇学术论文针对此主题进行了撰写. Alan Genz教授有许多计算各种多元密度和CDF的Fortran-77子例程,可在其页面上找到:

The multivariate normal CDF is not trivial to compute (especially for large dimensions) and there have been several academic papers written on the subject. Professor Alan Genz has a bunch of Fortran-77 subroutines that compute various multivariate densities and CDFs, available on his page here: http://www.math.wsu.edu/faculty/genz/software/software.html

从某些代码中可以看到,用另一种语言重新实现并不是一个轻松的选择,这也许就是为什么除非有人为此付出代价,否则它没有完成的原因.在研究级别,Fortran进行了大量数学/数字编程,因此,这是大多数最佳代码的所在.

As you can see from some of that code, it's not exactly a cakewalk to re-implement in another language, and that's probably why it hasn't been done unless someone has paid for it. A lot of mathematical/numerical programming is done in Fortran at the research level, so that's where most of the best code is.

这样,为了获得最佳结果,最好直接使用JNI或JNA调用(本机编译的)Fortran子例程.遵循以下指示,JNA似乎是最容易实现的: http://www.javaforge.com/wiki/66061 .使用该代码以及其他一些参考,我实现了Java-JNA-Fortran链接,以便能够调用MVNEXP(期望值)和MVNDST(cdf)子例程.您可以在此处查看代码:

As such, for optimal results, it would probably be best to call the (native-compiled) Fortran subroutine directly using JNI or JNA. JNA seems to be the easiest to implement, following instructions such as these: http://www.javaforge.com/wiki/66061. Using that, and some other references, I've implemented the Java-JNA-Fortran link to be able to call the MVNEXP (expected value) and MVNDST (cdf) subroutines. You can check out the code here:

  • Java: https://github.com/mizzao/libmao/tree/master/src/main/java/net/andrewmao/probability
  • Fortran (modified) and Makefile: https://github.com/mizzao/libmao/tree/master/src/main/fortran

还要指出:对于某些双变量分布以及在公共数学中找不到的其他东西,确实存在本机Java代码.改编自以上来源: http://www.iro.umontreal.ca /~simardr/ssj/indexe.html .这是一个很好的数学库,直到现在我还没有发现.

Also to point out: there does exist native Java code for some bivariate distributions and other things you won't find in commons math; it's adapted from the source above: http://www.iro.umontreal.ca/~simardr/ssj/indexe.html . This is a very good math library that I hadn't found until now.

这篇关于用Java计算多元正态CDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆