Skip to main content

RhoPrior

Enum RhoPrior 

Source
pub enum RhoPrior {
    Flat,
    Normal {
        mean: f64,
        sd: f64,
    },
    GammaPrecision {
        shape: f64,
        rate: f64,
    },
    PenalizedComplexity {
        upper: f64,
        tail_prob: f64,
    },
    Independent(Vec<RhoPrior>),
}
Expand description

Fixed prior family for smoothing parameters in joint HMC refinement.

Variants§

§

Flat

§

Normal

Fields

§mean: f64
§sd: f64
§

GammaPrecision

Gamma(shape, rate) conjugate hyperprior on the precision lambda = exp(rho).

The deterministic REML/LAML objective uses the MAP-in-lambda convention and is minimized, so this contributes rate * exp(rho) - (shape - 1) * rho up to an additive constant. Samplers over rho include the +rho Jacobian from lambda = exp(rho), so their log-density contribution is shape * rho - rate * exp(rho). For a block with effective dimension n_p and centered quadratic (beta - mu)'S_p(beta - mu), the conditional posterior is Gamma(shape + n_p/2, rate + quadratic/2) and the closed-form MAP precision is (shape + n_p/2 - 1) / (rate + quadratic/2). Gamma(1, 0) is the explicit flat/default case and reproduces the current MacKay/Tipping fixed point.

Fields

§shape: f64
§rate: f64
§

PenalizedComplexity

Penalized-complexity (PC) prior on the smoothing parameter (Simpson, Rue, Riebler, Martins, Sørbye, Statistical Science 2017).

A PC prior fixes a base model (here the infinitely-smooth limit, where the penalized component collapses to its null space) and puts an exponential prior on the distance away from it. For a Gaussian smooth with precision λ = exp(ρ) the relevant distance is the marginal standard-deviation scale d = λ^{-1/2} = exp(-ρ/2), and a constant-rate penalization p(d) = θ exp(-θ d) induces the closed-form log-prior

log p(ρ) = ln(θ/2) − ρ/2 − θ exp(−ρ/2).

The rate θ is calibrated by the single interpretable tail statement P(d > upper) = tail_prob, i.e. θ = −ln(tail_prob) / upper. The prior is reparameterization-invariant and shrinks toward the simpler model (an exponential wall against under-smoothing, only a gentle linear pull toward over-smoothing), which is exactly the Occam behaviour wanted for high-variance flexible components. The REML/LAML objective is minimized, so this contributes ρ/2 + θ exp(−ρ/2) (up to an additive constant) to the cost, with gradient 1/2 − (θ/2) exp(−ρ/2) and (always positive) curvature (θ/4) exp(−ρ/2).

Fields

§upper: f64

Upper bound U on the distance scale d = exp(-ρ/2) (the marginal SD scale of the penalized component) in the tail statement P(d > U) = tail_prob. Must be finite and strictly positive.

§tail_prob: f64

Tail probability α in P(d > U) = α. Must satisfy 0 < α < 1.

§

Independent(Vec<RhoPrior>)

Coordinate-specific priors for models whose smoothing parameters do not share one prior family, such as nested coefficient groups.

Implementations§

Source§

impl RhoPrior

Source

pub fn upper_tail_gradient_vanishes(&self, coordinate: usize) -> bool

Does this prior contribute nothing to ∂V/∂ρ_k in the λ→∞ (ρ_k → +∞) tail?

Every rail-reasoning path in the outer certificate — the analytic λ=∞ face form and the measured-tail probe alike — decides by the law

ĉ = −e^{ρ} ∂V/∂ρ   is CONSTANT along the tail,

