Skip to main content

A package for spherical positional encoding

Project description

Spherical-Implicit-Neural-Representation

Documentation Status

Spherical-Implicit-Neural-Representation is a Python package for constructing spherical implicit neural representations using Herglotz-based positional encoding. It provides flexible modules for processing spherical data along with customizable positional encoding layers and regularization tools.

Installation

Install the package from PyPI:

pip install spherical-inr

Or install the development version locally:

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

Getting Started

Instantiate HerglotzNet

The HerglotzNet module is designed for (θ, φ) coordinate data. Here’s an example of how to instantiate and use it:

import torch
import spherical_inr as sph

# Parameters for HerglotzNet
output_dim = 1
inr_sizes = [16] + 3 * [32]  # [PE size] + (hidden layers * hidden features)
omega0 = 1.0
seed = 42


# Instantiate the network NOTE : # HNET is defined for (θ, φ) coordinates only
model = sph.HerglotzNet(
    output_dim=output_dim,
    inr_sizes=inr_sizes,
    bias=True,
    pe_omega0=omega0,
    seed=seed
)

# Example
dummy_input = torch.randn(4, 2)
output = model(dummy_input)
print(output)

Generic Cartesian INR

You can also create a customized Cartesian implicit neural representation (INR). For example:

import torch
import spherical_inr as sph

# INR parameters
input_dim = 3
output_dim = 1
inr_sizes = [100] + 3 * [100]
pe = "fourier"
activation = "sin"
bias = False

# Instantiate a generic Cartesian INR
inr = sph.INR(
    input_dim=input_dim,
    output_dim=output_dim,
    inr_sizes=inr_sizes,
    pe=pe,
    activation=activation,
    bias=bias
)

To incorporate Laplacian regularization into your loss function:

import torch
from spherical_inr.loss import CartesianLaplacianLoss

laplacian_loss = CartesianLaplacianLoss()
mse_loss = torch.nn.MSELoss()

def loss_fn(target, y_pred, y_reg, x_reg):
    reg = laplacian_loss(y_reg, x_reg)
    mse = mse_loss(target, y_pred)
    return reg + mse

Then train your model as usual.

Instantiate and Use a Positional Encoding

You can also directly instantiate a positional encoding module and integrate it into your own PyTorch model. For example:

import torch
import torch.nn as nn
import spherical_inr as sph

# Example model using a positional encoding
class MyModel(nn.Module):
    def __init__(self, num_atoms, input_dim, output_dim, bias, omega0, seed):
        super().__init__()
        self.pe = sph.RegularHerglotzPE(
            num_atoms=num_atoms,
            input_dim=input_dim,
            bias=bias,
            omega0=omega0,
            seed=seed
        )
        self.linear = nn.Linear(num_atoms, output_dim)
        
    def forward(self, x):
        x = self.pe(x)
        return self.linear(x)

# Instantiate the model
model = MyModel(
    num_atoms=50,
    input_dim=10,
    output_dim=5,
    bias=True,
    omega0=1.0,
    seed=42,
)

dummy_input = torch.randn(4, 10)
output = model(dummy_input)
print(output)

📚 References

  1. Théo Hanon, Nicolas Mil-Homens Cavaco, John Kiely, Laurent Jacques,
    Herglotz-NET: Implicit Neural Representation of Spherical Data with Harmonic Positional Encoding,
    arXiv preprint, 2025.
    arXiv:2502.13777

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.3.12.tar.gz (17.6 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.3.12-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spherical_inr-0.3.12.tar.gz
  • Upload date:
  • Size: 17.6 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.3.12.tar.gz
Algorithm Hash digest
SHA256 2f75520ef1d43e21d9bc8fd626704dd37d0d2d5859c77835d2b1d09c3ea03b5a
MD5 1e1b9bbab0322e7e2ff84a23b2a5d38a
BLAKE2b-256 8420bf3ac250e7f775aa69c063e19fc8421f417d7b7b42473f3af6e0b537e4ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spherical_inr-0.3.12-py3-none-any.whl
  • Upload date:
  • Size: 19.5 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.3.12-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee87dfe10cbfc2c909f2031feac9bda94af09c7bf9fac603b8e5f176c581632
MD5 a0362aa7f7d6bd55cbe2ed0807a69026
BLAKE2b-256 44542d9ea63e1606865d6cf4e6211f7c622dfc27f0631fd3acd305025060ff84

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