Skip to main content

obsdim

CI PyPI License: AGPL-3.0-or-later

Concentration-based intrinsic dimension of geometric data sets.

obsdim is the maintained, pip-installable reference implementation of the intrinsic dimension ∂F introduced in

  • Tom Hanika, Friedrich Martin Schneider, Gerd Stumme, Intrinsic dimension of geometric data sets, Tohoku Mathematical Journal 74 (2022) 23–52. doi:10.2748/tmj.20201015a (arXiv:1801.07985)
  • Maximilian Stubbemann, Tom Hanika, Friedrich Martin Schneider, Intrinsic Dimension for Large-Scale Geometric Learning, TMLR 2023. (OpenReview, arXiv:2210.05301)

The dimension is defined through the concentration of measure phenomenon (following V. Pestov): a geometric data set is a triple (X, F, μ) of points, a family F of 1-Lipschitz feature functions, and a probability measure μ. Features that concentrate — that fail to discriminate points — signal high intrinsic dimension:

∂(𝒟) = 1 / Δ(𝒟)²,     Δ(𝒟) = ∫₀¹ ObsDiam(𝒟; −α) ∧ 1 dα

where the observable diameter ObsDiam is the largest diameter that any feature's push-forward of μ retains after discarding an α-fraction of mass. Every function/class documents the exact definition, theorem, or algorithm of the papers it implements. Numerical results are cross-validated against the authors' experiment code, ID4GeoL.

Install

pip install obsdim

Hard dependencies: numpy, scipy, scikit-learn. Extras: obsdim[array-api] (PyTorch/CuPy/JAX array support via array-api-compat).

Quickstart

import numpy as np
from obsdim import GeometricID

X = np.random.default_rng(0).normal(size=(500, 16))
est = GeometricID().fit(X)      # scikit-learn conventions, skdim-compatible
est.dimension_                  # the intrinsic dimension ∂_F

The default is the canonical setting of the papers: one-point distance functions d(x, ·) as features, exact O(n²) computation, features normalized by the data diameter for comparability across data sets.

Large-scale data (TMLR 2023 algorithms)

from obsdim import GeometricID, OnePointDistances

est = GeometricID(
    OnePointDistances(anchors=256),   # Monte-Carlo feature sampling
    support_sequence=32,              # TMLR support-sequence approximation
).fit(X)
est.dimension_bounds_        # certified interval for the exact dimension
est.approximation_error_     # relative error bound E(s, 𝒟), TMLR Def. 4.4
# support_sequence=32, exact=True refines to the exact value (TMLR Alg. 2)

The feature family is exchangeable — that's the point

∂F is parametrized by F. The dimension functional only ever sees the value matrix Phi[j, i] = f_j(x_i), so any feature family plugs in:

from obsdim import CustomFeatures, PrecomputedFeatures, UnionFamily

# arbitrary 1-Lipschitz features (constants estimated or declared)
GeometricID(CustomFeatures([f, g, h], lipschitz="estimate")).fit(X)

# features that are not functions of coordinates at all:
# kernel columns, model logits, graph centralities, ...
GeometricID(PrecomputedFeatures(phi), normalize=None).fit(None)

# "distances plus domain knowledge"
GeometricID(UnionFamily([OnePointDistances(), CustomFeatures([f])])).fit(X)

General metric-measure spaces and graphs

The theory lives on mm-spaces, not just ℝⁿ — a precomputed distance matrix is first-class, which is what makes the method apply to graphs:

from obsdim import GeometricID, OnePointDistances
from obsdim.graphs import khop_features, shortest_path_distances

# route 1: any graph metric
D = shortest_path_distances(adjacency)
GeometricID(OnePointDistances(metric="precomputed")).fit(D)

# route 2: k-hop aggregation features of an attributed graph (TMLR Def. 5.1)
GeometricID(khop_features(adjacency, attributes, n_hops=2)).fit(None)

Non-uniform measures are supported everywhere via fit(X, sample_weight=...).

Which normalization, when?

Features of different origins have codomains of different scale, and how you reconcile them decides which geometric data set you measure:

  • Features share one scale (distance functions, any metric input): keep them raw and normalize globally — normalize="diameter", the τ·𝒟 rescaling of Tohoku §6.1.1 and the package default. This is a pure change of units: the mm-space itself is untouched.
  • Tabular columns with incommensurable units (kg vs. €): scale per column at family construction — CoordinateProjections(scale="range"). This computes ∂_F for the sup-metric on min-max-scaled columns and is invariant under per-column affine changes of units. (Use scale="global" when the columns do share units — the TMLR Def. 5.1 / ID4GeoL convention.)
  • Unions of heterogeneous families: scale per member — UnionFamily([...], normalize_members=True) divides each member by its own diameter, keeping each family's internal relative scales while making members commensurable. FeatureScaler(family, per_feature=...) offers both scalings for any family.

Anything other than one global τ changes the induced metric d_F — a feature-engineering choice, not a change of units — so only compare dimensions computed with the same convention. See examples/02_tabular_normalization.py for a demonstration.

Examples

Short, runnable walkthroughs live in examples/: quickstart and large-scale bounds (01), normalization for tabular data (02), metric spaces and graphs (03), exchangeable feature families (04).

  • scikit-dimension — hub of classical ID estimators (MLE, TwoNN, DANCo, …) with the same fit(X).dimension_ interface; obsdim estimators drop into its benchmark scripts.
  • ID4GeoL — the original experiment code for the TMLR paper (this package's test suite reproduces its results).
  • Hille, Stubbemann, Hanika, Reproducibility and Geometric Intrinsic Dimensionality (TMLR 2024) — feature selection with this dimension, a downstream use case.

Development

pip install -e .[dev]
pytest
ruff check src tests

The test suite verifies the implementation against exact values derived from the papers (e.g. the nominal scale has dimension exactly n⁴, the contranominal scale converges to 64/9 — Tohoku §6.2.2), against brute-force subset enumeration of the defining formula, and against ID4GeoL.

License

AGPL-3.0-or-later.

Metadata

Release files for obsdim 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for obsdim 0.1.0
File Size Uploaded Provenance Actions
obsdim-0.1.0.tar.gz 47.0 kB With provenance Details for obsdim-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for obsdim 0.1.0
File Interpreter ABI Platform Actions
obsdim-0.1.0-py3-none-any.whl Python 3 none any Details for obsdim-0.1.0-py3-none-any.whl

Total release size: 82.0 kB

Release files / obsdim-0.1.0.tar.gz

Download URL obsdim-0.1.0.tar.gz
Size 47.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eef6eeccbe843709a4dfb8be9c000248b7aa4b44b344642e274ef972750ef4b5
BLAKE2b-256 checksum
How to use checksums
fba12708fa2ffe716d72cb9b80e174f1ea5233ffe0efdea12b4d026131eaaaac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

Release files / obsdim-0.1.0-py3-none-any.whl

Download URL obsdim-0.1.0-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
462af34bb3c940b2bcc29de2b4679e3640d322dadfc6d0fa24c9b5e798602350
BLAKE2b-256 checksum
How to use checksums
f2c8de8f16d508a16a664b2e7a7f25fb580b3ca8b407fa3de14b5a24c55c6701
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

Security for obsdim 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for obsdim-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page