which is a statement about a REML/LAML criterion, whose λ=∞ face gives ∂V/∂ρ = O(e^{−ρ}). It holds only when the criterion really is that one. Any ρ-prior whose own gradient survives into the tail adds a term the law does not model, ĉ diverges, and there is no λ=∞ face to certify at any box width (#2450: under Normal { 0, 3 } the measured ∂V/∂ρ → ρ/9 and ĉ → −ρe^{ρ}/9).

Carrying the answer here rather than re-deriving it at each consumer is the point: the previous consumer-side test was matches!(prior, Flat), which silently misclassifies the two other spellings of a flat coordinate.

True exactly for the families whose ρ-gradient is identically zero on the identified upper tail:

  • Flat — the REML runtime evaluates unset coordinates through the SELF-GATED, one-sided firth-default barrier, which is byte-identically flat above ρ = −2 ln(upper). The wall it does carry is on the other side, against the λ → 0 under-smoothing degeneracy.
  • GammaPrecision { shape: 1, rate: 0 } — exactly flat under the MAP-in-λ convention (cost, gradient and Hessian all vanish); the same “unset” coordinate as Flat, spelled differently.

False for every other family, each for a nameable reason: Normal leaves (ρ − mean)/sd² → ∞; PenalizedComplexity leaves its persistent +1/2 Occam pull; a GammaPrecision with rate > 0 leaves rate·e^{ρ}, which diverges faster than the law’s own scale.

coordinate indexes the ρ vector, so an Independent prior answers per coordinate — a face can be certifiable on one coordinate and not on another. A nested Independent is structurally invalid and answers false rather than pretending to know.

Source

pub fn upper_tail_gradient_vanishes_everywhere(&self, rho_dim: usize) -> bool

Does the upper-tail law hold on every coordinate of a ρ of length rho_dim? An Independent prior shorter than rho_dim is malformed and answers false.

Source

pub fn is_unset(&self) -> bool

Did the caller leave this prior UNSET, or did they configure it?

RhoPrior::default() is Flat, so “unset” and “explicitly asked for a flat coordinate” are the same value and deliberately indistinguishable — both mean the criterion is pure REML/LAML here, which is what any consumer of this predicate actually wants to know. What is NOT the same is a configured Normal / PenalizedComplexity / non-trivial GammaPrecision: that value is a modelling choice someone wrote down, and a subsystem that rewrites it is discarding an instruction (#2463).

Unset has more than one spelling. GammaPrecision { shape: 1, rate: 0 } is “the explicit flat/default case” by this enum’s own documentation — its cost, gradient and Hessian all vanish under the MAP-in-λ convention — so a matches!(prior, Flat) test silently misclassifies it as configured. Carrying the answer here rather than re-deriving it at each consumer is the point (#2427): the same question asked in three places must not get three answers.

An Independent prior is unset only when EVERY coordinate is, since a single configured coordinate is still an instruction. An empty Independent carries no instruction and is therefore unset.

Trait Implementations§

Source§

impl Clone for RhoPrior

Source§

fn clone(&self) -> RhoPrior

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 RhoPrior

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for RhoPrior

Flat, because the deterministic criterion is REML/LAML by contract.

SPEC: “REML (or LAML) always used for fitting, never GCV” and “posterior mean must always be the default (never MAP)”. A Default that installs a proper prior on ρ makes the shipped deterministic criterion REML + Σ_k ρ_k²/(2 sd²) — MAP in ρ — which is a different estimator, not a stabilised version of the same one. gam-custom-family has always passed Flat explicitly at its entry point for exactly this reason; the gam-models / CLI / Python path reached the same solver through FitOptions::default() and inherited a prior the enum’s own doc comment scopes to joint HMC refinement (#2450).

The sampler does not lose its prior by this. A flat prior on ρ gives an IMPROPER joint posterior — as ρ → ∞ the REML criterion tends to the finite λ=∞ face value, so exp(−V) does not decay and ∫dρ diverges — and that is precisely why joint HMC needs a proper one. The runtime already separates the two: resolve_effective_rho_prior fills unset (Flat) coordinates with the weakly-informative penalized-complexity default for consumers that need a distribution (serialization, joint-HMC refinement), while the REML/LAML objective evaluates those same coordinates through the self-gated one-sided barrier, which is byte-identically flat on the identified side. One default cannot serve both questions; Flat is the answer to “what criterion am I minimizing”, and the sampler’s answer is derived from it rather than shared with it.

Source§

fn default() -> RhoPrior

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RhoPrior

Source§

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

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

impl PartialEq for RhoPrior

Source§

fn eq(&self, other: &RhoPrior) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for RhoPrior

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RhoPrior

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

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

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