【问题标题】:Multivariate Hypergeometric Distribution in PythonPython中的多元超几何分布
【发布时间】:2020-12-21 10:44:24
【问题描述】:

是否有用于多元超几何分布(包括计算 CDF)的 python 包?

我希望从 scipy 中找到一个,但没有。

我正在考虑使用超几何分布的二项式近似,然后依赖 scipy 支持的多项式分布。 您认为这是一个好方法吗?

【问题讨论】:

    标签: python scipy cdf


    【解决方案1】:

    multivar-hypergeom 的一般用法

    使用multivar-hypergeom,使用pip install multivar-hypergeom轻松安装。

    multivar-hypergeomCDF

    测试中的示例用法:

    # CDF method tests
    @given(st.lists(st.integers(min_value=1, max_value=10000), min_size=2, max_size=10))
    @settings(max_examples=100, deadline=5000)
    def test_cdf_summing_to_1(xs):
        dist = MultivarHypergeom(xs)
        assert 1 - 1e-10 < list(dist.cdf())[-1] < 1 + 1e10
        for i in range(sum(xs)):
            dist.sample1()
            assert 1 - 1e-10 < list(dist.cdf())[-1] < 1 + 1e10
    

    一代

    使用 NumPy 的Generator.multivariate_hypergeometric

    【讨论】:

    • 如果我没记错的话,这个函数只是为了采样,对吧?我需要能够计算分布的 cdf
    • 添加到multivar-hypergeom,它也允许计算 CDF :)
    猜你喜欢
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 2015-06-30
    • 2018-09-01
    相关资源
    最近更新 更多