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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.5.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (981.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.5.4-cp314-cp314-macosx_11_0_arm64.whl (808.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.5.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (978.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.5.4-cp313-cp313-macosx_11_0_arm64.whl (806.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.5.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (978.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.5.4-cp312-cp312-macosx_11_0_arm64.whl (806.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.5.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (980.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.5.4-cp311-cp311-macosx_11_0_arm64.whl (808.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.5.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (983.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.5.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (984.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: gamrs-0.5.4.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.4.tar.gz
Algorithm Hash digest
SHA256 0c7ce1e0b98d59e44576612b20b8b4306dc36b4c9362083fe5f9e0dc35656696
MD5 acfd151428a1852298d865a575d189a8
BLAKE2b-256 63f758b9134329dc84d44c297f21a7cfede611a1fa9af2e25047e9566596cd83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e372a5731086a0f4b08654f1b90d8e7eebe57afec57d5e612323d50ff0bded59
MD5 bc1ee489425a9d3c8e865e6051cd5231
BLAKE2b-256 7e2fe305e5436e4dfc11e0f257659c6c6af0dea620b26bb830e1d08eaa5b8746

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.4-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.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3ddad65b5e1871e20653905227ec417bf6a8925f125261565a2b6f93f3c89dab
MD5 0d0a39bc4ed7af1ea48a596295ef149d
BLAKE2b-256 8bf28be1c7182d5ba5d7b33564637f48c7d0be18e05f8cd92fd074a304df045e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd2d7304b2a830fd8cace76e4686b1fdac88d100698127866034fbc6b0c5b8d5
MD5 fe0d3f19a542bc1825c241f51dd2f186
BLAKE2b-256 230c40c86d459d82834d19e81f90c8a90a1f95c39b6260316a4e402948883804

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a250cca8a840cdb8c7e8f04d15d2f70af1267a236321b9cbf2b4c899e476ba53
MD5 151d51da807bf1c2b1883b1155e00046
BLAKE2b-256 e8e8a97ffd52e8f57a479c59a8bbbdd62f0cc6c577c26a32e668fc1817d0a7ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.4-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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1cc649e4aa96843ad69b41c643464e3421b1e43881312b36aa9b7fa278953a4a
MD5 9207a1e575ef39e869511f1fd18d2009
BLAKE2b-256 f349c205549da5eccb3fc9befd2dd0dbbb9fddda0821e73620913082ea24a3d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f29a9994af5b40d33cde2992a40ce67218703a144d4fab90be68ef9d671e1812
MD5 618e71b46f6cebb1044189748376ca56
BLAKE2b-256 f0354b1c157bb86fa9950d6b3753b9631a008ca0fe38f0a48bd1d22a7a36658b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 677809bc874bbb232b112d7c1fcadb31a9146283ec1165e9f4db846b14b07cd1
MD5 ef6d63c0e4814d8c4ed06cbe03b886b4
BLAKE2b-256 6c4254b0b91a3a48a8d833714c622162a8a29e6399fca123a0fd1322817ec695

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.4-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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 13856117cd052f69412b77fbcaaa1d9622d2c0ee1ff1af2a3285683231c7468f
MD5 0fdc1878563cf165295109218f1621aa
BLAKE2b-256 ae7323da45ee14994cba4ee4dbe7d6a6412b7a3f599ee350d712036035565a30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb02f57e6afd6ea1bce1b7f0a6ad9423c7ab1260d7c67bddc83165ba445cebe8
MD5 2108497f14988c65142fcff4b641ea24
BLAKE2b-256 befa9228ab5e0a740636f727f5df227d527b89b2978438fc118ca71f6dc887f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9dbb099b03db521f1a2fce88ea1dcf01846cf278f8778f45626ebe83b11223e9
MD5 ea71131f16231a8affa15c76217cdfcd
BLAKE2b-256 bb20a0931e447280025b7ca87646cef7b24a1fd58dcf821d88f65fd6289724b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f3152b49d04a6c929c8d452d46f3089c33601489d92cd0c581fc56571f8dc263
MD5 c7cb18a983f5a901001ba8758e81876f
BLAKE2b-256 558946dd4d38585407602cdb4dd60faed81c616c12e4cf9c04f3938f111355eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adbd0f6b3f3db8372c8ca7e2590fc8cc42ce0a40799526fd1c4d7fe46863b2c6
MD5 a42a18be22c9f62530abb7b2755163ff
BLAKE2b-256 3dd0f4970149311ea54905e2f1d9a963acabd37d6103238c8be2d0104905b2a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 69713f2682bc8ef5a5e2b73b2fb923c7e024862418ef07a0e1d382fc691e2c6e
MD5 a1c28e7e537044dad185e5d5357c1e81
BLAKE2b-256 f29f58ba0fe76c706ef75413b29fa094857cfedd5ce7a80b764eef640a2a00d6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 58e847bfc74cf08a5793b2fe51a62f0524e654f577c4fa2e3e9f05a5a60e8778
MD5 16ec11f43d86c3195a0b05eaee512c7a
BLAKE2b-256 fee9e76b661efb3dd0de070b2e3d1ded0ea5b80d524d94d451b6b58867c1ef35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18d58444b2e3d5027adb1a38cf44136bb1ed2abc3142c43c48e2770fd466d890
MD5 e7d683e87f09de0ab46b2ee40326dde5
BLAKE2b-256 ab02dbcdce77e79af0e2a6a3798932bc354e8447f408cab6de8cf3c519754279

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b1246929c150cae1a43cb0460f28890ab34ef690994ad03c6686e78e631d8053
MD5 c201f5b150dd325cca364448ef87776d
BLAKE2b-256 681281a9db2c33cc2f28cb58eb6b87beaf32e9be05eb23362f38d58ebfb6dfc4

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