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.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.5.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.5.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.5.3-cp314-cp314-macosx_11_0_arm64.whl (833.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.5.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.5.3-cp313-cp313-macosx_11_0_arm64.whl (830.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.5.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.5.3-cp312-cp312-macosx_11_0_arm64.whl (830.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.5.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.5.3-cp311-cp311-macosx_11_0_arm64.whl (832.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: gamrs-0.5.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.5.3.tar.gz
Algorithm Hash digest
SHA256 cbd73d155fb8035f02449de9cea4e1195bf47efb83e7cc23a2e3d8fe975834b4
MD5 1424fee9ef67484f8f968ade9ab903c2
BLAKE2b-256 cb296075751448351e5e512ffa51b89e66f770fa0ff2ffd53f4a3943f961ec03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6559f23b9dd3c2a7649cde924d3cf1091996ce28f1ded9e9f36f41cd4a0e8778
MD5 e2dd5157bf56d7d9108b8969474911c5
BLAKE2b-256 96af15bfdb9884adc6cf7837f7a6c13b7326b7c91f4da2583f7f3c021c3a257b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.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.5.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 67ceac58a601fffc12d5defb27a415c7172e775fdd1bda22828c9f66cb2f714c
MD5 439c5da5eb1bf396b98f2c954029343e
BLAKE2b-256 6961bce4272b09fe183a08994fd77ca5229251d64f48429c9e352cd17aeb6524

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8ca39833d55809f5519b34f8ebf67c41ee48fb394baf4db6c0c13c7f64b0e0e
MD5 541d1fe1e84d9d4243a4f211dd5dcd51
BLAKE2b-256 aa66bbe937a57c052514c622f18b0bf089e03b04c81dad8ebb351a36633f10bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80bba66d735c78f8a51ee25cfad3095cf414a295b8034c231ebacc65359ed662
MD5 623da9089d48f64bdbdf453f2e32f2d8
BLAKE2b-256 894520b3de3af73bad87cda85d5f8bde0e1c4eca8fe56746aba249032aa45282

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 11059332d1d58b2e204e33417e3d2ca8290bba9b8061773dd71e6cb26c0c477a
MD5 39c873f278d1118e3b0a8dc29555a931
BLAKE2b-256 48cd445f403d8e9528d2f4bd1726d5b780bf6863d9b60a2c86d6c52166576013

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d1f5006bb333f67a8da95c36d9a58acc8e299c3b5bd4eaaf3772a3de68049e7
MD5 4b64c4c47151a51950d49c44840137d5
BLAKE2b-256 a2a94a8792af52f0d84d871acc5e3fbb9ce1d64c6e81be849ab66b0dc6173566

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1790bf3f5a03baffdc54dc0ce3300b4d58c08d6fdbe2f57ac81d0db7b056d4d
MD5 94ec58fbf6038363955e5a4d4b33343a
BLAKE2b-256 9705d6a07d0113d81d251a27cc7bf6ef183166f598ec9f0e646700472248597b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.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.5.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e3a4ad380869e2e5a7aad7e783f5aa3d2f4cc2850b976a5364a1fb28e5c574d2
MD5 0a8c4f68b3d3859e68094a23616f1794
BLAKE2b-256 ce69a056525cb7438d2a9e237316e3edc3a7c763ceec9c20bacdb3d31fda0344

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 305a34a5a04154ceae43d66a81fb22b81581362e4725c5dc794f6c17b5c796b3
MD5 b76f7449b3fd7b07a9c92427f09ea3cd
BLAKE2b-256 5cf60283262106da62ea6a5812258bfc538c9a45e39f227248ff3f780b8442bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1691a7bef586c59f53ad208280ec36175927c371aaa56d9583a498a52d8bba34
MD5 90924918ed5012357032aba14decb6bc
BLAKE2b-256 4598fe683a8004729ec71c3fc37c1f4b37bca8ce2072561d9dfcd1fa75969485

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.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.5.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3ae8ce26b57187fa58e5807b091e3049dda9269bd9fc1bb7f913ab40bb551539
MD5 a39a01d771247bbdce4180d800276227
BLAKE2b-256 7dc382270cf07609ee5a90f8ad075ba033a1d0660f955ef767752c2d17f8c287

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc649b6d079116d31f1bd79e6fe159842590e0cc625c4027d3b257a146516bc7
MD5 295f97d4bae9598bab03b14ecc8b9dc2
BLAKE2b-256 d44b6970787b6623c25043afd7e93f7af86d0d482f8aa8ee6942aeee950599ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fbd5493c4722dbfd580f6c53355acb2c89bd80920860447dac7f64ad97a850d3
MD5 eb8c5a5f522aacb3f80afebd8616874e
BLAKE2b-256 9daa7b16f462076bf23adf06acf93fa797016f9de8db65f0b7a3542d8f461598

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.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.5.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f7f761158d0a50152ba8bc8ef1c4fdc076ce6860840dade565ff41dc4001754f
MD5 eb5e7e72783bc7fb3073b29ef186c29a
BLAKE2b-256 143af27e78d616ccbbff97110e36f7217c8ec146d8b94b2f94bba401566b5a00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2be8972fdbe2ba387c1508f63bc83b4492f435b403244bed3a2cd90cebfd8b1a
MD5 7d38989970fefdf66378fddbb6f07c21
BLAKE2b-256 416853cce2e772b18e098a2129086dced9e86419239fef41b5a66f8402a3297a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8a862873aba819dcb4301c2c53b71afbcbfbd99649b441c247df6e36ccb2e151
MD5 63a9cbc2e1b6d4688daa952377c3a6bb
BLAKE2b-256 70bb2710c925770fb9aa96cb442d3e4a96b8d6335837fda009d40c277eca5f32

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