Weighted least-squares tensor-product splines in N dimensions.
Project description
MultiVariateSpline
MultiVariateSpline fits weighted least-squares tensor-product B-splines to
scattered or gridded data in one or more dimensions.
This standalone package contains the complete experimental implementation, including automatic knot placement, weighted fitting, sparse fitting, derivatives, gridded input, pairwise and grid evaluation, and an optional coefficient-smoothing penalty. The smaller implementation proposed for SciPy is being reviewed separately in scipy/scipy#25472.
Installation
After the package has been uploaded to PyPI:
python -m pip install MultiVariateSpline
Until then, install the current GitHub version directly:
python -m pip install \
"git+https://github.com/nikolasvalsamidis97/LSQMultivariateSpline.git"
For local development, run this from the repository root:
python -m pip install -e ".[test]"
NumPy and SciPy are installed automatically as package dependencies.
Fit In One Call
The constructor validates the data, creates the tensor-product basis, solves for the coefficients, and returns an evaluable spline:
import numpy as np
from multivariatespline import LSQMultivariateSpline
x0 = np.linspace(0.0, 1.0, 80)
x1 = np.linspace(-1.0, 1.0, 80)
x = np.column_stack((x0, x1))
y = np.sin(2.0 * np.pi * x0) + 0.5 * x1
spline = LSQMultivariateSpline(
x,
y,
t=[6, 6],
k=(3, 3),
sparse=True,
)
Each integer in t is the requested number of polynomial pieces in that
dimension. Explicit interior-knot arrays can be passed instead.
The previous import path remains supported:
from lsq_multivariate_spline import LSQMultivariateSpline
Evaluate The Fit
Evaluate scattered or pairwise coordinates:
points = np.array([[0.25, -0.5], [0.75, 0.5]])
values = spline(points)
x0_eval = np.array([0.25, 0.75])
x1_eval = np.array([-0.5, 0.5])
pairwise_values = spline(x0_eval, x1_eval, grid=False)
Evaluate every combination of coordinate values for a surface or volume:
surface = spline(x0_eval, x1_eval, grid=True)
Fit Gridded Data
When observations already form a complete tensor grid, use from_grid:
r = np.linspace(-1.0, 1.0, 30)
w = np.linspace(0.0, 2.0, 40)
rr, ww = np.meshgrid(r, w, indexing="ij")
psf = rr**2 - ww**2
spline = LSQMultivariateSpline.from_grid(
(r, w),
psf,
t=[8, 8],
k=3,
sparse=True,
)
Development Status
This is an alpha research package. Validate knot choices and residuals for each scientific use case, especially in sparsely sampled regions. Unsupported basis functions raise an error by default.
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 multivariatespline-0.1.0.tar.gz.
File metadata
- Download URL: multivariatespline-0.1.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36c329cbb84ae4e8f1c51024c6ae189b79430f99684de84cf81164412317dd83
|
|
| MD5 |
a99e15b69da4da7999209bf179949ad8
|
|
| BLAKE2b-256 |
4f24b89f22b3e62bb7c38514086db5d9be3978151426304bfd0d608a075293a4
|
File details
Details for the file multivariatespline-0.1.0-py3-none-any.whl.
File metadata
- Download URL: multivariatespline-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f065aec43b6fe743c20309e11b1f49301b034935b67af816c1e9236dd9b07ca3
|
|
| MD5 |
a4f469eb653c42ef1424b941b9b329a2
|
|
| BLAKE2b-256 |
e2ca52715480c9f99c7a2882a3adb8458d283786c0b90382bf3e532af46a0ae7
|