Radial Basis Function Interpolation in PyTorch
Project description
torchrbf: Radial Basis Function Interpolation in PyTorch
This is a PyTorch module for Radial Basis Function (RBF) Interpolation, which is translated from SciPy's implemenation. This implementation benefits from GPU acceleration, making it significantly faster and more suitable for larger interpolation problems.
Installation
pip install torchrbf
The only dependencies are PyTorch and NumPy. If you want to run the tests and benchmarks, you also need SciPy installed.
A note on numerical precision
If you are using TF32, you may experience numerical precision issues. TF32 is enabled by default in PyTorch versions 1.7 to 1.11 (see here). To disable it, you can use
torch.backends.cuda.matmul.allow_tf32 = False
torchrbf will issue a warning if TF32 is enabled.
Usage
Here is a simple example for interpolating 3D data in a 2D domain:
import torch
import matplotlib.pyplot as plt
from torchrbf import RBFInterpolator
y = torch.rand(100, 2) # Data coordinates
d = torch.rand(100, 3) # Data vectors at each point
interpolator = RBFInterpolator(y, d, smoothing=1.0, kernel='thin_plate_spline')
# Query coordinates (100x100 grid of points)
x = torch.linspace(0, 1, 100)
y = torch.linspace(0, 1, 100)
grid_points = torch.meshgrid(x, y, indexing='ij')
grid_points = torch.stack(grid_points, dim=-1).reshape(-1, 2)
# Query RBF on grid points
interp_vals = interpolator(grid_points)
# Plot the interpolated values in 2D
plt.scatter(grid_points[:, 0], grid_points[:, 1], c=interp_vals[:, 0])
plt.title('Interpolated values in 2D')
plt.show()
Performance versus SciPy
Since the module is implemented in PyTorch, it benefits from GPU acceleration. For larger interpolation problems, torchrbf is significantly faster than SciPy's implementation (+100x faster on a RTX 3090):
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
File details
Details for the file torchrbf-0.0.1.tar.gz
.
File metadata
- Download URL: torchrbf-0.0.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 591a9de6f6beb0e14024328c034417739a7fee6056e648ce374b910f50c47db3 |
|
MD5 | 768f06ce0e70e1f8dad6b04556ef26d7 |
|
BLAKE2b-256 | 9805223f2037d4fa84f9471343334586912b0f92f43ef835dd3376fc6b682ec7 |
File details
Details for the file torchrbf-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: torchrbf-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03dba76c92df073d6bc785fb8353602fbd4a7aad64cc27197f89485e970b26a8 |
|
MD5 | a7aa99e1fcf3691dff1cfaa184c592c3 |
|
BLAKE2b-256 | 971c1d34324b9b7d88971c5e2c20960d14f06e56889fa4258502b259f1e209b4 |