Metadata-Version: 2.4
Name: multivariatespline
Version: 0.1.0
Summary: Weighted least-squares tensor-product splines in N dimensions.
Author-email: Nikolas Valsamidis <nv222dv@student.lnu.se>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/nikolasvalsamidis97/LSQMultivariateSpline
Project-URL: Documentation, https://github.com/nikolasvalsamidis97/LSQMultivariateSpline
Project-URL: Issues, https://github.com/nikolasvalsamidis97/LSQMultivariateSpline/issues
Project-URL: SciPy tracker, https://github.com/scipy/scipy/pull/25472
Keywords: b-spline,interpolation,least-squares,multivariate,scipy
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.23.5
Requires-Dist: scipy>=1.10
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Provides-Extra: docs
Requires-Dist: sphinx>=7; extra == "docs"
Provides-Extra: dev
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: sphinx>=7; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Dynamic: license-file

# 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](https://github.com/scipy/scipy/pull/25472).

## Installation

After the package has been uploaded to PyPI:

```bash
python -m pip install MultiVariateSpline
```

Until then, install the current GitHub version directly:

```bash
python -m pip install \
  "git+https://github.com/nikolasvalsamidis97/LSQMultivariateSpline.git"
```

For local development, run this from the repository root:

```bash
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:

```python
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:

```python
from lsq_multivariate_spline import LSQMultivariateSpline
```

## Evaluate The Fit

Evaluate scattered or pairwise coordinates:

```python
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:

```python
surface = spline(x0_eval, x1_eval, grid=True)
```

## Fit Gridded Data

When observations already form a complete tensor grid, use `from_grid`:

```python
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.
