1

【Python】2 examples of Chebyshev inequality.

 2 years ago
source link: https://www.guofei.site/2017/08/04/pythonchebyshev.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【Python】2 examples of Chebyshev inequality.

2017年08月04日

Author: Guofei

文章归类: 趣文,文章编号:


版权声明:本文作者是郭飞。转载随意,但需要标明原文链接,并通知本人
原文链接:https://www.guofei.site/2017/08/04/pythonchebyshev.html

Edit

About the theory of Chebyshev inequality, see law of large numbers.

2 examples

This blog gives 2 examples of Chebyshev inequality: standard norm distribution, student’s t-distribution.

chebyshev

Here are two forms of Chebyshev inequality:

chebyshev1

Pr[∣X−u∣≥s]≤σ2s2Pr[∣X−u∣≥s]≤σ2s2
If the p.d.f is an even function ( meaning u=0 ),
Pr[X−u≥s]≤σ22s2Pr[X−u≥s]≤σ22s2

chebyshev2

(also known as Cantelli’s inequality)
Pr[X−u≥s]≤σ2s2+σ2Pr[X−u≥s]≤σ2s2+σ2

let u=0,σ2=1u=0,σ2=1

def chebyshev1(u,sigma,s):
    return sigma**2/s**2

def chebyshev2(u,sigma,s):
    return sigma**2/(sigma**2+s**2)

import numpy as np
u=0;sigma=1;

chebylist1=[]
chebylist2=[]
xlist=np.arange(0.5,5,0.01)
for s in xlist:
    #min(chebyshev1(u,sigma,s)/2,chebyshev2(u,sigma,s))
    chebylist1.append(chebyshev1(u,sigma,s)/2)
    chebylist2.append(chebyshev2(u,sigma,s))


from scipy.stats import norm
normlist=norm.sf(xlist)

from scipy.stats import t
tlist=t.sf(xlist,df=2)

import matplotlib.pyplot as plt
plt.plot(xlist,chebylist1)
plt.plot(xlist,chebylist2)
plt.plot(xlist,normlist)
plt.plot(xlist,tlist)
plt.legend(['chebyshev inequality 1','chebyshev inequality 2','norm distribution equality','t-distribution equality'])
plt.show()

output:

chebyshev.png

The graph tells us the accuracy of the Chebysheve inequality.


您的支持将鼓励我继续创作!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK