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.1.0a7.tar.gz (837.4 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.1.0a7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (830.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

gamrs-0.1.0a7-cp314-cp314-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.14Windows x86-64

gamrs-0.1.0a7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (830.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.1.0a7-cp314-cp314-macosx_11_0_arm64.whl (682.2 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gamrs-0.1.0a7-cp313-cp313-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.13Windows x86-64

gamrs-0.1.0a7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (830.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.1.0a7-cp313-cp313-macosx_11_0_arm64.whl (682.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gamrs-0.1.0a7-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

gamrs-0.1.0a7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (830.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.1.0a7-cp312-cp312-macosx_11_0_arm64.whl (682.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gamrs-0.1.0a7-cp311-cp311-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.11Windows x86-64

gamrs-0.1.0a7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (830.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.1.0a7-cp311-cp311-macosx_11_0_arm64.whl (685.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gamrs-0.1.0a7-cp310-cp310-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10Windows x86-64

gamrs-0.1.0a7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (833.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.1.0a7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (836.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file gamrs-0.1.0a7.tar.gz.

File metadata

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

File hashes

Hashes for gamrs-0.1.0a7.tar.gz
Algorithm Hash digest
SHA256 c2db06f365ea2d623bcac60997ef1f51d8f9811c8da09a3693b4e05831cbb1de
MD5 142047cf43d3c3f0bc5d9471e7a7df02
BLAKE2b-256 4afb80d2b47ac4383036d252667f759b78b8bff3faddf908a55cc8060abf24f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.1.0a7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a11359588ac5b11d1038ac73f69740f02181201bae4f0b040823cfe0574b8187
MD5 d7b74dccd55d4145276d7632290e300d
BLAKE2b-256 806ec511267d0efe007858902a3f20a3cd964e85c19831d305fc7339bb84dcc3

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.1.0a7-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 3.3 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.1.0a7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 94344475ea594692ce3ca7d45054d47eff13cbe726c06d8dfdfd4866ec5350c1
MD5 f0562ade992bcd12022b61eff6385eee
BLAKE2b-256 1d7f4de18735662f13ec2e7e563f65aba304b8dcf62e59423b6f0379d5f1ca69

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 91dd76f4c87ac9f1978aa75a332352f916f991a41d55b8c0439c7c4cc63ba3ae
MD5 b2b412587e19750931ff43b82cba5af0
BLAKE2b-256 be07b2999181e58ec8ad7630165435d2755b61e01b51e5cd71b575478af5f845

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f04bde517e8dad8826e733f2671c11a56c3aa5d3a4f500cd0b8a7280b75bcb4f
MD5 a849eedadf690981d6cd3e92d0e89f36
BLAKE2b-256 65e1ba480b84b290ecec99c133faf8dc91422bdbbda51be6ecb2caa565bed102

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.1.0a7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.3 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.1.0a7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 be9897f3c9e991470143363fc05ef31fd343ca827af55963dba57344f0a3cb9e
MD5 a65d87dc6d185f73042232d9aef1b901
BLAKE2b-256 43ea2d87c0611fd25d98e118d3640edc87669282922f68ea91dd06a76618ef86

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11636195289cc23dd98957cbb83940689757aa6090f5c91a83ede630b523a3cd
MD5 55cf30777c0775411bd80c3686f1eff2
BLAKE2b-256 7745145b9fb083a13a6f0c74671acf088a0f8521c8325d92c4a65ca37ead54af

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f35c18b66ecfb5f6b04060256ace6e3d26abf7243f8cda42a884ce9ebdaa2702
MD5 9d87909356576591376dec424568561e
BLAKE2b-256 07e69cf95c130c956a505ca42dcac90bc20beb7874db6cc0262335ac02a35f7b

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.1.0a7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.3 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.1.0a7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8c65778a133668b7869d4c1a036ff963bd462dcffcea54515412786d537825b5
MD5 9d70f984c23e490a8560662f3c0ffe0a
BLAKE2b-256 69e12ca6d30be5a3dd69f9b22d3bb412473fae6ed5e61f4a4e1b1725875d3ce6

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da42e825a7c40cd480b02714297cd193ffe8736d630c1b3cb5a6493af1f0a27b
MD5 2525306a4b843911c6eead3c974e90da
BLAKE2b-256 89339d9d93f427a480b2e3d75d7c18fa06971ae43a2bb8c3f3f8f659efd6f0f0

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c4f3425a5c04284f9a5b07459241f43e0e50bee0d0ae87470b6f96d1e2f7f4f
MD5 feeb340ad06648d540546660b20fe61e
BLAKE2b-256 692ad22fc4c3cbf0123859ca5fdec90afc1dbbddbd3b7f19307c31866aac729b

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.1.0a7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.3 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.1.0a7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e3b1a353ecd1352bebb335c3bcefd81298acb1cbf2bdb56e91a6858aa9b5c3f2
MD5 6990379033b306df9c4816d876e576fc
BLAKE2b-256 b357907b3e50c1630151cf250ae00e202a6f3c5537783b9f78a6c676c29d32a1

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e2013469e726a520a920efeda7a11ea06df030f62eec64b945e8491bc3873be
MD5 b90978b4bfb398d3bace9109871592ee
BLAKE2b-256 84a22d0e496274d40228fb4d95e6bc5458f10026796406a5a51e5636fca48c44

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0085d92a2e83b1b653848cdf80bfe1d99b84649138ef2457181ff6d4dcfb8a0a
MD5 82cc5a9b48663b1e1751aae227a03b58
BLAKE2b-256 6c9fd2d4db266266eef7b5c0f3ed488023763abcff76a0ef33d4b873d48a61a0

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gamrs-0.1.0a7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.3 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.1.0a7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f730092fa8f71140bf3f6e4c24f3a888e6455110af349764900cf60644a3ce90
MD5 b220dd676e351447e41a9a2c72dde4a0
BLAKE2b-256 a60bd7b639f3fc2d6075c27af63a6afe587d9eb5b77d5b3a0e3f25d26a4f96d6

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01826a7cfbbdc9e24a07c0751b9da666f46bf83af195364c0dc1b047c91b712f
MD5 2f5c1fd2b0a0e0445245dfccbfa1ad84
BLAKE2b-256 a007b3090e2596775591d7d08c52f73e8eab2679f97eda7f7d4ca41102371ac9

See more details on using hashes here.

File details

Details for the file gamrs-0.1.0a7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamrs-0.1.0a7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 48ea38f1bb5beafbdd3c45184e567c5a399dca725ca931d6de7bb00b0d74b8d7
MD5 9426290eed5aa7243124b15a1fb3bf1a
BLAKE2b-256 96260720a6ea7d4a5ba2dc43d74cd5958034acd1f143f594fe5ba0e55af89fff

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