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.4.0.tar.gz (3.5 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.4.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (886.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14Windows x86-64

gamrs-0.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (884.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.4.0-cp314-cp314-macosx_11_0_arm64.whl (703.9 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

gamrs-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (884.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (703.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gamrs-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (883.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (703.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gamrs-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (885.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (706.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

gamrs-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (887.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (889.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for gamrs-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6e22d38a3be1252d1063ed1a392d18af3db0a86d662e36dff6d0e2d805590bf6
MD5 a0440440aeff159f2869f6b439d55c30
BLAKE2b-256 2b0bb3467ba62911e4b809c92e38d958ea861a8cb8341d2e6cc480c03ec5294f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8320d00f724b71ece500570b880a1e594121982a59e781e643d626de23e75b7f
MD5 0d8816726f6889d1b2c8cb878918b002
BLAKE2b-256 1ad07a6da4e1f93ba20f631a23081aa1f2d45a62cc8794b78786a88ef54e0efc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.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.4.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1d6e919fc219321b47e07da23f15a76995a48ee8cc30d841b035b0bdb1041ecf
MD5 0e63ad513c956a71713c403c7ebc806b
BLAKE2b-256 c627e9223b3ce82ddd50a37d1ca4e0213c2ee2c16a5bc9bcee2cfb7450bd1402

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9bb92ef3024d4aae7db1d32f0476f05355e39eb5fd5edc9f5e4adf3630b5cfa6
MD5 d39b5096e1654607e71cc2f811672a51
BLAKE2b-256 7c312e12c2703056a936657ef4bf6623b5a1726604ddf7ad7244f451bddd8052

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b9594688937c3e709c68560af1d0fb22bf9add5a198d95de8a38f63b7b4ac19
MD5 662b3c92e2a83c6d67788de35c6c5665
BLAKE2b-256 e6ef0513bcff437cba412998fc0de96f22d5d3d781f5441470261e830cfa7289

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.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.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4691905aa19521d092b6ca8bbe98576c5f2b918a0496686cc418c94f97451612
MD5 6df1ddcc5e6fb2cdde615455a313a7fd
BLAKE2b-256 dde03068518ac4189cffb8b14c2ac0e54e90cefa1f78c9b682ff8cb3c6b9a313

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 015f4e1ef22d32e36de14eb79182523a876afee52177c91a0bb642176c46e3db
MD5 bb14344bb4e5a2766b39cb00bb750c6a
BLAKE2b-256 cf906dba894a1ed92d1f359f571bcc67d18f2a585803f55d19c29a73c2734a74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da404157ab6e372efde321d5e7f70fb09ae3225b7f97f85c76dcbf1207d597d8
MD5 274525b524281a698a1a9a092e6a9a75
BLAKE2b-256 a12bd7c22eddd290869692dd37287f41541228d357d397389cd8d2b4fc01f988

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.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.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 09aef58ce3122c983c27b57af4686dad8218e92e3491ed472058a7e761b213d5
MD5 c3a01e9dc85e7b2c83022638abc43c39
BLAKE2b-256 cf4783890b70badc3ab8324a2a3adba1f787ad25bebbc9317c5b4f0f9a4cad6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 91c9437cbd1cd6e432b55e5d8a1b303a71b22f9a726c3569777e09e1b2c4f97a
MD5 192dd0bbbd7b621a435cc1a2e5c294d0
BLAKE2b-256 ce8bfa2428cb69fd35e7870e4c5be7a1b926f2741fa800cf04d3702c70d8fad1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83f81e3f716e6b5c5d2d68036d16e43ac3b88930e226856c24b60774069ab0c6
MD5 9ea1cb822cd277432b4c996fd634dd4d
BLAKE2b-256 c1a00a27361448f28f7cbd96cdc75208082109452ae61ec2b11121f5ccf21a62

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.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.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 672b676e48c82a46ca358d2716e96590d82aed09149889950c7d0f8a4672d74b
MD5 690bc2e3a255cf1850470c6e25571c32
BLAKE2b-256 89d029d7e8786037cf785aa75b6097276027b9b7fa3532096bcf6f86ce6f1074

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 015d58cd9faa507af4c016c5a13615bf038c297cc5ba97e9e8179c53a548e814
MD5 f6a006f380366b36cc917b7db7950d7d
BLAKE2b-256 67864a346c944b0cc8e482acc80002a3f668279529a626874832da359e114204

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af9562fd287dda5e59d31d936fd60cf96025f30a6a0457645aab7f1f0be33fd7
MD5 773afd9f5589f0fe6e91a248ca70052e
BLAKE2b-256 651750d1b5712507b33155aa611dfd4749387505d6399a7912f9a21e4288fdd4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.4.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.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 57833bde3764ee63bf3523629892746883f163dd7eb95ab885959dc7655120af
MD5 3d14b26ce95506be8d797ccd57588f9b
BLAKE2b-256 2131413751cfb1980c27518ce7943dda0297dba3c7c868860e6bfe9f0001d8ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11d75aa071c10ba8b79d090cc5311e185882d71cbaa2b29caca6097eaa3922e6
MD5 6a96c7e1e91e6f15ede6c137d0208e12
BLAKE2b-256 58bc843a42e5e097325b0197c7ab235368931a0a5902fd2f988192996661da2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54b1606b6bb225d5df138d3c5f7345787f31f791b8b1f530d0b3aada39f08072
MD5 34f621e1d41fee7236f76822e2e05176
BLAKE2b-256 50514ef2fad2662bbbd846f1a4971dd41359cd3517ed8e567a7c577dc06ad34a

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