首页 > 解决方案 > 子类化 scipy.stats.rv_continuous

问题描述

我花了相当大的努力和搜索尝试子类scipy.stats.rv_continuous化以生成 Weibull 概率分布的新参数化 ( weibull_max),但不明白应该如何完成。我正在尝试将分布设置为能够使用 pdf、cdf、随机变量和拟合方法。

我可以使用以下独立函数生成所需的 pdf:

def weibull3P_pdf(x, shape, thres=0, loc=0, scale=1):
    return np.flip(scistats.weibull_max
                   .pdf(-x - thres, shape,
                        loc=loc, scale=scale))

有人会猜测以下应该可以工作:

class weibull3P_gen(scistats.rv_continuous):

    def _argcheck(self, c, k):
        return (c > 0) & (k < 0)

    def _get_support(self, c, k):
        return k, -k

    def _pdf(self, x, c, k):
        # Adjusted accordingly from weibull_max._pdf
        return c * pow(-x - k, c - 1) * np.exp(-pow(-x - k, c))


weibull3P = weibull3P_gen(name="weibull3P")

但该pdf方法不会产生相同的结果。欢迎任何指点。

标签: pythonscipy.stats

解决方案


推荐阅读