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 smooth —
y ~ s(x0) - Additive multi-smooth —
y ~ s(x0) + s(x1) + s(x2)(parity with mgcv_rust on Gaussian/Bernoulli/Poisson/Gamma/InvGauss/QuasiPoisson/QuasiBinomial) - Tensor product —
y ~ 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gamrs-0.6.0.tar.gz.
File metadata
- Download URL: gamrs-0.6.0.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d69032689b580d083d8f79c3dfc1ddc3f6c2d1dfc246e104447923fcf08901f
|
|
| MD5 |
64c4b50481c06f43dea6c73f35553689
|
|
| BLAKE2b-256 |
0f6fa2736aea526f71aa57cada9276828ad62ad0d2af5f8d208564553c043463
|
File details
Details for the file gamrs-0.6.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a47c0519f0261ca07f1be1019a017065e88fc1c694b5244e7ea93580abd106aa
|
|
| MD5 |
adea586a6dac2b0614149a1d56ac7a3e
|
|
| BLAKE2b-256 |
2a702aed1c1efefb32884b300cad05223c4dda209b29bc761ce1aff6b9e44040
|
File details
Details for the file gamrs-0.6.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: gamrs-0.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9ff77173f13fc68d97d336a916f0afab61d008dedd225400684817f2b69d929
|
|
| MD5 |
c5662ba70b6e2beaa0b46f6d1c7cb68e
|
|
| BLAKE2b-256 |
ef26b08ec31536b9001ba7e6b429a6176f978617e02633e035762a2216edb366
|
File details
Details for the file gamrs-0.6.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9830634167f4977738177968e057fe24bc46aec5771350d3b250259d1ed26cdc
|
|
| MD5 |
319ceb7475f2e768e20916310a37c077
|
|
| BLAKE2b-256 |
6587bbb50f3dcc95b1f4d36e7d527cf80391efd3a480394dba5b2838b83827ae
|
File details
Details for the file gamrs-0.6.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 842.0 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40a994ab2d019153fe7c8442c4b0f46c34816f002c580aa6c86054553fbf286d
|
|
| MD5 |
ffb58518d6c06baca511d0ad87125213
|
|
| BLAKE2b-256 |
d657e58ea151d8a2360c90cc2525302ab6e58da046aaac3720facaaf76cec3e6
|
File details
Details for the file gamrs-0.6.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: gamrs-0.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9de1e8866198b4426290240f0eab29abcf152f9cec60925bb37925817263b1c6
|
|
| MD5 |
856ae198fc6972ac66a544d4b3e1d07b
|
|
| BLAKE2b-256 |
0e140120380699986051e44f5af90e0664c2ff8c5d28a32227db756b979b5a24
|
File details
Details for the file gamrs-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04fd375919190a6585d076dbb45e232aad61fe926e109fcdc5e53b4f3993c66a
|
|
| MD5 |
86067272891712031e46279e02bb43e7
|
|
| BLAKE2b-256 |
434aa74a5a9cb8bf6daa404d3931094c15f81f4781917e311aebe5d6dee735eb
|
File details
Details for the file gamrs-0.6.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 839.6 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ed6ae55705391c926a560fd4d9f1fc920c35452e49faee89908b5ef8f4048d1
|
|
| MD5 |
f8136d776d93304a8fd31da6890203f3
|
|
| BLAKE2b-256 |
fadbb49fd4b12227e6719f2d54d37dc0717e333593bd64d0cf38c1486a6aeb51
|
File details
Details for the file gamrs-0.6.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: gamrs-0.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3d08764ad4ab996b82a7f0ef0f259d34a913d03fc7985f4047c4fb6083cf266
|
|
| MD5 |
1b1009b436837a77bdd0b31953ef6365
|
|
| BLAKE2b-256 |
d0f5c1a33d1ff2c3b0980508b362680b38b19034f762f4051f0683dc2ef2e187
|
File details
Details for the file gamrs-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3977571f62ec61b799058bcec547b5b57951827eb53d9129f9bcde36e677749f
|
|
| MD5 |
b4ea175629060921a91c7afd93b619fb
|
|
| BLAKE2b-256 |
dbe59c73f93c0be02f140bca509247fb53dd33b09a3cbf60990faaf99d665a01
|
File details
Details for the file gamrs-0.6.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 839.4 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
693dde345fdda630be0eecfbacdbac47a829d796e4fc3a6a789b41f4a7896020
|
|
| MD5 |
a789c2a48ef933dc7b520e62c957cc56
|
|
| BLAKE2b-256 |
667375ee5ebb82c750bc510f96613f542dabe23cf12cbccd2db78cafa4bc2e21
|
File details
Details for the file gamrs-0.6.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: gamrs-0.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd42f705436cfb4f6c45dee612640984c73a540ce064483107b6f9ad98b2f35a
|
|
| MD5 |
e43a540dc4b8bb0c02006ce75fd50e72
|
|
| BLAKE2b-256 |
9ac627494f45f6c25dfb909560e33cca9ed82925e1df30c86f8d9a2565c739dc
|
File details
Details for the file gamrs-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47a38abc81660d04074cd1f5230c20bba18c34bfd62959c0c6651400dc2e1ce7
|
|
| MD5 |
5c538b49253b57319f5d4935aefaae58
|
|
| BLAKE2b-256 |
b05a621932f85b6930f66b21537c268b895218d70a65a559dbbd1fc2e6b4aa0e
|
File details
Details for the file gamrs-0.6.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 842.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c891674442cfc57ec1c187eaf2661668b81ddefa5cf65964fa0097c1b0ec3150
|
|
| MD5 |
bce964fa0ca91b3ad45c786bd0135f67
|
|
| BLAKE2b-256 |
f13cac7106813994392891beb8422f74e52d874882f46e4b06611b9e43678821
|
File details
Details for the file gamrs-0.6.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: gamrs-0.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6eb618ea728e22e5f955e8f365c0490a1011c79199b73f786f675ff5d17205f9
|
|
| MD5 |
b7036463019060cdd33037b838fed579
|
|
| BLAKE2b-256 |
71eaf373acd7df17133d974cba5d7f8a4cfa59358670b231fb4dd13713a4e928
|
File details
Details for the file gamrs-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd60939cfb91e699cf40badf45e090156d1813101ae6934211786d59ef953f0d
|
|
| MD5 |
2c43f7a25eae8cd07a289cc7d87be368
|
|
| BLAKE2b-256 |
942e89d70a9f0756a1ec81d5d722a11e781efccade4612fa14763b2fb02d52dc
|
File details
Details for the file gamrs-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gamrs-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f1a4d7e094557b563fb2a521691525e235a9bcf7783652b3506d32a11441e5d
|
|
| MD5 |
838a4df2f0d0fc5e00227cb0340720f7
|
|
| BLAKE2b-256 |
8cf649b4af51c9c0596c75cf5a97f2e5489c8feb7d2de11c47ff1e09e1cb871f
|