简体   繁体   English

在多元正态分布中找出概率

[英]finding probability in multivariate normal distribution

I am using python. 我正在使用python。 I know that to find probability in multivariate normal distribution I have to use following: 我知道要在多元正态分布中找到概率,我必须使用以下内容:

fx(x1,…,xk) = (1/√(2π)^k|Σ|) * exp(−1/2(x−μ)T* Σ^-1 *(x−μ)) fx(x1,...,xk)=(1 /√(2π)^ k |Σ|)* exp(-1/2(x-μ)T *Σ^ -1 *(x-μ))

where x = [x1, x2] 其中x = [x1,x2]

I have different values of x1 and x2. 我有不同的x1和x2值。

but here I have to find probability for: 但在这里我必须找到概率:

0.5< x1<1.5 and 4.5< x2<5.5 0.5 <x1 <1.5和4.5 <x2 <5.5

I know how to use this formula for single value of x1 and x2. 我知道如何将此公式用于x1和x2的单个值。 But I am confused in this case. 但在这种情况下我很困惑。 Please help. 请帮忙。

What you need to so is find the area beneath the function for the rectangle bounded by 0.5 < x1 < 1.5 and 4.5 < x2 < 5.5 . 你需要的是找到函数下面的区域,该矩形由0.5 < x1 < 1.54.5 < x2 < 5.5界定。

As a quick and dirty solution, you could use this code to do a two-variable Reimann sum to estimate the integral. 作为一种快速而肮脏的解决方案,您可以使用此代码执行双变量Reimann和来估计积分。 A Reimann sum just divides the rectangle into small regions and approximates the area under each region as if the function was flat. Reimann和只是将矩形划分为小区域并近似每个区域下的区域,就好像函数是平坦的一样。

Provided you've defined your distribution as the function f . 如果您已将分布定义为函数f

x1Low   = 0.5
x1Hi    = 1.5
x2Low   = 4.5
x2Hi    = 5.5

x1steps = 1000
x2steps = 1000
x1resolution = (x1Hi-x1Low)/x1steps
x2resolution = (x2Hi-x2Low)/x2steps
area = x1resolution*x2resolution

x1vals = [x1Low + i*x1resolution for i in range(x1steps)]
x2vals = [x2Low + i*x2resolution for i in range(x2steps)]

sum = 0;
for i in range(len(x1vals-1)):
    for j in range(len(x2vals-1)):
        sum += area * f(x1vals[i],x2vals[j])

print sum

Keep in mind that this sum is only an approximation, and not a great one either. 请记住,这个总和只是一个近似值,也不是一个很好的总和。 It will seriously over- or under-estimate the integral in regions where the function changes too quickly. 它将严重高估或低估功能变化太快的区域中的积分。

If you need more accuracy, you can try implementing triangle rule or simpsons's rule , or look into scipy's numerical integration tools . 如果您需要更高的准确度,可以尝试实现三角规则或辛普森的规则 ,或者查看scipy的数值积分工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM