Skip to main content

Module model_payload_builders

Module model_payload_builders 

Source
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§

BernoulliMarginalSlopeInputs
The resolved, source-agnostic semantic content of a Bernoulli marginal-slope saved model.
LatentWindowInputs
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.
LocationScaleInputs
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.
LocationScaleWiggle
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.
SavedModelSourceMetadata
Source-specific metadata that the CLI and FFI populate differently but that every saved payload carries.
SurvivalLocationScaleInputs
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_*, and survival_noise_projection_ridge_alpha.
SurvivalMarginalSlopeInputs
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_logslopes vector mirrors the CLI wrote.
SurvivalTimewiggle
Snapshot of the baseline-timewiggle block persisted with a survival model.
SurvivalTransformationInputs
Source-agnostic semantic content of a survival transformation (Royston-Parmar) saved model — net single-cause or joint cause-specific.
TransformationNormalInputs
The resolved, source-agnostic semantic content of a transformation-normal saved model.

Enums§

LocationScaleResponse
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 FittedFamily from this once, rather than each save path stamping a (potentially wrong) likelihood and patching it afterwards.
SurvivalTimewiggleBeta
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 LocationScaleResponse so 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 persistable SavedCompiledFlexBlock form.