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.0.tar.gz (868.8 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.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (836.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.3.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (835.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.3.0-cp314-cp314-macosx_11_0_arm64.whl (686.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (835.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (686.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (835.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (686.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (837.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (688.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (839.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (842.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for gamrs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cd4c73bc26fc1c59fdc5f649cd354c9a70dff8ebbf72a0cc881524ed53ddecc6
MD5 0ad023d43d83fb63f9f1c56b8d55bce2
BLAKE2b-256 a80dceb67f8e1d4a0b0e1985e1ca11f8a76461afea7a2443f76d70e5b2d358e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09e6bf610167249315729bbdde08ad92d4a96eb7104273bb07667ca20cf57a69
MD5 5b91cd799ae2211e327cdae1c594c873
BLAKE2b-256 bd28ce16c9b7e421aeeac1ea4cac831fba1ed1d25e40576ea400b840b8b88f58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.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.3.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 06a9d201171b552f2bf10b1463749cecd938ffcc09cb343ac370ccc4565bf176
MD5 b37460786db5976a0065270398d754b8
BLAKE2b-256 c19625adcef4a7d9ba5a718e9eb429e290cb8d084dc648e6d82d4efed19a9af7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a06472543af82c789ecc6aeabfbd3015057d8c10f8314462670d633f0a9f6792
MD5 2ab01c33001a8c4b9b7c6c9ad802bec1
BLAKE2b-256 a82df8fd17de313a9ecbda29befcd508bc1cd0c3b96ab7a6d5e32fd705e531c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c80fc692c3701f5c9ba808b819bee6f0228e42344d8b9671aeeccaa6063a84eb
MD5 0c1bede92ed83da7eb5f90a6c9aee522
BLAKE2b-256 ad6289f2c01203f9313aceec17c23e6e24bc14d7a931886c4192895a3c749644

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.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.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 74e9c4d0a319922dcaa99fb28cc261b652a079025386a6677fcf2d40a7ea773e
MD5 e3265fb707367fe9a3421b7c2878e22c
BLAKE2b-256 ddb10e0293abb01fcaea3a457e2ffe57f217be691a2adf883a4420fbc1388221

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82568b74684dd4366240548113cf70ff54a84e6520bffbf435c94d24caf54918
MD5 c121fe13852643d90e72b2c846f81d23
BLAKE2b-256 ab1645fb3dba34611165f9dd0d8e5bf8ada0d15c445ff17423b78d89b5fe9647

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43cf7fa7c4f42f3a6d81fc94944b00923646da5d487534a25cee7ce260db338a
MD5 063483b29168c6b71270a03867d049c0
BLAKE2b-256 45e27d3d0fb0642c87f40cd09cd51c883e67424566cc5ef58d66d80eb203d62f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.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.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 59642c24009aef23f7ebcf344ffe80e36822f939ada91bb34cefd125d2c372d0
MD5 957adc52483e55481f16eab4cd045028
BLAKE2b-256 611f76739b73b7f685e68e8c3de8c0483b758dd37cf4a6efc9f3b02472b3c8a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9e2b91d2ba337d5c2f582b84466211eeb6a1af74f99d7a5beadc9a3f6ddd784
MD5 5a33cc763fc9ee5a2dc6b5b5569f3e0f
BLAKE2b-256 be7bb3618b941356d0f76bd6b229848ccae3f013e5e4594bcd4e1ef2082f93cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 327a205568cef4d13e1bc70e5f009ff32b8a9eb185f8e4be63c7dfa2ec1c565c
MD5 9c8e2c0d311647a4e6d136315556a4af
BLAKE2b-256 d8cb7d99a8023ec7e53a901728946a299e9e4abaa24df706858107e2a3533f01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.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.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4c95315761e7f080fba2ae0713d0bf2ae7664e9b34fe8cdebaed24ea128732d7
MD5 323f2732c850a19a605f55ecad164d7c
BLAKE2b-256 fede50776899be0d60ed57b43d7385365675f4ded3c998afeffd3b426e7865e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc5ec515efab0ac7a8185a243b38b5dd9e6b8487aee0534b42760f1adfa7099f
MD5 563445d77e21cd15cb8144a3cb354261
BLAKE2b-256 2f65d5dac7a120962cd1e251f50fffdf69dadba6fbd12a83457b78fa5d4f3e6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fd554e7e950cdabf6d3525560d2163a983c6131ed10c1060ad875a351fb31dc
MD5 21d02d52e88f075fd8ae2091875e2318
BLAKE2b-256 f2d0e8f46cb00eb8c3d803d7dd7e111a3857eed6808eafa459ad30fdab4ec6fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.3.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.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 33f0b67ca3df6f366bfa6b0f7cb620390bfb86e81754efff48a31247f6770990
MD5 5388284dc575b35f6f34c0d41a124065
BLAKE2b-256 205f016b5c3c34c6f210052b0583a9afc7c9c3f0456143304507b02425127619

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dce1fe7c4f6d89408fc9b3d024d3791273de5dcf83e3301724e42eaddaf37f71
MD5 e931b5624e519a391211dad49d1fc63b
BLAKE2b-256 98ffe0822753e87f82f57e4509ccae6fe62de1d62d77d77d2a6770ab48894f65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7f073a13871e26dc57eb510db43e535a42222e5d284662cb0fa90995b871c41
MD5 cff4147a9e3780017a5cedd8df8d657a
BLAKE2b-256 a46946776305db69b2b048d3f7b917370b5c11f9982055bb66e5e4dcea01a96a

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