PyTorch distributions on the Clifford torus (S^1)^d for HRR/VSA-compatible latent spaces
Project description
clifford-torus
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). Sampling on it (rather than on S^(d-1) directly) guarantees every
non-DC Fourier coefficient of the resulting vector has unit magnitude, i.e. the sample is
"unitary" w.r.t FHRR/HRR/SSPs (thus vectors are exactly invertible under circular-convolution binding). 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}
}
Optional memory optimizations can be implemented following this post.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clifford_torus-0.1.0.tar.gz.
File metadata
- Download URL: clifford_torus-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b71a97cd8c7b3581f47bda81265b8ea2c8969fafb12e7e14beb3efcae8407903
|
|
| MD5 |
081fd06dffff5ea4b50dc7ba4c52ae3a
|
|
| BLAKE2b-256 |
a372fdcfb7370d5fdbb335c8937b1568b4674b7bc1c8d53f13d037421a35f8ab
|
File details
Details for the file clifford_torus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clifford_torus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0ba90597db0593c08d8424a5eb1887ba5d6e1825d5ab795d33fa42b6eb400f
|
|
| MD5 |
14f8f2a547cfe78e3b9562b6a792d404
|
|
| BLAKE2b-256 |
26aaa6557ec9b5de97bbb06b28980f1c6f35a33067999e3b673dbc4d992cbf3e
|