Skip to main content

FittedModel

Enum FittedModel 

Source
pub enum FittedModel {
    Standard {
        payload: FittedModelPayload,
    },
    LocationScale {
        payload: FittedModelPayload,
    },
    MarginalSlope {
        payload: FittedModelPayload,
    },
    Survival {
        payload: FittedModelPayload,
    },
    TransformationNormal {
        payload: FittedModelPayload,
    },
}

Variants§

§

Standard

Fields

§

LocationScale

Fields

§

MarginalSlope

Fields

§

Survival

Fields

§

TransformationNormal

Fields

Implementations§

Source§

impl FittedModel

Source

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.

Source

pub fn from_payload(payload: FittedModelPayload) -> Self

Source

pub fn payload(&self) -> &FittedModelPayload

Source

pub fn likelihood(&self) -> LikelihoodSpec

Source

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).

Source

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.

Source

pub fn predict_model_class(&self) -> PredictModelClass

Source

pub fn saved_baseline_time_wiggle( &self, ) -> Result<Option<SavedBaselineTimeWiggleRuntime>, FittedModelError>

Whether this model has a link wiggle component with complete metadata.

Source

pub fn has_baseline_time_wiggle(&self) -> bool

Whether this model has a baseline-time wiggle component with complete metadata.

Source

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.

Source

pub fn saved_prediction_runtime( &self, ) -> Result<SavedPredictionRuntime, FittedModelError>

Source

pub fn saved_sas_state(&self) -> Result<Option<SasLinkState>, FittedModelError>

Source

pub fn saved_beta_logistic_state( &self, ) -> Result<Option<SasLinkState>, FittedModelError>

Source

pub fn saved_mixture_state( &self, ) -> Result<Option<MixtureLinkState>, FittedModelError>

Source

pub fn saved_latent_cloglog_state( &self, ) -> Result<Option<LatentCLogLogState>, FittedModelError>

Source

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.

Source

pub fn unified(&self) -> Option<&UnifiedFitResult>

Access the unified fit result, if stored.

Source

pub fn load_from_path(path: &Path) -> Result<Self, FittedModelError>

Source

pub fn save_to_path(&self, path: &Path) -> Result<(), FittedModelError>

Source

pub fn require_data_schema(&self) -> Result<&DataSchema, FittedModelError>

Source

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.

Source

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.

Source

pub fn random_effect_group_columns(&self) -> HashSet<String>

Source

pub fn validate_for_persistence(&self) -> Result<(), FittedModelError>

Source

pub fn validate_numeric_finiteness(&self) -> Result<(), FittedModelError>

Methods from Deref<Target = FittedModelPayload>§

Source

pub fn set_training_feature_metadata( &mut self, headers: Vec<String>, feature_ranges: Vec<(f64, f64)>, )

Source

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

Source§

fn clone(&self) -> FittedModel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for FittedModel

Source§

type Target = FittedModelPayload

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for FittedModel

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for FittedModel

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for FittedModel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V