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.4.2.tar.gz (3.5 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.4.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (919.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

gamrs-0.4.2-cp314-cp314-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.14Windows x86-64

gamrs-0.4.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (920.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.4.2-cp314-cp314-macosx_11_0_arm64.whl (731.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gamrs-0.4.2-cp313-cp313-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.13Windows x86-64

gamrs-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (917.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.4.2-cp313-cp313-macosx_11_0_arm64.whl (729.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gamrs-0.4.2-cp312-cp312-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.12Windows x86-64

gamrs-0.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (917.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.4.2-cp312-cp312-macosx_11_0_arm64.whl (729.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gamrs-0.4.2-cp311-cp311-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.11Windows x86-64

gamrs-0.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (919.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.4.2-cp311-cp311-macosx_11_0_arm64.whl (731.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gamrs-0.4.2-cp310-cp310-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.10Windows x86-64

gamrs-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (921.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (923.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for gamrs-0.4.2.tar.gz
Algorithm Hash digest
SHA256 af56b9a53734491ac87f6180420f21d505da8cf0fc87c18b5e0845df7bcbc505
MD5 5cff88527e2894d83c26fe77b2673364
BLAKE2b-256 84f20c7e645c810bc597cec9c6c2f3647b76cc4e97835d06a4fcc24e97fe5086

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c65535b9df422446d07d35875322f109e98c91d2a839218b088da7d645eb62cd
MD5 49e2e69ec82ef41840adc7c155969943
BLAKE2b-256 3e961393f5695938e6ce7fe750e7d0c6dcd247bd3e22e9edb2e07ba50a7a4a5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.4.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d6a73d478d74f60e60df63b67984ab5f8e4c28b156224b56ccc4161b3bca0cdf
MD5 406542e8f9aa574495d5dcc14a1008df
BLAKE2b-256 31fcbbdb8cdc76fb29ff367e0b6eb952d2a8277737cdd80a324d767d14cf389b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63221cf42f25c210db21d7c4ec281d8e225476d7586d5fd16bf3d54e13c51feb
MD5 e843258aaf2b1edd7bd5f2d072464093
BLAKE2b-256 82c487db65c3d88dc7755a37ad6398cb4b5df329c6081e72d804eca4c190c6f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f683c1688ed9b312b6e5e336afc65d724414f2f8044dba28a4ce078b96f6ec5
MD5 bb9dc89559ef116bfae6e2afccb141f9
BLAKE2b-256 2adf104b130ee6ff94b1978f1c5d33bea2ebcdd1bb71b2a851adcea7483a9a59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.4.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d39d9eac5ef4c41534f44af57f35a6039926fa9ce3efd793837a48a3d03e2b4d
MD5 e639a147567791ad1ffc0dc446f3f1da
BLAKE2b-256 07f3df5a2a090d646b9ed971cc4ade7f25f8334d2205731a695e6995eec699d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 387d4f248a5bbae27c2124ee780341453b0a50dbcbda190dd5e3ed9f376d7ba9
MD5 068789fbff6431c9e5b352af73611923
BLAKE2b-256 37e363f445eb7606a159a4d95ef8d0182f6991453e242961098234924c4a60b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9dd70b42e848419939dff9e10afc958313e836286613d12101c0587e69cf4d31
MD5 7456b5891112f10f63800a02c96befd4
BLAKE2b-256 96424259f0913d91894e8b3c49b3986e4565e0cad69a5c1a1530576f2e71b2de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.4.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d8af7f020624726b7f3993608eb66898e28883a2d47b081b8011a031e953d6eb
MD5 2e00d44530c486e4b3a0be8c5efd511b
BLAKE2b-256 6a12c7290bbb555a30a55734c9ea0280753bd561abe4eb67196b9b4c851cda10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7ad5ad02be983b267a7b49a6c193414e4a1691319a54244022136902b90688f
MD5 0cfaaa4ca43862e5e82dbfef7e52168e
BLAKE2b-256 710b0eff920ee461dc8e82418421e1f1104a19be79e375f847fe87b1dd17fe4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 813c366afdef6e69e77add769829b65512821ccb7ba3aa55b2ac4bcf7cc3262f
MD5 9d225a73897275ea086ce0e6dd29ead0
BLAKE2b-256 7dc7ff2795fb73aac695aa429a32c3df313c89814dfd29f32e4f224d60c563d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.4.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 772f8a26d3d37c12a55df401e1bbb7ab624805161393226ff5ef13ff3ffcfb29
MD5 2a63ba260fb7a2b38230f0b964982486
BLAKE2b-256 7087fdb645a7a4500a09ae0411bccff9a66c11dfe3a5fc8ce45267d103f65ba7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8cc377a257b372fb410058f866ffefefba60c2b35bf3de68f3743aa4f13b171
MD5 aed7b3fb1009def56c594118f3ae6f58
BLAKE2b-256 ba3cac30df689adf21e333c4cfed1f6ef65a93fb430e7ac1323e2292b6c49213

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d88c31f7c546ae8bc87e8b3b7f2d908fa48efeb55e49507aa4384c273d2a18e2
MD5 a141077bfc2cb6aaee1430a16118d4b5
BLAKE2b-256 224abc1f46213963edba9fff50877bc7b52939f6ae26d2e2f0c5eee770e3ca6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.4 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.4.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0859dace3d5911a19d09bf54d450bedb79989bcd82d394b9aed9badc5ad31604
MD5 853f49360212da69a7ab01f5e0c01aff
BLAKE2b-256 5c8f72ab0e988af2348a8c21b43f7da7924248bb840778d488a19f4202f16191

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a555d60ff9b7b875eccf01eb45e6e1e4fdc499ff7a3a61853db0dc83d1076f8
MD5 9c99ac88d348400b2b58812ddfe5c96f
BLAKE2b-256 642c239e77d20b05b9a198cccffa26146db14a8eb01233031a11a023d79524b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3069953b4845a2313fbb0b8c623fccd2f070363cfe2ccf405b4024b63de2aa8
MD5 795d8557bdfdd83eedc26776c9ef4207
BLAKE2b-256 1aef00d26a8d8f27b0e2b3a215d4ccee60adfe3b76c2fcee3618b4325c9c2f74

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