使用 scipy 在 Python 中实现多元正态 CDF [英] Multivariate Normal CDF in Python using scipy

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

问题描述

为了计算多元正态的 CDF,我遵循了这个示例(对于单变量情况)但无法解释 scipy 产生的输出:

In order to calculate the CDF of a multivariate normal, I followed this example (for the univariate case) but cannot interpret the output produced by scipy:

from scipy.stats import norm
import numpy as np
mean = np.array([1,5])
covariance = np.matrix([[1, 0.3 ],[0.3, 1]])
distribution = norm(loc=mean,scale = covariance)
print distribution.cdf(np.array([2,4]))

产生的输出是:

[[  8.41344746e-01   4.29060333e-04]
 [  9.99570940e-01   1.58655254e-01]]

如果联合 CDF 定义为:

If the joint CDF is defined as:

P (X1 ≤ x1, . . . ,Xn ≤ xn)

那么预期输出应该是一个介于 0 和 1 之间的实数.

then the expected output should be a real number between 0 and 1.

推荐答案

找了很多,我觉得this 由 Noah H. Silbert 撰写的博客条目描述了标准库中唯一的现成代码,可用于计算 Python 中多元正态的 cdf.Scipy 有办法做到这一点,但正如博客中提到的那样,很难找到.该方法基于 Alan Genz 的一篇论文.

After searching a lot, I think this blog entry by Noah H. Silbert describes the only readymade code from a standard library that can be used for computing the cdf for a multivariate normal in Python. Scipy has a way to do it but as mentioned in the blog, it is difficult to find. The approach is based on a paper by Alan Genz’s.

来自博客,这是它的工作原理.

From the blog, this is how it works.

from scipy.stats import mvn
import numpy as np
low = np.array([-10, -10])
upp = np.array([.1, -.2])
mu = np.array([-.3, .17])
S = np.array([[1.2,.35],[.35,2.1]])
p,i = mvn.mvnun(low,upp,mu,S)
print p

0.2881578675080012

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

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