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.2.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.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clifford_torus-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 13bf42009e94303488ce8e2a00f3099705e6ca8916219f7e675c047cd0ddb43b
MD5 c61a1f353b939ffe0692d829c1360efa
BLAKE2b-256 b9cf1562bb5a303916eed31a0a8e08b5d47473e97d728636f780e2f39f668e1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clifford_torus-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a8a148cc7c15ca21c10154fc5defd6809974e4dc3359c73ea49ef238edf95839
MD5 6c465dcf67c0b90fc98f6fe5461f8d02
BLAKE2b-256 7a6d89c2e949e9900df9e6ace8dd12c24dc2edfff9feb8b14c80d122239c8c84

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