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.1.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.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (962.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.5.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (964.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.5.1-cp314-cp314-macosx_11_0_arm64.whl (812.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.5.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (961.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.5.1-cp313-cp313-macosx_11_0_arm64.whl (809.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (960.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.5.1-cp312-cp312-macosx_11_0_arm64.whl (809.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (963.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.5.1-cp311-cp311-macosx_11_0_arm64.whl (812.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (965.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (967.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: gamrs-0.5.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0ca4ce79c5033f94948fc1656d3f0d720874a2352df905b2924f85ed6aef7f93
MD5 3a21e08be7ca2d24679a632f4cb10524
BLAKE2b-256 c59bc3ca0e1a9069d01db6a5d9e423095efcbe25afefbd282235f26540995908

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b3f1c39d967b91fa71080d07a0b84ab0ce7f3a0c950d6e5b791b6892966ac051
MD5 a1dbb84898e3613acb87c88441af0f3f
BLAKE2b-256 f02262540ce79018e90f5dac6ebe3fcbb866f97e40d9c98684fe502915507501

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.1-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.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9823fb3b567f4b4502064697e0966a8ff1091655358ac721ce6c4585b2ec6449
MD5 be4820d3d7881ce4d4dd83cea1c8ff5e
BLAKE2b-256 a7ec2d47a9d367693546e7d8c7c3118688fce5a8db5070135d2998491b5471db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e54924c98d64a7b317745d5a2c71b24ea916d35525f0e1b833331c4d10c13f1b
MD5 e49aeba2ba68ffb16c96cecd733160f0
BLAKE2b-256 fa26351a0614ad7eb75f1df0cd21aebd75fe1810d4f0a42bcd0635376481cc73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 492ee44490811bc5b6b6c9c9ca318ef43bb1e30f8726ea55e4caf08ee1d02f34
MD5 ac4f323ae4321492d39fcc92bcbff41b
BLAKE2b-256 795cf9f8547a9aa80c599a1bbe1a573165833f7c9b335630e320d901ec8e2db0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 67298e9f4fdc4b1c5e62f45f808dee526e50551abfbe4d9215f55fc7d3faa8bb
MD5 16e96d5e7e952ae1e33b5e0f266aaf8e
BLAKE2b-256 435cbefd672f0e291e3db784bccc4666030e075d325c6f84347c5c29e4480553

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 892c2dc50bdd39ed8dbaf11e8c3f1f9e45524f32e97d5f42d91ba1b55524cb86
MD5 82587e579ed0137206957e9468b92e2d
BLAKE2b-256 3a4e0762e6882515b0069db8355f9286141b35b3116f47931afe07446d5c96e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebff52c18824037c895908ee9484d375364be8ee8b75b0a0dfcc860495c4404b
MD5 6cb642a12822d9adeb9980d6ddcc6151
BLAKE2b-256 f54ed71f76b3a73d1398e103bdbc8ef4132be444f955097c5212d46651b9bf19

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7112a73c12bce22ae348199ed7072c222258465040b7c94a675609a7b695f7a7
MD5 2af85c2569cc0900179c534a37a25349
BLAKE2b-256 1c6981420695e3fccebf2a30474a7e5d8559afb11031fc493af6fcb17ad65239

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af5e16224fe036fe4c34ad26ae30ed371646538a64f88fab310595b4c8217504
MD5 d3ff876ad939b2ad442173f543cbd01b
BLAKE2b-256 8cb4d8a8abccb2807b38ca28358ea4ceca6dadea8034678a90c2fac6b499dafa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6f6a8734c559ac560a3b02fbf72214cad6dd697845b62d0a1a47fe747933408
MD5 27174dd09fe3a460646abd7a91fd2394
BLAKE2b-256 35bf56116c5db1fc1dab85b3c7d9b3789c98998695a1cfb02bea87f0383e7947

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ccfcf6e3d19c3e193e1348beb43d49a9b041995952ccc602519e8a096cca8475
MD5 e086364ee622d0216067462dbecf06d9
BLAKE2b-256 992171b9c1a4488027034b8f7d245a3cef7dee5160710fb25ea13140f8a6a0fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae6ec2288d58ffc9220065348bba82907af69427fabd8626030558b454480a34
MD5 09bb146e6d89d0124667081e9c29118f
BLAKE2b-256 40a7713c014a70d3f213a7dda1d764463c7e12d8c3aaf564639d03dab6575316

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b3bbdf9959c23aa9fdb4b880f65019730f216fd2ea39f8afbffc27b8788cf5f
MD5 93db4c70b6c55de8aee934bfbdd249ec
BLAKE2b-256 d4177d012226a9fe412b2502afc9dffa3fbefe0ad79bf0534e2080f753049be5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 16516bc4dfffbecec8e0160463c6c4e71ea0aebba7717da4e79f9a00707db320
MD5 9dcf8c5c75de92f72003748d713de4c7
BLAKE2b-256 0f9af8bbfc0d72ff5f711985252676cee8799c2f67c804f7bd4dc7dad47ffc87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a97ea1970408f6794afd156c14f39ce40e3533436ff5c28463f4e90e58a5dbd4
MD5 666d55a48d590afde057d5ad0f6da116
BLAKE2b-256 a773938f6ed1a2aca269ba786a48c2e7326f05968b97b9133708b58432ec400d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47481ffb6196df51deed20a8ba4958f6616d4aed7e55c4b8da2643591c97cfc7
MD5 c18600fd8b419cf1bb3f92dcc661a3f8
BLAKE2b-256 841434d284f0d6148a6056c8b4d265bdb0e986fe1268950c094c0a2e90101576

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