简体   繁体   English

Python Scipy截断指数分布

[英]Python Scipy truncated exponential distribution

I need to construct a truncated exponential random variable, bounded between 5 and 7, with a rate parameter equal to 0.76. 我需要构造一个截断的指数随机变量,其范围在5到7之间,比率参数等于0.76。 I am using scipy.stats.truncexpon, with loc=5 and scale=1/0.76. 我正在使用scipy.stats.truncexpon,loc = 5和scale = 1 / 0.76。 I am not sure how to specify the upper bound though. 我不确定如何指定上限。 Any ideas? 有任何想法吗?

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()

在此处输入图片说明


stats.truncexpon is an instance of a subclass of rv_continuous . stats.truncexponrv_continuous子类的rv_continuous The rv_continuous class has a and b parameters which define the lower and upper bound of the support of the distribution. rv_continuous类具有ab参数,这些参数定义了分布支持的下限和上限 truncexpon has the a parameter fixed at 0: truncexpon a参数固定为0:

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

Thus by default truncexpon 's support goes from 0 to b . 因此,默认情况下truncexpon的支持范围从0b Per the docs , 根据文档

truncexpon.pdf(x, b, loc, scale) is identically equivalent to truncexpon.pdf(y, b) / scale with y = (x - loc) / scale . truncexpon.pdf(x, b, loc, scale)等同于truncexpon.pdf(y, b) / scale其中y = (x - loc) / scale

So as y goes from 0 to b , x goes from loc to b*scale + loc . 因此,当y0变为bxloc变为b*scale + loc So to make x go from lower to upper , let loc = lower and b = (upper-lower)/scale . 因此,要使xlowerupper ,让loc = lowerb = (upper-lower)/scale

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

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