Python Scipy截断指数分布

时间:2016-10-20 00:43:00

标签: python scipy

我需要构造一个截断的指数随机变量,其范围在5到7之间,速率参数等于0.76。我使用scipy.stats.truncexpon,loc = 5,scale = 1 / 0.76。我不知道如何指定上限。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

import scipy.stats as stats
import matplotlib.pyplot as plt

lower, upper, scale = 5, 7, 1/0.76
X = stats.truncexpon(b=(upper-lower)/scale, loc=lower, scale=scale)
data = X.rvs(10000)

fig, ax = plt.subplots()
ax.hist(data, normed=True)
plt.show()

enter image description here

stats.truncexponinstance of a subclass of rv_continuousrv_continuous类具有a and b parameters which define the lower and upper bound分发的支持。 truncexpon a参数固定为0:

truncexpon = truncexpon_gen(a=0.0, name='truncexpon')

因此,默认truncexpon的支持从0转到bPer the docs

  

truncexpon.pdf(x, b, loc, scale)完全相同   相当于truncexpon.pdf(y, b) / scale y = (x - loc) / scale

y0转到b时,xloc转到b*scale + loc。 为了让xlower转到upper,请loc = lowerb = (upper-lower)/scale

相关问题