Skip to main content

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

python -m pip install MultiVariateSpline

Install the current GitHub development version directly with:

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

rng = np.random.default_rng(0)
x0 = rng.uniform(0.0, 1.0, 500)
x1 = rng.uniform(-1.0, 1.0, 500)
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multivariatespline-0.1.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

multivariatespline-0.1.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file multivariatespline-0.1.1.tar.gz.

File metadata

  • Download URL: multivariatespline-0.1.1.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

Hashes for multivariatespline-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c940d3385a7ba8e71d8cf42fcd12ada5b9c4e3767deda78ee15615493d877d0a
MD5 699c0f1c7ca5c2327f9f84adbfaee2d3
BLAKE2b-256 41bc08b0b354aa1f3dd10b5a331f6479ae9ff7ce7127fa9f8f9b4a0c9e59e2f2

See more details on using hashes here.

File details

Details for the file multivariatespline-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for multivariatespline-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 51054b280feae13aa8272605f73f4e4304c4b2efab0600cc9aca9d19c5a95d3e
MD5 a184859aa220befe5d3489ef6d708d39
BLAKE2b-256 11e0bc11fd6dc8856e021832abba64da02a25331ecf8be011e569d9576374690

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