Metadata-Version: 2.4
Name: spline_basis
Version: 0.2
Author-email: Biprateep Dey <biprateep@pitt.edu>
License: MIT License
        
        Copyright (c) 2023 Biprateep Dey
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Provides-Extra: torch
Requires-Dist: torch; extra == "torch"
Provides-Extra: jax
Requires-Dist: jax; extra == "jax"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: sphinx==6.1.3; extra == "dev"
Requires-Dist: sphinx_rtd_theme==1.2.0; extra == "dev"
Requires-Dist: sphinx-autoapi==2.0.1; extra == "dev"
Requires-Dist: astroid<3; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: nbconvert; extra == "dev"
Requires-Dist: nbsphinx; extra == "dev"
Requires-Dist: ipython; extra == "dev"
Requires-Dist: ipykernel; extra == "dev"
Requires-Dist: matplotlib; extra == "dev"
Requires-Dist: scikit-learn; extra == "dev"
Requires-Dist: numpy; extra == "dev"
Dynamic: license-file

# spline_basis

[![Template](https://img.shields.io/badge/Template-LINCC%20Frameworks%20Python%20Project%20Template-brightgreen)](https://lincc-ppt.readthedocs.io/en/latest/)


A python library to generate spline basis functions. Check out examples in the [notebooks](docs/notebooks/).

### Installation:
From PyPi: `pip install spline-basis`

NumPy is the default backend. To use the splines with PyTorch tensors or JAX arrays, install the optional extras:
`pip install "spline-basis[torch]"`, `pip install "spline-basis[jax]"` (or both: `"spline-basis[torch,jax]"`).

### Backends:
Every class accepts NumPy arrays (or lists), PyTorch tensors and JAX arrays, and returns results on the same backend, dtype and device as its inputs:

```python
import torch
from splinebasis import Isplines, ISplineBasis

isplines = Isplines(order=3, lower=0, upper=1, num_knots=10)
x = torch.linspace(0, 1, 100, requires_grad=True)
values = isplines.evaluate_all(x)  # (100, isplines.n) tensor, differentiable w.r.t. x

basis = ISplineBasis(order=3, num_basis=10, lower=0, upper=1, n_grid=100)
weights = torch.rand(10, requires_grad=True)
curve = basis(weights)  # torch tensor, differentiable w.r.t. weights
```

`ISplineBasis`/`MSplineBasis` compute their basis on the backend of `grid` (NumPy by default; `backend="torch"` or `"jax"` overrides it). JAX evaluation works inside `jax.jit`, `jax.grad` and `jax.vmap`.

Currently supported basis functions:
1. $\mathrm{M}$-Splines: Non-negative spline functions which integrate to 1 over the support of the basis function.
2. $\mathrm{I}$-Splines: Monotone spline functions defined as the integral of M-splines.



**Notes:**
1. The M/I splines are based on [`Ramsay (1988)`](https://www.jstor.org/stable/2245395) and the [`Praat manual`](http://www.fon.hum.uva.nl/praat/manual/spline.html). The API follows the implementation in the [`dms_variants`](https://jbloomlab.github.io/dms_variants/index.html) python package ([`dms_variants` Source Code](https://jbloomlab.github.io/dms_variants/_modules/dms_variants/ispline.html#Isplines)), but the splines are evaluated with a vectorized form of de Boor's recursion, written once for all backends: at each point only the `order` non-zero B-splines are computed, so the cost hardly grows with the number of basis functions.


maintainer: Biprateep Dey
contact: `biprateep@pitt.edu`
