Skip to main content

PyTorch distributions on the Clifford torus (S^1)^d for HRR/VSA-compatible latent spaces

Project description

Clifford Torus distribution

A PyTorch implementation of distributions on the Clifford torus (S^1)^d, as used by Clifford-VAE [1] to learn Holographic Reduced Representation (HRR) / Vector Symbolic Algebra-compatible latent spaces.

This distribution samples points on the Clifford torus (S^1)^d ⊂ R^(2d). This package also includes the PowerSpherical and HypersphericalUniform distributions (adapted from nicola-decao/power_spherical [2]), since the Clifford torus's per-circle concentration can be parameterized with either a von Mises or a Power Spherical distribution.

Dependencies

  • python >= 3.9
  • torch >= 1.10

Installation

pip install clifford-torus

or from source:

git clone https://github.com/momalekabid/clifford-torus
cd clifford-torus
pip install .

Structure

  • clifford_torus/distributions.py: PowerSpherical, HypersphericalUniform, CliffordTorusUniform, CliffordTorusDistribution (von Mises concentration), CliffordPowerSphericalDistribution (Power Spherical concentration).

Usage

Differentiable sampling on a d-dimensional Clifford torus, returned as a real vector of length 2d whose non-DC Fourier coefficients all have unit magnitude:

import torch
from clifford_torus import CliffordPowerSphericalDistribution, CliffordTorusUniform

d = 8
loc = torch.zeros(d, requires_grad=True)          # per-circle mean angle
concentration = torch.full((d,), 4.0, requires_grad=True)

q = CliffordPowerSphericalDistribution(loc, concentration)
z = q.rsample()               # shape (2*d,), unit-magnitude fourier coefficients
z.sum().backward()

KL divergence against the uniform prior on the torus:

p = CliffordTorusUniform(dim=d)
torch.distributions.kl_divergence(q, p)

z from a CliffordPowerSphericalDistribution/CliffordTorusDistribution is directly usable in an HRR/VSA: bind two codes with circular convolution (torch.fft.ifft(torch.fft.fft(a) * torch.fft.fft(b)).real), and unbind with the exact inverse since every Fourier coefficient has unit magnitude.

references

@article{abid2026clifford,
  title={Learning Holographic Reduced Representations with Clifford Variational Autoencoders},
  author={Abid, Mohamed Malek and Furlong, P. Michael},
  year={2026}
}

for the underlying PowerSpherical distribution we use:

@article{decao2020power,
  title={The Power Spherical distribution},
  author={De Cao, Nicola and Aziz, Wilker},
  journal={Proceedings of the 37th International Conference on Machine Learning, INNF+},
  year={2020}
}

Some optional memory optimizations implemented following this post.

Visualization

Stereographic projection of points on the Clifford torus

Stereographic projection of spheres centered at points on the Clifford torus inside the 3-sphere, rotated in the zw-plane and projected down to R^3. From Clayton Shonkwiler's Wolfram Community post, "[GIF] Inside (Stereographic projection of points on the Clifford torus)".

@misc{shonkwiler2017inside,
  title={[GIF] Inside (Stereographic projection of points on the Clifford torus)},
  author={Shonkwiler, Clayton},
  howpublished={Wolfram Community},
  year={2017},
  url={https://community.wolfram.com/groups/-/m/t/1245707}
}

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

clifford_torus-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

clifford_torus-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file clifford_torus-0.1.1.tar.gz.

File metadata

  • Download URL: clifford_torus-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for clifford_torus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f2170063179e19f53b6e20462c28d6e43787bb2a3a7188ea16070a56828f9ff9
MD5 d6d931d11ac0033b0016aa0eda5d11b9
BLAKE2b-256 3b0a4575b64bba8af6a2fde7cf7931f792d7eae297a6fa455bc1ef74640ed31c

See more details on using hashes here.

File details

Details for the file clifford_torus-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for clifford_torus-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dabb2017af18cd6ee33ffb5e382c4174f36a81c90890e28bfd03e1f4a01ee42c
MD5 c8be334f93f5615d11b23034d3970ebb
BLAKE2b-256 b87bae4b6df222552540c8343251561a7a57809e0fe073d999c19321e8148c1a

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