我想根据各种类型的连续概率分布函数(PDF)生成用于测试的样本。例如,我有一个超过 24 小时的 PDF,我想知道事件在 10 分钟、20 分钟、30 分钟......等等发生的概率。
因此,我想计算 P(a < X < a + n), where n is a time value of my choice. Does it exists any module capable of doing this with Python ? Is it also usable for summation of PDF ?
我想使用蓝色 PDF 检索红色直方图。我已经能够在这里执行此操作,因为我已经知道每个时间片的事件数量,但我想自动执行此操作。这里它是一个威布尔函数,但它可以是其他任何函数(主要是普通函数和威布尔函数)。
Python 有什么可以帮助我的吗?
谢谢。
编辑:Weibull 的 CDF 和 PDF 代码:
def weibull_pdf(scale, shape, x):
"""
Determine the probability P(x ).
:param scale: Scale parameter of Weibull distribution.
:param shape: Shape parameter of Weibull distribution.
:param x: Value.
:return: Value of f(x).
"""
if x < 0:
return 0
return (shape / scale) * ((x / scale) ** (shape - 1)) * np.exp(- (x / scale) ** shape)
def weibull_cdf(scale, shape, x):
"""
Determine the cumulative distributive function for the Weibull distribution.
:param scale: Scale parameter of Weibull distribution.
:param shape: Shape parameter of Weibull distribution.
:param x: Upper bound of the distribution.
:return: P(x <= X).
"""
if x < 0:
return 0
return 1 - np.exp(- (x / scale) ** shape)
PDF 确定如下:
# Determination of the PDF function.
for i in range(1, 10):
cdf = weibull_cdf(SCALE, SHAPE, i) - weibull_cdf(SCALE, SHAPE, i - 1)
print"CDF for interval [{}, {}]: {}".format(i - 1, i, str(cdf))
x = [i / (INPUTS_NB / 10.0) for i in range(INPUTS_NB)]
results = [weibull_pdf(SCALE, SHAPE, x[j]) for j in range(len(x))]
edit2:好吧,我在编码时并没有真正注意到这一点,但我已经在上一批代码中回答了我自己的问题(PDF函数的确定)。不过还是谢谢DYZ提供的信息。只需要做 P(X < a+n) - P(X < a) to determine P(a < X < a+n)..
我们如何在不实现实际数学函数的情况下从 np.random.weibull 的 pdf 确定 cdf