Skip to main content

LikelihoodSpec

Struct LikelihoodSpec 

Source
pub struct LikelihoodSpec {
    pub response: ResponseFamily,
    pub link: InverseLink,
}
Expand description

Unified likelihood specification: response distribution + parameterized link.

ResponseFamily carries the per-family scalars (Tweedie p, NegBin theta, Beta phi); InverseLink carries the parameterized link state. Together they replace the former flat likelihood enum.

Only the legal (response, link) cells enumerated by LikelihoodSpec::kind are representable through the public surface: LikelihoodSpec::try_new validates the legal matrix on construction, and deserialization routes through LikelihoodSpecWire (#[serde(try_from / into)]) so saved bytes cannot resurrect an illegal cell. The on-wire shape is byte-identical to the historical { response, link } struct, so legal saved models load unchanged.

Fields§

§response: ResponseFamily§link: InverseLink

Implementations§

Source§

impl LikelihoodSpec

Source

pub const fn new(response: ResponseFamily, link: InverseLink) -> LikelihoodSpec

Unchecked constructor: assembles a (response, link) cell without validating the legal matrix. Reserved for the in-crate named const constructors below (gaussian_identity, poisson_log, beta_logit, the binomial_* family, …), every one of which builds a cell that is legal by construction. The public, fallible entry point for an arbitrary (response, link) pair is LikelihoodSpec::try_new; the serde path also validates via LikelihoodSpecWire. Do not expose illegal cells through this method.

Returns true when the (response, link) pair is one of the legal cells the family math honours — exactly the cells enumerated by LikelihoodSpec::kind before any masking. Each non-binomial response is pinned to a single inverse link; the binomial family admits its full set of probability links but never the identity/log standard links.

Source

pub fn try_new( response: ResponseFamily, link: InverseLink, ) -> Result<LikelihoodSpec, IllegalLikelihoodCell>

Fallible constructor over an arbitrary (response, link) pair. Validates the legal matrix (LikelihoodSpec::is_legal_cell) so that an illegal cell — one whose stored link would drive a wrong response transformation — is rejected instead of silently masked by LikelihoodSpec::kind.

Source

pub const fn gaussian_identity() -> LikelihoodSpec

Source

pub const fn binomial_logit() -> LikelihoodSpec

Source

pub const fn binomial_probit() -> LikelihoodSpec

Source

pub const fn binomial_cloglog() -> LikelihoodSpec

Source

pub const fn binomial_latent_cloglog( state: LatentCLogLogState, ) -> LikelihoodSpec

Source

pub const fn binomial_sas(state: SasLinkState) -> LikelihoodSpec

Source

pub const fn binomial_beta_logistic(state: SasLinkState) -> LikelihoodSpec

Source

pub fn binomial_mixture(state: MixtureLinkState) -> LikelihoodSpec

Source

pub const fn poisson_log() -> LikelihoodSpec

Source

pub const fn tweedie_log(p: f64) -> LikelihoodSpec

Source

pub const fn negative_binomial_log(theta: f64) -> LikelihoodSpec

Estimated-theta NB spec: theta is the seed, refined by the inner solver (#802 default).

Source

pub const fn negative_binomial_log_fixed(theta: f64) -> LikelihoodSpec

Fixed-theta NB spec: the fit holds theta at exactly this value (--negative-binomial-theta, issue #983).

Source

pub const fn beta_logit(phi: f64) -> LikelihoodSpec

Source

pub const fn gamma_log() -> LikelihoodSpec

Source

pub const fn royston_parmar() -> LikelihoodSpec

Source

pub fn kind(&self) -> FamilySpecKind

Once-and-for-all classification into the legal-only FamilySpecKind.

(ResponseFamily, InverseLink) is a 40-cell product (8 response × 5 inverse-link); only the cells listed here are legal. Construction (LikelihoodSpec::try_new) and deserialization (the LikelihoodSpecWire try_from) both enforce LikelihoodSpec::is_legal_cell, so an illegal cell can never reach this method. Each link-pinned family therefore matches its one legal link explicitly; the remaining (now-unreachable) illegal combinations are unreachable!() so the historical silent masking — collapsing e.g. Poisson + Identity to PoissonLog while the transform predicted μ = η — can never silently happen again.

Source

pub fn is_binomial(&self) -> bool

Source

pub fn is_gaussian_identity(&self) -> bool

Source

pub fn is_royston_parmar(&self) -> bool

Source

pub fn is_latent_cloglog(&self) -> bool

Source

pub fn is_binomial_mixture(&self) -> bool

Source

pub fn is_binomial_sas(&self) -> bool

Source

pub fn is_binomial_beta_logistic(&self) -> bool

Source

pub fn default_scale_metadata(&self) -> LikelihoodScaleMetadata

Default scale metadata for this (response, link).

Source

pub fn pretty_name(&self) -> &'static str

Human-readable label, routed through FamilySpecKind.

Source

pub fn name(&self) -> &'static str

Short identifier, routed through FamilySpecKind.

Source

pub fn supports_firth(&self) -> bool

Source

pub const fn fixed_dispersion(&self) -> Option<f64>

Family-level fixed-dispersion contract. Returns the dispersion parameter phi that the GLM log-likelihood / weight expressions treat as fixed for the given ResponseFamily, or None when the family carries no fixed scale (profiled or jointly estimated).

  • Gaussian and Gamma profile/estimate the scale jointly with the mean, so no fixed phi is exposed here.
  • Binomial and Poisson are unit-scale exponential-family fits, so the contract is Some(1.0). NegativeBinomial’s overdispersion lives in theta (a separate parameter / flag), not in a free phi, so it also returns Some(1.0).
  • Tweedie { p } carries its variance power on the family variant. Its free dispersion phi lives in LikelihoodScaleMetadata and is estimated by default (EstimatedTweediePhi, issue #771), so this family-level contract only exposes the unit seed used when callers ask the response family without scale metadata.
  • Beta { phi } carries its precision parameter directly on the family variant; the contract returns that exact value rather than the placeholder used elsewhere for unit-scale GLMs.
  • RoystonParmar has no GLM-style dispersion slot.

Trait Implementations§

Source§

impl Clone for LikelihoodSpec

Source§

fn clone(&self) -> LikelihoodSpec

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 LikelihoodSpec

Source§

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

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

impl<'de> Deserialize<'de> for LikelihoodSpec

Source§

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

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

impl From<LikelihoodSpec> for LikelihoodSpecWire

Source§

fn from(spec: LikelihoodSpec) -> LikelihoodSpecWire

Converts to this type from the input type.
Source§

impl PartialEq for LikelihoodSpec

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for LikelihoodSpec

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 LikelihoodSpec

Source§

impl TryFrom<LikelihoodSpecWire> for LikelihoodSpec

Source§

type Error = IllegalLikelihoodCell

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

fn try_from( wire: LikelihoodSpecWire, ) -> Result<LikelihoodSpec, <LikelihoodSpec as TryFrom<LikelihoodSpecWire>>::Error>

Performs the conversion.

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