Expand description
Shared, source-agnostic builders for saved-model payloads.
The CLI (src/main.rs) and the Python FFI (crates/gam-pyffi/src/lib.rs)
both persist fitted models, and both used to assemble the serialized
FittedModelPayload independently. That meant the on-disk contract for a
given model kind could silently drift depending on whether the model was
created through the CLI or through Python — exactly the failure mode that
repeatedly bit the marginal-slope save→load path.
This module assembles the semantic payload exactly once. Each caller is
responsible only for the source-specific work of producing the resolved
semantic inputs (the CLI threads them through from its argument parsing and
fit pipeline; the FFI freezes term collections from designs and re-derives
metadata from the [FitConfig]). Once both sides hand the same semantic
content to the same assembler, payload drift becomes impossible by
construction.
Structs§
- Bernoulli
Marginal Slope Inputs - The resolved, source-agnostic semantic content of a Bernoulli marginal-slope saved model.
- Latent
Window Inputs - Source-agnostic semantic content of a latent survival / latent binary saved model. The caller resolves the family (splicing the learned latent SD into the persisted frailty for survival) and the model-class / likelihood labels.
- Location
Scale Inputs - Source-agnostic semantic content of a (non-survival) location-scale saved model — the shared core behind the CLI’s Gaussian/binomial save paths and the FFI’s two location-scale builders.
- Location
Scale Wiggle - Optional link-wiggle metadata persisted alongside a location-scale model.
Knots/coefficients are already in raw response units — the Gaussian
standardization and its inverse remap live inside
fit_gaussian_location_scale_model, so the save path persists them verbatim. - Saved
Model Source Metadata - Source-specific metadata that the CLI and FFI populate differently but that every saved payload carries.
- Survival
Location Scale Inputs - Source-agnostic semantic content of a survival location-scale
(Royston-Parmar with a learned residual link) saved model. Centralizing
fixes the drift where CLI and FFI disagreed on
formula_noise,baseline_timewiggle_*, andsurvival_noise_projection_ridge_alpha. - Survival
Marginal Slope Inputs - Source-agnostic semantic content of a survival marginal-slope
(Royston-Parmar net) saved model. Centralizing assembly also fixes the
FFI’s prior omission of the
*_logslopes/*_columns/formula_logslopesvector mirrors the CLI wrote. - Survival
Timewiggle - Snapshot of the baseline-timewiggle block persisted with a survival model.
- Survival
Transformation Inputs - Source-agnostic semantic content of a survival transformation (Royston-Parmar) saved model — net single-cause or joint cause-specific.
- Transformation
Normal Inputs - The resolved, source-agnostic semantic content of a transformation-normal saved model.
Enums§
- Location
Scale Response - Which likelihood a (non-survival) location-scale model carries: Gaussian
(residual response scale) or binomial (noise scale-deviation transform whose
likelihood is resolved from the inverse link). The assembler resolves the
FittedFamilyfrom this once, rather than each save path stamping a (potentially wrong) likelihood and patching it afterwards. - Survival
Timewiggle Beta - Fitted baseline-timewiggle coefficients: a single block (net) or one per cause (joint cause-specific). Callers pass already-sliced coefficients.
Functions§
- assemble_
bernoulli_ marginal_ slope_ payload - Assemble the canonical Bernoulli marginal-slope payload.
- assemble_
latent_ window_ payload - Assemble the canonical latent survival / latent binary payload.
- assemble_
location_ scale_ payload - Assemble the canonical (non-survival) location-scale payload — single source
of truth for that on-disk contract. The family/likelihood is resolved from
the
LocationScaleResponseso the binomial branch never persists a wrong probit likelihood that a caller must patch afterwards. - assemble_
residual_ cascade_ payload - Assemble the canonical residual-cascade payload (#1032).
- assemble_
spline_ scan_ payload - Assemble the canonical spline-scan payload (#1030/#1034): a standard
Gaussian-identity model whose fit representation is the exact O(n)
smoothing-spline smoother state instead of a dense
fit_result. The CLI and FFI save paths both route through here so the scan on-disk contract cannot diverge between sources. - assemble_
survival_ location_ scale_ payload - Assemble the canonical survival location-scale payload (the single source of truth for that on-disk contract).
- assemble_
survival_ marginal_ slope_ payload - Assemble the canonical survival marginal-slope payload — single source of truth for that Royston-Parmar / Gaussian-residual on-disk contract.
- assemble_
survival_ transformation_ payload - Assemble the canonical survival transformation payload — single source of truth for the Royston-Parmar transformation on-disk contract.
- assemble_
transformation_ normal_ payload - Assemble the canonical transformation-normal payload.
- serialize_
anchored_ deviation_ runtime - Serialize an anchored-deviation
DeviationRuntime(score-warp or link-deviation block) into its persistableSavedCompiledFlexBlockform.