跳转到主要内容

Hartigan的diptest。

项目描述

diptest

Linux Build Windows Build MacOS build PyPi

Python/C(++)对Hartigan & Hartigan的单峰性diptest的实现。

diptest通过在所有样本点之间,经验分布函数与最小化该最大差异的单峰分布函数之间的最大差异来衡量样本中的多峰性。除了单峰性,它对零分布的形式没有其他假设。

用法

此库提供两个函数

  • dipstat
  • diptest

第一个只计算Hartigan的diptest统计量。 diptest 计算统计量和p值。p值可以使用临界值表的插值(默认)或通过自举零假设来计算。注意,对于较大的样本(N > 1e5),这计算和内存密集度很高。

    import numpy as np
    import diptest

    # generate some bimodal random draws
    N = 1000
    hN = N // 2
    x = np.empty(N, dtype=np.float64)
    x[:hN] = np.random.normal(0.4, 1.0, hN)
    x[hN:] = np.random.normal(-0.4, 1.0, hN)

    # only the dip statistic
    dip = diptest.dipstat(x)
    
    # both the dip statistic and p-value
    dip, pval = diptest.diptest(x)

依赖项

  • numpy
  • [可选] OpenMP

使用OpenMP提供通过自举计算p值的并行化。OpenMP默认禁用,但可以启用,请参阅下面的安装部分。可以通过将线程数设置为1来关闭多线程。有关详细信息,请参阅 diptest 的文档字符串。

安装

diptest 可以通过 PyPi 使用以下命令安装:

    pip install diptest

以下预编译扩展的 Wheel 包可供使用:

  • Windows x84-64 - CPython 3.8 - 3.12
  • Linux x84-64 - CPython 3.8 - 3.12
  • MacOS x84-64 - CPython 3.8 - 3.12
  • MacOS ARM-64 - CPython 3.8 - 3.12

请注意,Wheel 包供应商/发行商将 OpenMP 与扩展一起提供,以便提供开箱即用的并行化。如果您遇到加载多个 OpenMP 版本的问题,您有两个选择:从源代码构建或安装非捆绑 Wheel。

非捆绑 Wheel

