Skip to main content

GAM core (Rust) with sklearn-style Python bindings — beta

Project description

gamrs

Generalised Additive Models in Rust — a clean-room reimplementation built on six composable trait layers (Basis, BasisTransform, Loss/Link/VarianceFn, InnerSolver, ScoreDerivatives, OuterSolver). Designed for parity with R's mgcv and the sibling mgcv_rust crate.

Status: beta. Multi-smooth additive (y ~ s(x0) + s(x1)), n-margin tensor products (te(x0, x1, …) / ti(…)) and thin-plate splines (s(x0, x1, bs="tp")) all ship. NegBin and Tweedie now fit multi-smooth too, and Tweedie supports both profile-p (tw()) and fixed-p (Tweedie(p)) via the tweedie_p toggle. The remaining single-smooth-only families are scat/TDist, Ocat, and ELF/quantile.

What's in this beta

Families (all 1-D parity, 10 families)

Family Link Inner solver Outer Newton Parity (μ rel-err)
Gaussian identity one-Cholesky 1-D Newton ~3e-6
Bernoulli logit PIRLS 1-D Newton ~1e-3
Poisson log PIRLS 1-D Newton ~8e-5
QuasiPoisson log PIRLS 1-D Newton (prof φ) ~2e-4
QuasiBinomial logit PIRLS 1-D Newton (prof φ) ~7e-5
Gamma log PIRLS 1-D Newton (prof φ) ~2e-2
InverseGaussian log PIRLS 1-D Newton (prof φ) ~3e-4
NegBin log PIRLS 2-D joint Newton ~9e-7
Tweedie log PIRLS 3-D joint Newton ~5e-3
TDist (scat) identity PIRLS 3-D joint Newton ~2e-2
Ocat logit gam.fit5 joint β + threshold smoke
Quantile (ELF) identity Armijo BT 1-D Newton smoke

Bases

  • Cr — cubic regression splines (default for 1-D smooths)
  • Re — random effects (bs="re")
  • Tensor<A, B> — anisotropic tensor product (te(x0, x1))

