Skip to main content

Smoothcon - Construct basis and penalty matrices in JAX

pre-commit pytest doctest coverage

smoothcon constructs JAX-native basis matrices and quadratic penalties for smooth terms. It is a standalone numerical library: arrays and construction parameters go in, and an immutable Smooth comes out.

Installation

smoothcon requires Python 3.13 or 3.14.

pip install smoothcon

With uv:

uv add smoothcon

Quick start

import jax.numpy as jnp
import smoothcon

x = jnp.linspace(0.0, 1.0, 100)
smooth = smoothcon.pspline(x, k=20, degree=3, penalty_order=2)

basis = smooth.basis(x)
penalty = smooth.penalty

The Smooth object

smooth.basis(values) evaluates the design matrix, smooth.penalty contains the coefficient penalty, smooth.rank records its numerical rank, and smooth.knots retains knot or center locations when applicable.

Smooth.basis supports jax.jit and finite first-order autodiff almost everywhere for continuous smooth families. Exact derivatives at nonsmooth knot or boundary locations and higher-order derivatives are not guaranteed. MRF bases are discrete and excluded from the autodiff contract.

Smooth families

  • P-splines, integrated-derivative B-splines, and cyclic P-splines: pspline, bspline, and cyclic_pspline
  • cubic regression and cyclic cubic regression splines: cubic_regression and cyclic_cubic
  • thin-plate regression splines: thin_plate
  • fixed-range Gaussian-process smooths: gaussian_process
  • Markov random fields: mrf

Transformations

Transformations return new Smooth objects and can be composed explicitly:

nonlinear = (
    smooth.constrain("constant_and_linear", values=x)
    .scale_penalty(values=x)
    .diagonalize_penalty(values=x)
)

Available constraints are evaluated-term sum-to-zero, coefficient sum-to-zero, constant-and-linear trend removal, and arbitrary matrices A representing A @ coefficients == 0.

Documentation

The documentation includes the complete API reference and notes on deviations from mgcv. To inspect it locally:

uv run zensical serve

Development

uv sync --all-groups
uv run pytest
uv run ruff check .
uv run ty check
uv run mypy
uv run zensical build --clean --strict

Normal tests do not require R. See tests/mgcv_reference/README.md for manual oracle regeneration.

Provenance and license

The numerical constructors include Python/JAX adaptations of algorithms from Simon N. Wood's GPL-licensed mgcv, pinned for development and regression testing to mgcv 1.9-4 at commit 1b6a4c8374612da27e36420b4459e93acb183f2d.

smoothcon is licensed under GPL-3.0-or-later. See THIRD_PARTY_NOTICES.md for source provenance, copyright notices, and academic citations.

Download files

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

Source Distribution

smoothcon-0.3.0.tar.gz (152.1 kB view details)

Uploaded Source

Built Distribution

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

smoothcon-0.3.0-py3-none-any.whl (37.1 kB view details)

Uploaded Python 3

File details

Details for the file smoothcon-0.3.0.tar.gz.

File metadata

  • Download URL: smoothcon-0.3.0.tar.gz
  • Upload date:
  • Size: 152.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smoothcon-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7d3887ba07013829e1d6033cb6b3f8e218158e9bd9f7dc3e65755be873b0289a
MD5 bf906a6adce9979a1c077e45b117a4b1
BLAKE2b-256 a98eaae2d79cb941fa324da2300ea4ff6d156aa0648fa7e466e7bbd1d2d0e15f

See more details on using hashes here.

Provenance

The following attestation bundles were made for smoothcon-0.3.0.tar.gz:

Publisher: pypi.yml on liesel-devs/smoothcon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smoothcon-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: smoothcon-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 37.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for smoothcon-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e0155a4f60b8ce85e007a16daa9378cdafaee077faf04edc58e9d6ec4bee65d
MD5 c1f5221587648d5508da5f2b9911b1ab
BLAKE2b-256 90787929c063f9b2f4a5f6219534f42ec5f6392d8554992717913cbfe41546cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for smoothcon-0.3.0-py3-none-any.whl:

Publisher: pypi.yml on liesel-devs/smoothcon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page