Skip to main content

NoiseModel

Enum NoiseModel 

Source
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

Fields

§sigma: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Per-observation standard deviation.

§

Poisson

§

Tweedie

Fields

§phi: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Per-observation dispersion φ (> 0). A scalar-dispersion fit broadcasts one value to every row; a dispersion location-scale fit (#913/#1125) supplies the fitted per-row φ = 1/exp(eta_d(x)).

§

NegativeBinomial

Fields

§theta: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Per-observation overdispersion θ (> 0); see Tweedie::phi.

§

Beta

Fields

§phi: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Per-observation precision φ (> 0); see Tweedie::phi.

§

Gamma

Fields

§shape: ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>

Per-observation Gamma shape k (> 0), with mean-driven scale; see Tweedie::phi.

§

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

§probabilities: ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>
§

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: CtnTransformTable

The fitted transform and its tails, one row per observation.

Implementations§

Source§

impl NoiseModel

Source

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.

Source

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

Source§

fn clone(&self) -> NoiseModel

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 Debug for NoiseModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<C> CloneExpand for C
where C: Clone,

Source§

fn __expand_clone_method(&self, _scope: &mut Scope) -> C

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoComptime for T

Source§

fn comptime(self) -> Self

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<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<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<T> TuneInputs for T
where T: Clone + Send + Sync + 'static,

Source§

type At<'a> = T

The concrete input type at lifetime 'a.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more