Conditional expectation of exponential random variable (KPS problem 1.3.4)

import numpy as np

def exprv(Lambda, N):
 return [-np.log(u)/Lambda if u > 0 else 0 for u in np.random.uniform(0,1,N)]

def exppdf(Lambda,x):
 return Lambda*np.exp(-Lambda*x)

L=exprv(Lambda, 10**3)
print("average", mu)
for a in [1,2,3,4]:
 mua=np.mean([x for x in L if x >= a])
 print(a, mua, a +1/Lambda)

average 1.93113738994
1 2.93380553585 3.0
2 3.98684230673 4.0
3 5.11461608894 5.0
4 6.1494766773 6.0


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s