Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
概率分布与Python_Python_Math_Probability_Weibull - Fatal编程技术网

概率分布与Python

概率分布与Python,python,math,probability,weibull,Python,Math,Probability,Weibull,我想根据各种类型的连续概率分布函数(PDF)生成测试样本。例如,我有一个超过24小时的PDF,我想知道一个事件在10分钟、20分钟、30分钟发生的概率。。。。等等 因此,我想计算p(a

我想根据各种类型的连续概率分布函数(PDF)生成测试样本。例如,我有一个超过24小时的PDF,我想知道一个事件在10分钟、20分钟、30分钟发生的概率。。。。等等

因此,我想计算p(a 这是我想要实现的一个数字

我想检索红色直方图,使用蓝色PDF。我已经能够在这里做了,因为我已经知道每个时间片上的事件数,但是我想自动做。这里它是一个威布尔函数,但它可以是任何其他函数(主要是正常函数和威布尔函数)

在python方面有什么可以帮助我的吗

谢谢

编辑:威布尔的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)

edit2:好的,我在编写代码时并没有注意到这一点,但我已经在上面的代码中回答了我自己的问题(确定PDF函数)。不过,谢谢DYZ提供的信息。只需要做P(XPDF是如何给你的?它是Python函数吗?对于上面的函数,我已经有了参数,并且刚刚编写了规则。除此之外,我在样本上使用EM工具来检索法律参数,并将它们与我开发的函数一起使用。但是你读过我的问题了吗?请在您的问题中包含PDF函数的Python定义。我已经编辑了这篇文章。首先,在
numpy.random.Weibull()中有一个Weibull PDF的现成实现。为了提高效率,您可能需要使用它,因为它可以一次生成成吨的样本,这就是您需要的:创建多个样本(10000?)的数组
arr
,并调用
numpy.histogram(arr)
。PDF是如何提供给您的?它是Python函数吗?对于上面的函数,我已经有了参数,并且刚刚编写了规则。除此之外,我在样本上使用EM工具来检索法律参数,并将它们与我开发的函数一起使用。但是你读过我的问题了吗?请在您的问题中包含PDF函数的Python定义。我已经编辑了这篇文章。首先,在
numpy.random.Weibull()中有一个Weibull PDF的现成实现。为了提高效率,您可能需要使用它,因为它可以一次生成成吨的样本,这就是您需要的:创建多个样本(10000?)的数组
arr
,并调用
numpy.histogram(arr)
# 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))]