Skip to main content

Compute the Hopkins statistic to assess clustering tendency.

Project description

hopkins-statistic

CI PyPI - Version PyPI - Python Version Docs

hopkins-statistic is a library for computing the Hopkins statistic to test for departure from complete spatial randomness (CSR), i.e., the presence of clustering or regularity in point patterns.

This implementation defaults to the formulation of Cross and Jain (1982), raising distances to the power of the data dimension. In two dimensions this is equivalent to the original definition by Hopkins and Skellam (1954) and, under the CSR null hypothesis, the statistic has a Beta distribution, so p-values can be computed analytically.

Installation

pip install hopkins-statistic

Usage

import numpy as np
from hopkins_statistic import hopkins

rng = np.random.default_rng(42)

# Simple clustered example: two Gaussian blobs
centers = np.array([[0, 0], [0, 1]])
labels = rng.integers(len(centers), size=100)
X = centers[labels] + rng.normal(scale=0.1, size=(100, 2))

statistic = hopkins(X, rng=rng)
print(f"{statistic:.3f}")
#> 0.771

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hopkins_statistic-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hopkins_statistic-0.2.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file hopkins_statistic-0.2.0.tar.gz.

File metadata

  • Download URL: hopkins_statistic-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hopkins_statistic-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3a51e3f33804d9923f94ba164978f86028796151a6f0882478e19bc171a1caa1
MD5 eb92d23a9dd5e1319229e227703cbc8d
BLAKE2b-256 2d05172dcc2ef1e78bc927dc83c1af2056ca08f044cba3c45ec8428fa270f015

See more details on using hashes here.

File details

Details for the file hopkins_statistic-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: hopkins_statistic-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hopkins_statistic-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 561523054e4b156c34f343f7551e56a14dd48ffb387815e2ee185b93aba6c42d
MD5 aaf10c36ec9d2f4a00dbf26e3a4d993c
BLAKE2b-256 3eaf680a7357a3fa03cf58cd6e3fa4a7224a4c1a713317d80fe01672f6689448

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page