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.3.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.4.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (934.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.4.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (936.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.4.3-cp314-cp314-macosx_11_0_arm64.whl (789.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (934.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.4.3-cp313-cp313-macosx_11_0_arm64.whl (787.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (933.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.4.3-cp312-cp312-macosx_11_0_arm64.whl (787.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (936.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.4.3-cp311-cp311-macosx_11_0_arm64.whl (789.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (938.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (939.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: gamrs-0.4.3.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.4.3.tar.gz
Algorithm Hash digest
SHA256 5257784b9b80c407568432c071e730deae0a35378a70310973a0b493c37bd5fc
MD5 0f7a6d32f140de5acf1209fe3d14d1d0
BLAKE2b-256 fe73b6022b64e3d28e3792bda504a7b5ac3af0e8f6bfe123c46da337c6f82716

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82d704001a5298f1ad025458b1618ce8e193eb317136ee4396a26a7387a6521d
MD5 9cfa5f6dbe3691dc0b0401074ea69aad
BLAKE2b-256 2ee9bf7e7681547b41853b8e0e043275836d5f5998253610ee289e1aabdd52f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.3-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.4.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e60f502d1636bb71211c0ddff534931033eaa9eeafdf36ffcce55f2125322172
MD5 fe7d4e9c04ea0ac59670dca365451625
BLAKE2b-256 6d3cfc41cbe8037122dfacca8644f7e618394cd6c51dfe5582be13e168adecc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebdbc35ecd217608a0e4558cd2bc0ff98ca86bfd6de1fe89b8d70cdcc6cbbea7
MD5 6b0fea3d3b3a117c360e0a2c4da56f33
BLAKE2b-256 5d17f5de64c009a7de3fcc8428deeba36faa9ed06e6ba970c50721fb42d83fe2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1fa09deb3fa04d8756a1671fc4cdca0220a9d6752ded4b7e708e5761a9955607
MD5 c2d1b07a0aee18db7fcdc2a14e5f9839
BLAKE2b-256 ee499845a65c4da11d79e1776f7b79f795e9a6224df18207293b906b4ff17fab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e299351eac51f23d4d6d10c0de56063e0401555a392177af5b246c65f24eac03
MD5 e5dace801c1ded369fec677bc34a65e2
BLAKE2b-256 0e663d53faa498b367534a6eac4f87e6ab9d5aca81a6bc65c1416e9022b586a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75a6998a596757f852c3485eac00d04141eeacb5c1e9e7d129b250719a333d4f
MD5 ba9dc9b1e7ecf1e76afef6e08d9208de
BLAKE2b-256 4c479a1bb220889966af6e8543773c2647794e7f5e412c96e03f3d17d3f3fde3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c11a9bd551e73999c367b763b11ed7111125b96535a943b5f6dc153033f7f120
MD5 8813cfa8b809889699703c1d4ed2fd11
BLAKE2b-256 f3dde37c83ea6213dfd0ddbd73b2f30f52a0448191aaf0f7d2b1855bcea04fd9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.3-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.4.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3e5501f1e33173e45caae7c20b39ecbbb5299fa8db4af1428a6d83df23685b99
MD5 ea202984fd93f61577864e89e0500282
BLAKE2b-256 bfdc3869d410ebb176442fc12f325dd3efa70d66cd221993b803901ae676b8bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b1098a4f42f08f486f634116da8bd35c1d92c9a95b1a796bff3218248d40c6b
MD5 5d8dfd1cf1a574cb726021eb48ef4171
BLAKE2b-256 c66357735134aeb549ce9c12aa3d3c110b02806e77b829203298d1c87028f4fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2208aa43d3a23a4fbef5170c333a93760de5ac3378210b09167d58b95ff377ae
MD5 5732f2e0d2ea52b4f4e2d0fe89085e44
BLAKE2b-256 e85497ace53a42717c2ca8c936aa9cfa4bb3eba1e2bbaf7fa8d8eec9448c876b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.3-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.4.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bf9187e5b8a63431418bc6142f23db2d19695cd71e4cccc792ada4d25d91bc10
MD5 05399dcc8147eb9a64642079765f918a
BLAKE2b-256 6504974908124d8e72368cd97f4ea819e5d8ca076497a40727e03553cbda115d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45746ca76e30f816b87dc829ed898b16ad02485c89ea588245afd06efc78a1da
MD5 f72cc160252217b0d126517249c9f98c
BLAKE2b-256 b980704ede5834aa6339513c68ac9b65bc7c4dcda5f4a2aacb039d50ab1d5440

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 facdf0874fd5857333f563c9ca54f0e548841eff205abc8b519d86bf2ffa77f2
MD5 aa50d87a03296d7767acef377b041bd8
BLAKE2b-256 64827da683df7a1f76849ebc22018b4db4dbc331d3fe3ce2c78822a366c80f26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.3-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.4.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2a30cc27cbedeb817a8dae12037dba9c98b3bc2905a1b8b7bd6511aa1783be53
MD5 51859c9a084dfe0b483c6e29b3c49c45
BLAKE2b-256 6cdc9c5d9165b896b5d3fdf027984ca8e90349f51b8f25d04e19ccd1fe39b842

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e8c3779e70fbc1cc0264d8c4c87fb692afa9657f2e20691e93624c653229371
MD5 4e66bde71d3b5efb8565b0d49347aa96
BLAKE2b-256 c1c009342a31103094c90b3053abd54ab712586ea40daeae1f13dc352998511b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd26a44fd09ed5a0837c82db1667d8e27d61fa53fd2cc4ae9c0defff66c0cfdf
MD5 5b701d54dde9a7245c0c68d35b7d35bb
BLAKE2b-256 d6d60f3be4aeb93be1767e7968b58bf168cbc4601d15523bfeca2a27d75c33db

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