我们在此提供了相同的 Wheel 包,但不包含 OpenMP:[https://github.com/RUrlus/diptest/releases](https://github.com/RUrlus/diptest/releases) 您可以安装与您的 Python 和操作系统相对应的 Wheel 包。例如,对于 CPython 3.11 和 MacOS ARM

pip install diptest-0.8.0-cp311-cp311-macosx_11_0_arm64.whl

从源代码构建

如果您有 C/C++ 编译器可用,建议不使用 Wheel 进行安装,因为这可以启用特定架构的优化。

    pip install diptest --no-binary diptest

通过 Pybind11 兼容的编译器

  • Clang/LLVM 3.3 或更高版本(对于 Apple Xcode 的 clang,这是 5.0.0 或更高版本)
  • GCC 4.8 或更高版本
  • Microsoft Visual Studio 2015 更新 3 或更高版本
  • Intel 经典 C++ 编译器 18 或更高版本(在 CI 中测试了 ICC 20.2)
  • Cygwin/GCC(以前在 2.5.1 上测试过)
  • NVCC(在 CI 中测试了 CUDA 11.0)
  • NVIDIA PGI(在 CI 中测试了 20.9)

禁用 OpenMP

要禁用 OpenMP,请使用

    SKBUILD_CMAKE_ARGS="-DDIPTEST_DISABLE_OPENMP=ON" pip install diptest --no-binary diptest

调试安装

要启用调试构建,请使用

    SKBUILD_CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug" pip install diptest --no-binary diptest

调试打印

要启用调试打印语句,请使用

    SKBUILD_CMAKE_ARGS="-DDIPTEST_ENABLE_DEBUG=ON" pip install diptest --no-binary diptest

然后调用函数,将调试参数设置为大于零的值

    diptest(x, debug=1)

参考文献

Hartigan, J. A. & Hartigan, P. M. (1985). The Dip Test of Unimodality. The Annals of Statistics.

Hartigan, P. M. (1985). Computation of the Dip Statistic to Test for Unimodality. Journal of the Royal Statistical Society. Series C (Applied Statistics), 34(3), 320-325.

致谢

diptest 只是 Martin Maechler 的 R 模块 diptest 的 Python 端口。包装 C 实现的包最初由 Alistair Muldal 编写。这个分支是一个更新,包含了许多更改

  • 修复了 _dip.c 中的缓冲区溢出问题,通过回滚到原始 C 实现来修复
  • 使用 Pybind11 (C++) 而不是 Cython 的 Python 绑定
  • 将 P 值计算从 Python 移动到 C++,并提供了通过 OpenMP 的可选并行化支持
  • 通过编译时定义将调试分支语句放入其中,从而消除了调试分支语句引起的开销
  • 添加了测试和 Wheel 支持
  • diptest 的 C 实现由 Prodromos Kolyvakis 重新编写为 C++

许可证

diptest 是免费软件:您可以在自由软件基金会发布的 GNU 通用公共许可证的条款下重新分发和/或修改它,许可证版本为 3,或(根据您的选择)任何更高版本。

项目详情


下载文件

下载适用于您平台的应用程序文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。

源代码发行版

diptest-0.8.1.tar.gz (86.3 kB 查看哈希值)

上传时间 源代码

构建版本

diptest-0.8.1-cp312-cp312-win_amd64.whl (400.5 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

diptest-0.8.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.8 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp312-cp312-macosx_12_0_x86_64.whl (417.7 kB 查看哈希值)

上传时间 CPython 3.12 macOS 12.0+ x86-64

diptest-0.8.1-cp312-cp312-macosx_12_0_arm64.whl (368.1 kB 查看哈希值)

上传时间 CPython 3.12 macOS 12.0+ ARM64

diptest-0.8.1-cp311-cp311-win_amd64.whl (400.4 kB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

diptest-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (197.4 kB 查看哈希值)

上传时间 CPython 3.11 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp311-cp311-macosx_12_0_x86_64.whl (418.8 kB 查看哈希值)

上传时间 CPython 3.11 macOS 12.0+ x86-64

diptest-0.8.1-cp311-cp311-macosx_12_0_arm64.whl (368.8 kB 查看哈希值)

上传时间 CPython 3.11 macOS 12.0+ ARM64

diptest-0.8.1-cp310-cp310-win_amd64.whl (399.4 kB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

diptest-0.8.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.3 kB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp310-cp310-macosx_12_0_x86_64.whl (417.3 kB 查看哈希值)

上传于 CPython 3.10 macOS 12.0+ x86-64

diptest-0.8.1-cp310-cp310-macosx_12_0_arm64.whl (367.4 kB 查看哈希值)

上传于 CPython 3.10 macOS 12.0+ ARM64

diptest-0.8.1-cp39-cp39-win_amd64.whl (400.2 kB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

diptest-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.4 kB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp39-cp39-macosx_12_0_x86_64.whl (417.4 kB 查看哈希值)

上传于 CPython 3.9 macOS 12.0+ x86-64

diptest-0.8.1-cp39-cp39-macosx_12_0_arm64.whl (367.5 kB 查看哈希值)

上传于 CPython 3.9 macOS 12.0+ ARM64

diptest-0.8.1-cp38-cp38-win_amd64.whl (420.4 kB 查看哈希值)

上传于 CPython 3.8 Windows x86-64

diptest-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.0 kB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp38-cp38-macosx_12_0_x86_64.whl (417.2 kB 查看哈希值)

上传于 CPython 3.8 macOS 12.0+ x86-64

diptest-0.8.1-cp38-cp38-macosx_12_0_arm64.whl (367.3 kB 查看哈希)

上传于 CPython 3.8 macOS 12.0+ ARM64

由以下机构支持