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.5.2.tar.gz (3.6 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.5.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (977.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

gamrs-0.5.2-cp314-cp314-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.14Windows x86-64

gamrs-0.5.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (979.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

gamrs-0.5.2-cp314-cp314-macosx_11_0_arm64.whl (814.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

gamrs-0.5.2-cp313-cp313-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.13Windows x86-64

gamrs-0.5.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (975.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gamrs-0.5.2-cp313-cp313-macosx_11_0_arm64.whl (810.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gamrs-0.5.2-cp312-cp312-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.12Windows x86-64

gamrs-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (975.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gamrs-0.5.2-cp312-cp312-macosx_11_0_arm64.whl (810.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gamrs-0.5.2-cp311-cp311-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.11Windows x86-64

gamrs-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (977.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gamrs-0.5.2-cp311-cp311-macosx_11_0_arm64.whl (813.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gamrs-0.5.2-cp310-cp310-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.10Windows x86-64

gamrs-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (980.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gamrs-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (982.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for gamrs-0.5.2.tar.gz
Algorithm Hash digest
SHA256 310158f28a5773422df8401371b68e86aecf28348b64fb6a938602a7bbce19ec
MD5 65eca35d83933e7beab73ddc5b52e73d
BLAKE2b-256 3ac49e8cb8e54cdabf4b7e21d33be5608ef471fcc9b74322fcbe1641a682a8a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3a7f5177faceab6f1d1ebf747cdf2f17bfbbf76c0844589b8443d5be41c3624
MD5 d1cf4bcf69399a6d4aafb0c15b80c03e
BLAKE2b-256 1a84ef8f44accdf43e6ae6a1c847d410968527c9cf4b100f9ed8e10b8af6e5e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.5.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 7133c5cd457097305de6080183d1e331560d68377626dd185145a699a73b63f9
MD5 3eb457be065ba978f7bd44d7bb8a8030
BLAKE2b-256 dd0a423d2cc74c490fc81b020e5b3b2763f04bb85880d5ca6b5edf0f7aab7138

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f397ecfdc7415a58f7aa564d6cab1de3509bb24e1a79d17bbe1aa70a8a230a23
MD5 6de928461e01e6594a9242889c56f6ef
BLAKE2b-256 36f264915213a4303f866301b59f29c7b07da31c6ee82d8db06bf83bedaa1b3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8481dc838f6170e18d46bed5b57db4d3276c1074eb93183641e22a9e24758a19
MD5 23b51a12391de3a86278512fbb097a11
BLAKE2b-256 9ca309551b3591d84e5d06d346718a8f599280404099aa8265311e715f9c9c23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.5.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 700f79be8dba6c71936c405770e2310e24734cae8df64da5e795bb2e15885907
MD5 30c701f7a4b63e76c24bc3147893fe46
BLAKE2b-256 9e535ee33d43795f552c97e7dcbccc3025d4f608de76ec98cf1d8ad459fe8ebd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c021c6001fbeb7f101c9328a4c2981cc56d01f232a50286b87bd2f8b75b5e376
MD5 de86a47c579a30bb4d0e3a39f43f900e
BLAKE2b-256 072acb0c922eef39c8cbd1683c75fcdf7524ef3638d3b28e7d43c8f1b221b6cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33b8b8e1d05e3c9c90d42f1e6bb9947cd76deb9873060899b578c39f125eed02
MD5 a2002993bf5a4ca5725b5f829119610c
BLAKE2b-256 02b9f7963b17ece14c17ff9af7bd81a79b373b312637e6aa8f3481bfbb13a70f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.5.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8361e5193a81a2707f6cb130d8a0fc59740cef49f72321ac3d8f47c02ee0f67c
MD5 ea4dc1f5400bc70ac46e9031fcd7fb53
BLAKE2b-256 10e7254954fe9e431d6df0b929e8691701f4bddc7592446177170a56cda1d4b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0229ac601f132236bcf9c8bfee4795b3b662222a56b0c2a815854ca08bead986
MD5 cce4f5a75c326b9ae3050a9ef75f8e44
BLAKE2b-256 4ff627c92286ffb80e4a6114917b7760fb58c7937c9b71e7f8c8adc660ae3ba5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c88e0df98479db8ef1f3d57bb967ee3f8dd97627d918bed78a8c0acca4f2f094
MD5 8ac740e4e1e741277d9dec7d7222f472
BLAKE2b-256 2c09cd143041239912af0f9f3c82bfdbe86e4c2789e835fdcef37e75dd7de904

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.5.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cc34ccf91788931e736a48ff2ead55cfccad4c8f05e9e3f3e86884d1e24f67a1
MD5 88a2a3875694714b55e07f4b570941a8
BLAKE2b-256 171b89e5b0f0f03acef128f04fe4d95d8988177aa9233bc365bc09f29d637570

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 154c86ae57b382cb2f096ede960045a9fd86199e6974454d2d078c9b39b0d918
MD5 5e1e3ffd4c63a4a6439fbac63440c2a5
BLAKE2b-256 3efaa8545eeff076f097a225e310d0232fcb9ff9736f8e670d8f878f83e99450

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a72e93714b37b966aba732f639f5a769ebc3fa73fc8e3e44ebc616a2fc69e24
MD5 82cefa873f1ce438d02be23d496c71aa
BLAKE2b-256 c76215153e0244f1e56515344aca743de7f1bd4c96943c5abca6f0847083af71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamrs-0.5.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d7f86bb578d86a4a03b90148fad0f2ea0805dc4c5b608c1bb70a0b759075c406
MD5 0c30395d235ee5e1f37c364d221ac233
BLAKE2b-256 a0d4eb0dfb9df2211651b3aec521b3e2d9f42d7cf3901b49f33b877d6dfe5845

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c14e4e3f41013824c7bbcdff0f31242dfeff76a7e2687b00ba73f30036a1082
MD5 bdc8a113205bc3fd9f513adaeedda13b
BLAKE2b-256 01ab38b197fd59236a83d3ff58cbc14ef838db17b37a749eb2318655f48de459

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamrs-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c7ac50c91caaaa6f1c57159528551af36182959dcc5c594c49c82983f2a4912
MD5 4e4f4f813bd7c761aa2d48896d203d61
BLAKE2b-256 a0a7a0eb82757bcca8354f864a51934e2ccb098a7538eff438fdd266b9c2da84

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