Skip to main content

A package for spherical positional encoding

Project description

Spherical-Implicit-Neural-Representation

Project Overview

Documentation Status

Spherical-Implicit-Neural-Representation unifies Fourier features (SIREN) [1], pure Spherical Harmonics (SphericalSirenNet) [3], and our learnable Herglotz‐map encodings [2] into a single PyTorch toolbox. Build implicit neural representations on:

  • (HerglotzNet, SphericalSirenNet)
  • Volumetric data in ℝ³ with radial basis (solid harmonics)
  • Generic ℝᵈ inputs via FourierPE, HerglotzPE

Coordinate conventions:

  • Angles: θ∈[0,π], φ∈[0,2π) in radians.
  • Full spherical: (r≥0, θ, φ).
  • 2D polar: (r,θ) or angle-only (θ).

📦 Installation

pip install spherical-inr

OR for development:

git clone https://github.com/yourusername/spherical_inr.git
cd spherical_inr
pip install -e .

📦 Features

  • General INR (INR): Plug-and-play Cartesian implicit networks with your choice of
    Fourier / Herglotz / Spherical-Harmonic features + flexible MLP backbones.
  • Sphere-only nets (HerglotzNet, SphericalSirenNet): For data on (S^2), encode ((\theta,\phi)) directly.
  • Solid-harmonic nets (RegularSolid* / IrregularSolid*): Capture radial & angular variation in (\mathbb R^3).
  • SIREN-style variants (SirenNet, HerglotzSirenNet): Learnable Fourier / Herglotz features + sine-activated MLPs.
  • Standalone PEs: FourierPE, HerglotzPE, SphericalHarmonicsPE, RegularSolidHarmonicsPE, IrregularSolidHarmonicsPE, …
  • Transforms: Handy spherical↔cartesian converters (tp_to_r3, rtp_to_r3, rt_to_r2, t_to_r2, …).
  • Regularization: Laplacian losses for smoothness (CartesianLaplacianLoss, SphericalLaplacianLoss, …).
  • Differentation : Cartesian & Spherical Differential Operators (spherical_gradient, spherical_laplacian, spherical_divergence, cartesian_gradient, ...).

🚀 Quickstart

1️⃣ HerglotzNet on S²

import torch
from spherical_inr import HerglotzNet

# Create a HerglotzNet: harmonic order L → num_atoms=(L+1)**2
model = HerglotzNet(
    L=3,                # spherical-harmonic degree
    mlp_sizes=[64,64],  # two hidden layers of width 64
    output_dim=1,       # scalar output per direction
    seed=0,
)
# Random spherical angles (θ,φ)
x = torch.rand(16,2) * torch.tensor([torch.pi, 2*torch.pi])
y = model(x)
print(y.shape)  # → (16,1)

2️⃣ Generic Cartesian INR

from spherical_inr import INR

# Fourier‐feature INR with sin‐activation (SIREN style)
inr = INR(
    num_atoms=128,          # Fourier channels
    mlp_sizes=[256,256],    # two hidden layers
    output_dim=3,           # 3D output
    input_dim=3,            # 3D Cartesian inputs
    pe="fourier",         # FourierPE
    activation="sin",      # sine‐activated MLP
    pe_kwargs={"omega0":10},
)
x = torch.randn(10,3)
y = inr(x)

3️⃣ Solid‐harmonic INR in ℝ³

from spherical_inr import RegularSolidHarmonicsPE, SineMLP
import torch

# Regular solid harmonics encode radial+angular growth r^ℓ
pe = RegularSolidHarmonicsPE(L=2, seed=1)
mlp = SineMLP(input_features=pe.num_atoms, output_features=1, hidden_sizes=[64])
# Example input: (r,θ,φ)
x_sph = torch.stack([torch.rand(5), torch.rand(5)*torch.pi, torch.rand(5)*2*torch.pi], dim=-1)
x_cart = rtp_to_r3(x_sph)
x = pe(x_cart)
y = mlp(x)

📚 References

  1. Sitzmann, M., Martel, J., Berg, R., Lindell, D. B., & Wetzstein, G. (2021). Implicit Neural Representations with Periodic Activation Functions (SIREN). Advances in Neural Information Processing Systems (NeurIPS). https://arxiv.org/abs/2006.09661
  2. Hanon, T., et al. (2025). Herglotz-NET: Implicit Neural Representation of Spherical Data with Harmonic Positional Encoding. arXiv preprint arXiv:2502.13777. https://arxiv.org/abs/2502.13777
  3. Rußwurm, M., Klemmer, K., Rolf, E., Zbinden, R., & Tuia, D. (2024). Geographic Location Encoding with Spherical Harmonics and Sinusoidal Representation Networks. arXiv preprint arXiv:2310.06743. https://arxiv.org/abs/2310.06743

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

spherical_inr-0.4.1.tar.gz (71.8 kB view details)

Uploaded Source

Built Distribution

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

spherical_inr-0.4.1-py3-none-any.whl (72.4 kB view details)

Uploaded Python 3

File details

Details for the file spherical_inr-0.4.1.tar.gz.

File metadata

  • Download URL: spherical_inr-0.4.1.tar.gz
  • Upload date:
  • Size: 71.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spherical_inr-0.4.1.tar.gz
Algorithm Hash digest
SHA256 602dec5475381dbef10306a10e0a70f2600a456604c0bb1f9d09aa6877ae1097
MD5 bd3a3df5ad53087b2654510ebdcd8f87
BLAKE2b-256 6844e961fcc1f45d6744b33ee5e34e178cd4c357d0cdb61cb7d0ba24e0c93b59

See more details on using hashes here.

File details

Details for the file spherical_inr-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: spherical_inr-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 72.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spherical_inr-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8db7d937f696f14c757bb6b26afc9f88906034d0500b9b859d5c2615a604dc10
MD5 739d2856602e234547399c95d14a2a32
BLAKE2b-256 dcd2cf5a7d016ac76195677b89d142f91fb63aecd5ae3d9d3f8b80e7c972af48

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