Skip to main content

Bispectrum analysis for machine learning

Project description

bispectrum_logo

bispectrum

Tests Pre-commit codecov

An open-source, fully unit-tested PyTorch library that implements selective G-bispectra for seven group actions as differentiable torch.nn.Modules, ready to plug into ML pipelines and deep learning architectures.

The G-bispectrum is a principled complete invariant of a signal — it retains all information up to the group action. Selectivity reduces cost from O(|G|²) to O(|G|) for finite groups, and from O(L³) to Θ(L²) coefficients for SO(3) on S².

Supported Groups

Module Group / Domain Output mode Complexity (selective)
CnonCn C_n on C_n selective + full O(n)
SO2onS1 SO(2) on S¹ selective + full O(n)
TorusOnTorus T^d selective + full O(n)
DnonDn D_n on D_n selective O(n)
SO2onDisk SO(2) on disk selective O(L)
SO3onS2 SO(3) on S² selective + full Θ(L²)
OctaonOcta chiral octahedral O (24 elements) selective 172 coefficients

SO2onS1 is the continuous-n limit of CnonCn and shares its implementation.

API

Every module exposes a uniform interface:

  • forward(f) — selective (default) or full bispectral invariants
  • fourier(f) — group Fourier coefficients
  • invert(beta) — signal reconstruction up to group-action indeterminacy (where available)

Modules default to O(|G|) selective coefficients; pass selective=False for the full O(|G|²) set. CG matrices, DFT kernels, and Bessel roots are precomputed as non-learnable buffers. Dependencies: PyTorch, NumPy, and torch_harmonics (for SO3onS2).

Benchmarks

Median wall-clock on a single NVIDIA H100 80 GB GPU (batch=16, torch.utils.benchmark):

Module Group |G| / L_max Coefs (sel.) Coefs (full) Fwd sel. (ms) Fwd full (ms)
CnonCn C_128 128 128 8,256 0.14 8.53
TorusOnTorus C_32 × C_32 1,024 1,024 524,800 0.07 0.31
DnonDn D_32 64 245 0.57
SO2onDisk SO(2) L=16 105 0.22
SO3onS2 SO(3) L=16 430 0.48
OctaonOcta O 24 172 0.68

Installation

pip install bispectrum

Or with uv:

uv pip install bispectrum

Development

git clone https://github.com/geometric-intelligence/bispectrum.git
cd bispectrum
uv pip install -e ".[dev]"
pre-commit install

Pre-commit Hooks

This project uses pre-commit for code quality checks. After installing dev dependencies, the hooks run automatically on each commit.

# Run hooks on all files (useful for first-time setup or CI)
pre-commit run --all-files

# Run a specific hook
pre-commit run ruff --all-files

# Update hooks to latest versions
pre-commit autoupdate

Usage

Cyclic group on itself

from bispectrum import CnonCn

bsp = CnonCn(n=8)
f = torch.randn(4, 8)       # signal on Z/8Z
beta = bsp(f)                # shape (4, 8), complex64
f_rec = bsp.invert(beta)     # reconstructed up to cyclic shift

SO(3) on the 2-sphere

from bispectrum import SO3onS2

# Selective bispectrum: O(L²) entries with generic completeness
bsp = SO3onS2(lmax=5, nlat=64, nlon=128, selective=True)
f = torch.randn(1, 64, 128)  # signal on S²
beta = bsp(f)                 # shape (1, 35), complex64

# Full bispectrum: O(L³) entries
bsp_full = SO3onS2(lmax=5, nlat=64, nlon=128, selective=False)
beta_full = bsp_full(f)       # shape (1, 69), complex64

Octahedral group

from bispectrum import OctaonOcta

bsp = OctaonOcta()
f = torch.randn(4, 24)       # signal on O (|O| = 24)
beta = bsp(f)                 # shape (4, 172), complex64
f_rec = bsp.invert(beta)      # reconstructed up to group action

License

MIT

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

bispectrum-0.3.6.tar.gz (47.9 kB view details)

Uploaded Source

Built Distribution

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

bispectrum-0.3.6-py3-none-any.whl (54.3 kB view details)

Uploaded Python 3

File details

Details for the file bispectrum-0.3.6.tar.gz.

File metadata

  • Download URL: bispectrum-0.3.6.tar.gz
  • Upload date:
  • Size: 47.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bispectrum-0.3.6.tar.gz
Algorithm Hash digest
SHA256 6fd71da60efbfe6a94b9f7a9a4575b4893417302270a62b3233b7112a2cfb2b3
MD5 be91d71e68d1e48917979a5acf6f2905
BLAKE2b-256 f102c6ad54109b43827e028077034e054326a2ac9c0a4089c34aa40dfe85fe99

See more details on using hashes here.

Provenance

The following attestation bundles were made for bispectrum-0.3.6.tar.gz:

Publisher: publish.yml on geometric-intelligence/bispectrum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bispectrum-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: bispectrum-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 54.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bispectrum-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 aec43bc893acf11d4ece69e36a686a31d0826738ff8ff32b56c8f16aa69c2d88
MD5 b2a87639de76fe87ee99003e9b696426
BLAKE2b-256 0cd93792c636a76d9f7dafdba7194e36926bfa08156fc232864a590829a8fbd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bispectrum-0.3.6-py3-none-any.whl:

Publisher: publish.yml on geometric-intelligence/bispectrum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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