Skip to main content

GAM core (Rust) with sklearn-style Python bindings — alpha

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: alpha. Multi-smooth additive (y ~ s(x0) + s(x1)) and tensor products (te(x0, x1)) both ship in this release — the latter leap-frogs mgcv_rust. Shape-aware families (scat, NegBin, Tweedie, Ocat, ELF) are still single-smooth-only; production users with multi-smooth shape-aware models should stay on mgcv-rust for now.

What's in this alpha

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 ~2e-1
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 alpha (follow-ups)

  • Multi-smooth shape-aware families — scat/TDist, NegBin, Tweedie, Ocat, ELF/quantile gated at single-smooth via runtime error. Lifting θ packing from [ρ, shape…] to [ρ_0, …, ρ_{T-1}, shape…] is tracked.
  • s(x0, x1) TPRS — isotropic thin-plate; separate basis kind from te().
  • 3+ margin tensor products te(x0, x1, x2) — mechanical generalization.
  • ti(x0, x1) centred tensor interaction — needs main-effect orthogonalisation.

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

0.1.0-alpha.x indicates pre-stable. Breaking changes are expected on every minor bump until shape-aware multi-smooth lands.

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.2.0.tar.gz (857.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gamrs-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (888.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (888.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.2.0-cp314-cp314-macosx_11_0_arm64.whl (732.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (888.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (732.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (888.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (732.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (888.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (734.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (891.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (892.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for gamrs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 44f26d8ffdd577f7d04fc6e82d9a4c866be15cf14032cf979ec551b392e86411
MD5 a985ee1906b89d56b90fa8a0641d14e6
BLAKE2b-256 e34e60411796c3b59b026864873ebbe236f944b1ae6adf7e7e9e170ad645d4e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05ad19a9db59ea989dd59c92a70d2b05bc8dfacf52883b65ca72fc1e1186dac1
MD5 81a34229b5dfd5c739c8adc12742a3d1
BLAKE2b-256 abe06c01aaab7ea0dc4b2cb753f8039a47e7cdc763a4b8b411ca27ab0eff3424

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.2.0-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.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 542d3a68edf160d2ae708d7ddaf9848deecdb154a3926bfe5da7a20e0a91e78e
MD5 c8c8652320385b32cef27e78ee0736c6
BLAKE2b-256 0a205ce9d81ea442c7f05ef05669d97407a26a516de1b704b382a92962b8c096

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adbda804d771026b9dab3dcace5a8a739035b1c53eb0e69b388440998280fa37
MD5 2e7b0dcd5ebebdd746889220f85ae26c
BLAKE2b-256 4bd5d3b352e6f14c214502b0b912dfe2251d2185bc5765ecbd03c8dc3fd723d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ebd3f7d066051b3d57f9ec2cd3722a3eef3eed0bdb33a55af4a259f4f62d592
MD5 8f63d08396c9e25fdabea190d87f135c
BLAKE2b-256 eac6a9d0d77c0fc983b5de0c64b9490ad065baaba99f23a6b8c29ca0ab32725c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.2.0-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.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9e237597d7a010ec447844154095a291838947bc4c4190cf66992ce846315c2a
MD5 8eb635aa0f1b24feb9247ca68e780112
BLAKE2b-256 fbe2e4adf3b361c816927573ceb6cdabce479c9fa821d64f26d73cb76b4d2825

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0f1d5e6c5416793ed7e1c6cc215138769e7f5c9423e5fd0e4389105ff792a7b
MD5 999f727de9b695ba3ede87ecdfd3794b
BLAKE2b-256 6227eb0611a1ff06b7e9a541720d12ea2e948cd9f95225c9f9ea7da4be81ce8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40eed33ee6dcac402844ec9013615620fcf124a329796d489bf8bc43fbf1c50f
MD5 323125695f33b90bb61e616918662636
BLAKE2b-256 cdb0c4562e6e837f9e498db216f27564609e8a669c4d74f8b42b84c4a43db54f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.2.0-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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 13819e667fcffffb79c98ed75f5e4e7c0aa7932381fc4eb4b4d7db8065e2887d
MD5 d9aa4d7837def822725877b0798648fa
BLAKE2b-256 2e3bebeecbaa0f3e32d7e17c995da98b1b5d58d03c3803d7608d39193e405474

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e15b15955d966798b866e9506eae4f3612406142d76d3bdbb4ede123a6bb837
MD5 987d929bc455b81dd2e08fce16af4b62
BLAKE2b-256 10984723faccb39147e4a0e4c98e5e644885c57199aa1998b5a7c8c9b7c29901

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f04e312170d2f486b593aa12be0fcbf707edc30cc10804797ad552ac0a4876d
MD5 1ce539c338ba1fa625135757253cfb5a
BLAKE2b-256 7c94a8ff7e0d72454467b86d55d6cfa2a7ebf5ac1db6d6356581fcbc4893cb35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.2.0-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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ab9323de77c3ebee44e55764e72b4894fc1ac346003612da1ed7e7daf2037fb4
MD5 6429b2d5a807c78d26c7904febc6e824
BLAKE2b-256 4463b50a610bc52187d13b1e031212468cb6d34253c9453fccb10b6b65a0248a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33f89ad911dd18a962a56b751a56c530dc9fa0755b18c183a4095c3881e11547
MD5 2923df2f5a1fe3ae1c26b996504cb4d6
BLAKE2b-256 ec226e1ca77a5fc5401125c260cb19e75e15be64bf76676886668c0e0d265d70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 961a06dd7d30a41c1a684aafb6db6ac13b6e84bbb1093d51da04e3c1c8a0760f
MD5 6a4743489b7a43e5c97be49d9b68d508
BLAKE2b-256 c83b06f36288a354289a8735aa35ca1032c8814b02adf56982eabd776811eea6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.2.0-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.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d97803f587ee4554088fb4a4aa21c774638ea3de37b85a0806bb3ecf57d5b513
MD5 5a76be1e84a6d775b704cfd8f755e32d
BLAKE2b-256 48866202076ab9233d121625cdacdd6367374953a3cc1c9ee127413481d969e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 840696a9fc0d5d285bb2c5fdcb3fa54f66eae36576d2bf12df352ee6f3b9c131
MD5 7a5415ec2d524f4c2bfb8fc305c8f640
BLAKE2b-256 35042952f7c8772ed73da38b4dc4c7c80086bfd8add09763fdfe1e17acd4faed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2816b52141cc45b76871509ba2eadb18f4b599ff7dc82f8bd997d3e7aadd45b7
MD5 7fb1a477158b61fa530623e9a15a8e7b
BLAKE2b-256 9e3ee80753eb534db284bafa093aa9fdf08bdd23b6882e6f32f44c1f38cbdd8a

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