Smooth strategies

  • Single 1-D smoothy ~ s(x0)
  • Additive multi-smoothy ~ s(x0) + s(x1) + s(x2) (parity with mgcv_rust on Gaussian/Bernoulli/Poisson/Gamma/InvGauss/QuasiPoisson/QuasiBinomial)
  • Tensor producty ~ te(x0, x1) (leap-frogs mgcv_rust; v0.x doesn't have this)

Python API

PyO3 bindings + numpy. sklearn-like with vcov, predict_ci, predict_diff, serialize/deserialize, GamPredictor for inference-only deployment.

Not in this beta (follow-ups)

  • Multi-smooth scat/Ocat/ELF — scat/TDist, Ocat and ELF/quantile are still gated at single-smooth. (NegBin and Tweedie multi-smooth now ship: the shape-aware θ packing [ρ_0, …, ρ_{T-1}, shape…] works for those two.)

Use (Rust)

use gamrs::{TermSpec, MarginKind, DesignStrategy};
use ndarray::Array2;

let x: Array2<f64> = /* (n, n_input_dims) */;
let y = /* Array1<f64> */;

// Single 1-D smooth
let fit = gamrs::fit(gamrs::family::gaussian_identity(), x.view(), y.view(), None, 10)?;

// Multi-smooth additive
let fit = gamrs::fit_with_design(
    gamrs::family::gaussian_identity(),
    DesignStrategy::Additive { terms: vec![
        TermSpec::Cr { col: 0, k: 10 },
        TermSpec::Cr { col: 1, k: 15 },
    ]},
    x.view(), y.view(), None,
)?;

// Tensor product
let fit = gamrs::fit_with_design(
    gamrs::family::gaussian_identity(),
    DesignStrategy::Additive { terms: vec![
        TermSpec::Tensor { col_a: 0, col_b: 1, k_a: 5, k_b: 5, bs_a: MarginKind::Cr, bs_b: MarginKind::Cr },
    ]},
    x.view(), y.view(), None,
)?;

let mu = fit.predict(x.view())?;

Use (Python)

from gamrs import Gam, CrTerm, ReTerm, TeTerm

# Additive multi-smooth
g = Gam(terms=[CrTerm("x0", k=10), CrTerm("x1", k=15)])
g.fit(df, "y")
mu = g.predict(df)

# Tensor product
g = Gam(terms=[TeTerm(cols=("x0", "x1"), k=(5, 5))])
g.fit(df, "y")

Architecture

See architecture-assumptions.md in the repo root and the v2 plan note in ~/ObsidianVault/Projects/mgcv_rust/plans/mgcv_rust - v2 Architecture Plan 2026-05-22.md.

The trait layering (src/traits.rs):

Layer 1   Basis              ←  CrBasis, RandomEffectsBasis, TensorProductBasis<A, B>
Layer 1.5 BasisTransform     ←  SumToZero, StableReparam
Layer 2   Loss/Link/Variance ←  10 families (see table above)
Layer 3   InnerSolver        ←  GaussianClosedFormInner, PirlsInner, GamFit5Inner, ArmijoInner
Layer 4   ScoreDerivatives   ←  EnvelopeScore, ShapeAwareEnvelopeScore
Layer 5   OuterSolver        ←  NewtonWithHalving (ρ-dim generic)
Layer 6   FittedGam          ←  predict, predict_ci, predict_diff, vcov, serialize

Versioning

Beta (0.4.x). The API is stabilising; minor bumps may still carry breaking changes until the remaining shape-aware families (scat/Ocat/ELF) gain multi-smooth support and the 1.0 surface is locked.

License

MIT.

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

gamrs-0.5.0.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

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

gamrs-0.5.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (958.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

gamrs-0.5.0-cp314-cp314-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.14Windows x86-64

gamrs-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (960.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.5.0-cp314-cp314-macosx_11_0_arm64.whl (790.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gamrs-0.5.0-cp313-cp313-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.13Windows x86-64

gamrs-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (957.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.5.0-cp313-cp313-macosx_11_0_arm64.whl (788.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gamrs-0.5.0-cp312-cp312-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.12Windows x86-64

gamrs-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (956.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (788.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gamrs-0.5.0-cp311-cp311-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.11Windows x86-64

gamrs-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (958.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (790.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gamrs-0.5.0-cp310-cp310-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.10Windows x86-64

gamrs-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (961.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (963.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file gamrs-0.5.0.tar.gz.

File metadata

  • Download URL: gamrs-0.5.0.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for gamrs-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b5af36cc751f2d6fb65fe9849e164599690607cf5fd1ca373e5c4469ed4f7ba4
MD5 283cf7f49a901180a8d8695d86c11408
BLAKE2b-256 4090a15e02a6d96e8d57435b0432433c8eb27228e57bd1ef68b338da605ce73c

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a2af2c74f00bcefef19575e9a144f35a33af34aaa433972e3f7bb36552f0e32
MD5 d4870d134ac8b270e81e32339520d6f2
BLAKE2b-256 36541182b9597767a7d4fe02c65610284d7bc4f770a540c568a3fdf82730d371

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.5.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for gamrs-0.5.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1991c6fd0a63a9e061046cf55d6b396b4aee74ff9ec547c981c8f46b4804219c
MD5 c7124014882cdfc089ff065b920bad1d
BLAKE2b-256 d51f25b1f3c63da2b5c0d87efee3c3c51f58dc78b4da26949b98122ee73b4ead

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5fd81fe19f73025f5a8d1a3cdd674fb5cc7c1da10b036abaff8f4135bcbc604
MD5 c62868875dd38ee43a4c4a9c2997999b
BLAKE2b-256 2a0c8eceb8a04cf317c157c8b6d777f08e335e942b48b31b9aa1d284aae6bd82

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 141d41e6d5cdf18b617d644e0aee02b9bcdc13c0672a21e1a111a266d7046eab
MD5 dcf485039fedcc5c672d26799f77238b
BLAKE2b-256 55eda63c0fd296086f079d7920412aa1a01dfafaad40738119f453445229c2b2

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.5.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for gamrs-0.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1b65934dcffb4bd187e43f2878c42b449cd53193e0869f9bd79c1574849d0632
MD5 c0e5ab88da2364c6f156558d69ac4a5a
BLAKE2b-256 868efe6b2e10957c3d61e233651b2bf496a3e9712708c80fddbdefdcc4ef26af

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0df409f79490f3159df0fc6ff50cad7fb5a3b0ac56849c066481ab6edef21fa
MD5 617f207e31ea90f448a49b7ce3297b96
BLAKE2b-256 297162a2ab6b1eba288658396142ed246f6017efa641595aef17a6b57b4a667e

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e74777f81d72d12099cf6a310e231375031ee5ba1ce5fdce37c6de0bd533a50c
MD5 0a97d6c392db9cf0c488a647c8cf0821
BLAKE2b-256 3290db03bdb29bb97c458e8210017ff26dd4ccb1f804b9d2f323168d57bce1e7

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.5.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for gamrs-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d4ad95361c46d9db6554d532b5946821abea01afaedff8afe48aa1676d90566d
MD5 f9a5a5c46e48d5dd885691d9491f687a
BLAKE2b-256 2d9b25f8f16339364fdf6fbba2660f86f732c45f70a401e0103b1992f5050460

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc8cb0c2b37effe3f315730555ef9d2f91c6c2ac280041320afe890b1819a84b
MD5 d5c9bb3d8e9e6baaa568a611f2b6157c
BLAKE2b-256 8b8f609dc3b679b8509a340def184d87dc282fa53a76d868c7bab8b67ad860ee

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9be84e0fb654988abd11c1522892122f43beaa132e6dc054e15c1b1e38c86c0c
MD5 c01b7acfabbbdac14116695808ae3d40
BLAKE2b-256 bdb56f1b92927ec8ac3d2d6128a825774e8e46ff2f075e168ff689b7131ad213

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for gamrs-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 60e1c58f0c8cef63e351c045e6690c6542b07d1ff075e28017996bb67e1a3227
MD5 e26050c5b7d5cd1c68c0e7a096781dff
BLAKE2b-256 e77a4b44103a75b3a4f43407bc2eb97ee71af6bab509b03b393e3aa9ee3bd5ed

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 697cbf658f21ca60c502adc385bc45f4c6aa5a43894e1d1825b642976f8df396
MD5 9883051a3c866e1c63373b3f41c7fd68
BLAKE2b-256 0f4f5919df31fcf817c57f6cde73798fb5e39d74341eb34842f92ae9b9f70393

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45f85cf09c5c58d77cbbb29ea1fb295834919247b41aef77d0916817d2089279
MD5 95801d980aa009572df28bf52b6d738d
BLAKE2b-256 0da3126c9ac394f0daa92062eec64e4d94cf09be3ba86e7f6ef198da8c78323e

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for gamrs-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8374d41ee61f79ae027c86f55f06ef34850ae3f202d550b19fe943cc5fda1b3d
MD5 91e7773828694c14f04e8d51569a299c
BLAKE2b-256 ee58635dad60407ed139f635c6d2499f45a1ffaa6c7e76c78f8ead6f7f77df7a

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddb980c20818b84838aa65e8bd2d9b5d5aa8136d3d2437af6841e2bfd84bc2bc
MD5 0b236f720d7fac85d4c1d01046b93888
BLAKE2b-256 5973e915283ef66a3106e0ac913ae296f9be3153e8535d4433d96eb0c85004be

See more details on using hashes here.

File details

Details for the file gamrs-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad08954c89183e8a1bf49da3a9c27914c37b64288b83d1ed71ed9037ed7f9688
MD5 d0b9f7e9493f38e7a332f1d0fab1ed62
BLAKE2b-256 69a10dca68ae358f51222fa2e64ea108ef6662f4be7f534a1b599ec0ef4fc54a

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