pub enum NoiseModel {
Gaussian {
sigma: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
},
Poisson,
Tweedie {
p: f64,
phi: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
},
NegativeBinomial {
theta: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
},
Beta {
phi: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
},
Gamma {
shape: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
},
Bernoulli,
Categorical {
probabilities: ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>,
labels: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
},
TransformationNormalQuantile {
table: CtnTransformTable,
},
}Expand description
Observation-noise model used for generative sampling.
Variants§
Gaussian
Poisson
Tweedie
Fields
NegativeBinomial
Fields
Beta
Fields
Gamma
Fields
Bernoulli
Categorical
Row-specific categorical response law.
probabilities[[i, j]] is the fitted probability that observation i
takes labels[j]. This is the natural saved-response representation for
competing-risk event-window generation: label zero means no event in the
requested window and positive labels identify the persisted causes.
Fields
TransformationNormalQuantile
Inverse-transform sampling for a conditional transformation-normal (CTM)
model (issue #1613). The fitted latent transform h(·|x_i) is strictly
increasing in y and h(Y|x) ~ N(0, 1), so a response-scale draw is
Y = h⁻¹(Z | x_i) with Z ~ N(0, 1). The earlier generate path drew
Gaussian noise around the mean, which produced latent-scale draws whose
per-row mean moved the wrong way with the covariate; this variant instead
samples from the genuine conditional law F(·|x).
Both this sampler and the response-scale conditional mean E[Y|x] used by
predict (#1612) invert the SAME object — a CtnTransformTable, which
carries the tabulated transform together with the slopes of the two
affine tails it has outside the tabulated range — so the two paths cannot
disagree on the underlying transform, and neither of them can truncate
the predictive law at the training range.
That truncation is what this variant used to do: a latent draw past
h(y_hi|x) — which happens with the model’s own probability
1 − Φ(h(y_hi|x)), around 1/(n+1) for a calibrated fit — returned the
support endpoint, so y_lo and y_hi were atoms of the sampled law
(gam#2600).
Fields
table: CtnTransformTableThe fitted transform and its tails, one row per observation.
Implementations§
Source§impl NoiseModel
impl NoiseModel
Sourcepub fn from_likelihood(
likelihood: &LikelihoodSpec,
nobs: usize,
gaussian_scale: Option<f64>,
) -> Result<NoiseModel, EstimationError>
pub fn from_likelihood( likelihood: &LikelihoodSpec, nobs: usize, gaussian_scale: Option<f64>, ) -> Result<NoiseModel, EstimationError>
Single canonical mapping from a fitted LikelihoodSpec (response
distribution + dispersion gaussian_scale) to the observation
NoiseModel used for generative sampling. Both simulation
(FamilyStrategy::simulate_noise) and generative inference
(generativespec_from_predict) route through this one helper so the
set of supported likelihoods and the interpretation of dispersion
parameters can never diverge between the two paths.
nobs is the number of observations the resulting per-observation
Gaussian sigma vector should span; it is ignored for families whose
noise carries no per-observation state.
Sourcepub fn from_likelihood_with_per_row_dispersion(
likelihood: &LikelihoodSpec,
dispersion: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
) -> Result<NoiseModel, EstimationError>
pub fn from_likelihood_with_per_row_dispersion( likelihood: &LikelihoodSpec, dispersion: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ) -> Result<NoiseModel, EstimationError>
Build the observation NoiseModel for a dispersion location-scale fit
(#1125) from a fitted PER-ROW dispersion surface dispersion[i] (the
predictor’s exp(eta_d(x_i)) mapped into NoiseModel units — NB θ, Gamma
shape, Beta φ directly, Tweedie φ as the reciprocal). Unlike
from_likelihood, which broadcasts a single scalar dispersion to every
row, this threads the genuine per-observation precision channel so
generated data reproduces the fitted non-constant dispersion instead of
coming out homoscedastic at the seed.
Trait Implementations§
Source§impl Clone for NoiseModel
impl Clone for NoiseModel
Source§fn clone(&self) -> NoiseModel
fn clone(&self) -> NoiseModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for NoiseModel
impl RefUnwindSafe for NoiseModel
impl Send for NoiseModel
impl Sync for NoiseModel
impl Unpin for NoiseModel
impl UnsafeUnpin for NoiseModel
impl UnwindSafe for NoiseModel
Blanket Implementations§
impl<T> Allocation for T
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<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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.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.