pub enum FittedModel {
Standard {
payload: FittedModelPayload,
},
LocationScale {
payload: FittedModelPayload,
},
MarginalSlope {
payload: FittedModelPayload,
},
Survival {
payload: FittedModelPayload,
},
TransformationNormal {
payload: FittedModelPayload,
},
}Variants§
Standard
Fields
payload: FittedModelPayloadLocationScale
Fields
payload: FittedModelPayloadMarginalSlope
Fields
payload: FittedModelPayloadSurvival
Fields
payload: FittedModelPayloadTransformationNormal
Fields
payload: FittedModelPayloadImplementations§
Source§impl FittedModel
impl FittedModel
Sourcepub fn axis_clip_to_training_ranges(
&self,
data: ArrayView2<'_, f64>,
col_map: &HashMap<String, usize>,
) -> Option<Array2<f64>>
pub fn axis_clip_to_training_ranges( &self, data: ArrayView2<'_, f64>, col_map: &HashMap<String, usize>, ) -> Option<Array2<f64>>
Axis-clip each continuous new-data column to the (min, max) range
observed in training. Categorical and binary columns are left
untouched so unseen levels surface rather than being silently remapped
onto seen ones. Returns Some(clipped_copy) only if at least one
value was actually clipped; otherwise None so callers can avoid
owning a redundant copy. Pre-2026-04-29 model JSONs that lack the
training_feature_ranges field deserialize to None and pass through
unchanged.
pub fn from_payload(payload: FittedModelPayload) -> Self
pub fn payload(&self) -> &FittedModelPayload
pub fn likelihood(&self) -> LikelihoodSpec
Sourcepub fn prediction_required_columns(&self) -> Result<BTreeSet<String>, String>
pub fn prediction_required_columns(&self) -> Result<BTreeSet<String>, String>
Columns this model consumes from a prediction frame — its input contract.
Every variable named by the main formula (features, interaction margins,
random-effect groups, and a smooth’s by= column), the survival
entry/exit columns or the transformation-normal response, the auxiliary
noise / logslope formula columns, and the offset / noise-offset /
latent-z columns. The event-indicator and the plain response of a
standard model are deliberately excluded: they are not needed to form
a prediction (the conformal-calibration fold layers the response back on
separately).
This is the single authority shared by the CLI and PyFFI predict paths. A prediction frame column that is not in this set is irrelevant to the model and must be ignored rather than strict-encoded against the training schema — otherwise an unrelated ID/label column with a held-out categorical level aborts predict (#840).
Sourcepub fn diagnostic_extra_columns(&self) -> Result<Vec<String>, String>
pub fn diagnostic_extra_columns(&self) -> Result<Vec<String>, String>
Columns a post-fit diagnostic command (diagnose / sample / report)
needs beyond Self::prediction_required_columns.
Prediction deliberately drops a standard GAM’s bare response so a
prediction frame may omit it (#840 / #864). Diagnostics are statements
about that observed response — residuals, R², posterior likelihoods,
leave-one-out — so the response must be present. This returns the bare
response column when the prediction projection would otherwise drop it,
and nothing when the response is already prediction-required (survival
Surv(...) time/event columns, the transformation-normal response) or
is not a plain data column.
Centralising the intent here is what makes it structurally impossible
for a diagnostic command to silently drop the response: callers use
load_dataset…_for_diagnostics, which always folds these in, instead of
each remembering to thread an extra_required response by hand.
pub fn predict_model_class(&self) -> PredictModelClass
pub fn saved_link_wiggle( &self, ) -> Result<Option<SavedLinkWiggleRuntime>, FittedModelError>
pub fn saved_baseline_time_wiggle( &self, ) -> Result<Option<SavedBaselineTimeWiggleRuntime>, FittedModelError>
Sourcepub fn has_link_wiggle(&self) -> bool
pub fn has_link_wiggle(&self) -> bool
Whether this model has a link wiggle component with complete metadata.
Sourcepub fn has_baseline_time_wiggle(&self) -> bool
pub fn has_baseline_time_wiggle(&self) -> bool
Whether this model has a baseline-time wiggle component with complete metadata.
Sourcepub fn prediction_uses_posterior_mean(&self) -> bool
pub fn prediction_uses_posterior_mean(&self) -> bool
Whether the default point prediction must integrate the inverse link
over the coefficient posterior — reporting the posterior mean
E[g⁻¹(Xβ)] — rather than plugging in the posterior mode g⁻¹(Xβ̂).
SPEC (issue #960): the posterior mean is always the default point
estimate (never MAP). It is observably distinct from the plug-in exactly
when the inverse link is curved over the posterior’s uncertainty, so
E[g⁻¹(η)] ≠ g⁻¹(E[η]) by Jensen. The curvature-based classification is:
- all log-link families (Poisson / Gamma / Tweedie / NegativeBinomial):
E[exp η] = exp(η + se²/2) ≠ exp(η)(log-normal MGF); - all Binomial links (logit / probit / cloglog / SAS / BetaLogistic / Mixture / LatentCLogLog): bounded sigmoidal inverse links;
- Beta (logit link):
E[σ(η)] ≠ σ(E[η]); - Royston–Parmar (curved survival-probability inverse link).
The integral collapses to the plug-in (so the cheaper plug-in path is
exact and taken instead) only for the effectively-linear identity-link
Gaussian. Any model carrying a link wiggle or baseline-time wiggle is
curved regardless of family. This curvature partition mirrors
families::family_runtime::posterior_mean, the compute path that produces the corrected mean for each of these families.
This is the single source of truth shared by the CLI (gam predict)
and the Python FFI prediction path so the two can never drift on which
models receive the posterior-mean correction.
pub fn saved_prediction_runtime( &self, ) -> Result<SavedPredictionRuntime, FittedModelError>
pub fn saved_sas_state(&self) -> Result<Option<SasLinkState>, FittedModelError>
pub fn saved_beta_logistic_state( &self, ) -> Result<Option<SasLinkState>, FittedModelError>
pub fn saved_mixture_state( &self, ) -> Result<Option<MixtureLinkState>, FittedModelError>
pub fn saved_latent_cloglog_state( &self, ) -> Result<Option<LatentCLogLogState>, FittedModelError>
pub fn resolved_inverse_link( &self, ) -> Result<Option<InverseLink>, FittedModelError>
Sourcepub fn measure_jet_extrapolation_variance(
&self,
data: ArrayView2<'_, f64>,
col_map: &HashMap<String, usize>,
) -> Result<Option<Array1<f64>>, FittedModelError>
pub fn measure_jet_extrapolation_variance( &self, data: ArrayView2<'_, f64>, col_map: &HashMap<String, usize>, ) -> Result<Option<Array1<f64>>, FittedModelError>
V∞ §5 producer: per-row measure-jet extrapolation variance on the η
scale for a prediction batch (docs/measure_jet_v_infinity.md).
For every frozen measure-jet term in resolved_termspec this prices
the off-support ignorance of the fitted multiscale spectrum at each
query row: support curve from the frozen nodes/masses/band
(gam_terms::basis::measure_jet_support_curve), fitted per-scale
amplitudes λ̂_ℓ read from the fit’s lambdas through the replayed
design’s penalty layout, folded through
gam_terms::basis::measure_jet_extrapolation_variance and scaled by
the fit’s coefficient-covariance scale φ̂ so the result sits on Vp’s
η-variance scale. Terms not yet frozen (no frozen_quadrature or
non-UserProvided centers) are skipped with a warning. Returns
Ok(None) when no measure-jet term contributes, so callers leave
PredictUncertaintyOptions::extrapolation_variance untouched.
data must be the RAW (unclipped) prediction matrix in prediction
column order — clipping to the training ranges would freeze the
distance signal at the hull and defeat the honesty contract — and
col_map the prediction header → column map (the same map handed to
the design builder). This is the minimal-plumbing producer seam: the
option-building callers (CLI predict, FFI) hold exactly
(model, data, col_map) at the point where they assemble
PredictUncertaintyOptions, and the fusion in
predict_gamwith_uncertainty adds the array AFTER its multiplicative
inflations: Var_total = Var_Vp·inflation + Var_extrap.
Sourcepub fn unified(&self) -> Option<&UnifiedFitResult>
pub fn unified(&self) -> Option<&UnifiedFitResult>
Access the unified fit result, if stored.
pub fn load_from_path(path: &Path) -> Result<Self, FittedModelError>
pub fn save_to_path(&self, path: &Path) -> Result<(), FittedModelError>
pub fn require_data_schema(&self) -> Result<&DataSchema, FittedModelError>
Sourcepub fn saved_spline_scan(
&self,
) -> Result<Option<(&str, SplineScanFit)>, FittedModelError>
pub fn saved_spline_scan( &self, ) -> Result<Option<(&str, SplineScanFit)>, FittedModelError>
Restore the exact in-memory spline-scan fit from a scan-bearing
payload (#1030/#1034). Ok(None) for dense models; the returned
predict replays the training Gaussian bridge bit-for-bit.
Sourcepub fn saved_residual_cascade(
&self,
) -> Result<Option<(&[String], ResidualCascadeFit)>, FittedModelError>
pub fn saved_residual_cascade( &self, ) -> Result<Option<(&[String], ResidualCascadeFit)>, FittedModelError>
Restore the in-memory residual-cascade fit from a cascade-bearing
payload (#1032). Ok(None) for non-cascade models; the returned fit
replays the multilevel Wendland-frame posterior for the d ∈ {2, 3}
feature columns at each predict point.
pub fn random_effect_group_columns(&self) -> HashSet<String>
pub fn validate_for_persistence(&self) -> Result<(), FittedModelError>
pub fn validate_numeric_finiteness(&self) -> Result<(), FittedModelError>
Methods from Deref<Target = FittedModelPayload>§
pub fn set_training_feature_metadata( &mut self, headers: Vec<String>, feature_ranges: Vec<(f64, f64)>, )
Sourcepub fn apply_survival_time_basis(&mut self, snapshot: &SavedSurvivalTimeBasis)
pub fn apply_survival_time_basis(&mut self, snapshot: &SavedSurvivalTimeBasis)
Write the persistable time-basis snapshot for a survival model.
This is the only path that should populate the survival_time_*
fields used by the loader. Routing every FFI builder through this
helper guarantees no builder can silently drop a field — the
marginal-slope save→load bug was a builder that
missed survival_time_basis.
Trait Implementations§
Source§impl Clone for FittedModel
impl Clone for FittedModel
Source§fn clone(&self) -> FittedModel
fn clone(&self) -> FittedModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Deref for FittedModel
impl Deref for FittedModel
Source§impl DerefMut for FittedModel
impl DerefMut for FittedModel
Source§impl<'de> Deserialize<'de> for FittedModel
impl<'de> Deserialize<'de> for FittedModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !RefUnwindSafe for FittedModel
impl !UnwindSafe for FittedModel
impl Freeze for FittedModel
impl Send for FittedModel
impl Sync for FittedModel
impl Unpin for FittedModel
impl UnsafeUnpin for FittedModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.