Skip to main content

Compute the Hopkins statistic to assess clustering tendency.

Project description

hopkins-statistic

CI Coverage PyPI - Version PyPI - Python Version Docs DOI

hopkins-statistic is a library for computing the Hopkins statistic to assess clustering tendency (also known as clusterability) by testing for departure from complete spatial randomness (CSR) in point patterns.

This implementation defaults to the Cross and Jain (1982) formulation, raising distances to the power of the data dimension. In two dimensions, this matches the original definition by Hopkins and Skellam (1954). Because the resulting statistic follows a beta distribution under the null hypothesis, 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.3.1.tar.gz (6.1 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.3.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hopkins_statistic-0.3.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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.3.1.tar.gz
Algorithm Hash digest
SHA256 5e37d2ccb9a2e315bc2afde8b0fe982addc3bc5f5f7758a009d49850a6481f49
MD5 299c48aa060f02959dbbf289788ad4f1
BLAKE2b-256 cf051c95cce6003bdc8e7d7a2728a454fae57f2db20fd3cf9d96428d61ad2185

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopkins_statistic-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a199717620f5acbce6c8a28d46cfb10fa00efd66c38f6d65470ec2b3867df0c1
MD5 fd7cd576e9fbf57638b7e19ffb7dfaa3
BLAKE2b-256 48e0ccbaaa883bcc1d28238890f75594a9a38fed0ee144bece65f645c161eb0c

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