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.3.1.tar.gz (869.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.3.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (879.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.3.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (877.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.3.1-cp314-cp314-macosx_11_0_arm64.whl (688.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (877.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.3.1-cp313-cp313-macosx_11_0_arm64.whl (688.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (877.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.3.1-cp312-cp312-macosx_11_0_arm64.whl (687.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (880.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.3.1-cp311-cp311-macosx_11_0_arm64.whl (690.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (883.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (885.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for gamrs-0.3.1.tar.gz
Algorithm Hash digest
SHA256 bdb30c596a4414507c7aeb57186cb81b8a3255ca79dc6a0451fcaeb1ec9eda03
MD5 1755ec330a9369ac3ceb09efe2681fbc
BLAKE2b-256 4742645ba74457bdd5b4e30299c294f57f07ec4b8266d28aadb8a4f057d951d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3757dfa205f3c1cad76888cf8bfb0e09b8487a03e9fbaaa82eb28e13762403c3
MD5 914c2834e57866705da8bd19de5a441a
BLAKE2b-256 a77d4ddf550f3e0aac8147c23fa2c25e86c48c39827c05fe5361e350f92af4db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.1-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.3.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 192b032ce8adf851d904798b4c8559040732575c87044a9b188b6841ea6e1800
MD5 1e107abb434c62b0405dd0301f4c2459
BLAKE2b-256 7d317dcbfab237eb72ea3be8a580d74c81a15262d35a79e627ed733c89651e30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bb8b3324c11c3d4f53c3f54766ef47fbf7884c61178c3967562555926cd7b2d
MD5 cc9c48a3fd835266b26556c82893a18a
BLAKE2b-256 0d20d4cf4609c7ca71199704f725dc12646607cff66c6db30cc0dd2121b8c564

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 440cd21232bd2eff7a625da96452bded62ca719d915911cfac2925395a29cef8
MD5 a3c5b6c9840ffe1749da78a94e469fc7
BLAKE2b-256 0587b5b8ef816edad888c2a6d203357c170f9a8e45d4550f9c83041b9bd75eba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.1-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.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3a9f18f48ee1cbc7718ff5a16ac96ab2c77acc6ff80c7b256db5a4fc79290acc
MD5 4573f968fe6bb19ae35fd9a12f53c8a0
BLAKE2b-256 251e78d633923e8325fa584bf67905d64ab8c22176fbbb961df6491c2bf24e04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a20013b9792a9a216ede88e45b331fcc14f9d490d8465995516faef623306965
MD5 e8fe1c85be100d204195b8514f3b8e52
BLAKE2b-256 3ff7e2dfd94b00d49873ede84614f5b768476b1fd737b2ab5fc366da62d4a479

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4dd014de8444532cf9a726b0401df2538f18279843e064fc6da941af1c2c886
MD5 df16159a2035475b3ddad14b07d36807
BLAKE2b-256 1e1bae64b1e1c68173e1123d05826ff80f95b86a5814469998ae57199be27166

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.1-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.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0f0faf4da12f2dc5929db6c2e1d8dc59495e0524084eb357ce7b8b6b66d86da6
MD5 4f69f54c93c685aeb97ae28838e38163
BLAKE2b-256 dd5dce1e73715e4bd4e9c09cec8ffd29e3c6c3a38c5c2c5e5a4c8669b20e24f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 567535287b3feca1e4a25f8d8e3fbf0e03881acd525f35c0eededca7a88f2381
MD5 398db998be1b3693fb14e545c555bf67
BLAKE2b-256 8136022290f8820efa36443d6f5d67ac7239d7d1aeb09c764a08574ebb6fe2a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 093e94e91017d078833d543de768b3d610adb25a56df91f283d45da434da9967
MD5 1078fcf1f9b02bff9f0ee25d3d1d1aa7
BLAKE2b-256 d8b42afc530a89ac99fc2496a4a78c9f3478b1872d9704b1b58082584879f418

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.1-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.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ffd406dbfe2092a5cfccbab9ea832cda6311e1b13c02545ef667fb9f33ba7544
MD5 04555dec840982c177d04bd0510a201e
BLAKE2b-256 7abfd9a51bb8eec218cc7a106a2481e4962ccdfb981f390726b0376f03a15842

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f8429015b3a0d6043a0bf793067b9b9529b75e4a9c8954b0d348a0498b6187f9
MD5 2361847637e1c439ac0e794f3d6b7b8b
BLAKE2b-256 01056f7a2b9ff09bcec26770dd709eba08ef5b050ad41a4fa7f2f071635701c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ced14790bd580659580bfbfde28423fc83077f282e19d30f4a48607642f9eaf
MD5 fc73f77942611e894a2001a7c4b2c9b9
BLAKE2b-256 0ddab629d2cda6c4a63323801dfd61fbcfde07a760d59cb87ac0108fe336d61c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.1-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.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 af08513e3ec4d8007b21c4d3195f9944ac34780e7bcc078f4b3687b9bd340317
MD5 a4c5b2dca1edcd5a0e07af2373981814
BLAKE2b-256 32c495370abc2d32c61ab44701f40a34676e629f33c5897deee55056e7e060d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b08a38a0629e5008472de84f8173764350d6cc12d6e143bb9804acd2a8193dc6
MD5 be612c5672c65ebdae2d5c3e1e3af081
BLAKE2b-256 fe52bbf8400125dc16f2944f51ffb780f6777a72fde282aca81db983ed197c1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c99d9e69f22ec834809d75afc49ad9d0a32c83ca4d4e52765426494ecbe51fa
MD5 e3a472a9c46d2cbd3fbf49fb35bbf98b
BLAKE2b-256 6c9c0763cd294fecdad173a64d3859eb09714715cdbb0e0003fe6cd6bf460887

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