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: InverseLinkImplementations§
Source§impl LikelihoodSpec
impl LikelihoodSpec
Sourcepub const fn new(response: ResponseFamily, link: InverseLink) -> Self
pub const fn new(response: ResponseFamily, link: InverseLink) -> Self
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.
Sourcepub fn is_legal_cell(response: &ResponseFamily, link: &InverseLink) -> bool
pub fn is_legal_cell(response: &ResponseFamily, link: &InverseLink) -> bool
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.
Sourcepub fn try_new(
response: ResponseFamily,
link: InverseLink,
) -> Result<Self, IllegalLikelihoodCell>
pub fn try_new( response: ResponseFamily, link: InverseLink, ) -> Result<Self, 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.
pub const fn gaussian_identity() -> Self
pub const fn binomial_logit() -> Self
pub const fn binomial_probit() -> Self
pub const fn binomial_cloglog() -> Self
pub const fn binomial_latent_cloglog(state: LatentCLogLogState) -> Self
pub const fn binomial_sas(state: SasLinkState) -> Self
pub const fn binomial_beta_logistic(state: SasLinkState) -> Self
pub fn binomial_mixture(state: MixtureLinkState) -> Self
pub const fn poisson_log() -> Self
pub const fn tweedie_log(p: f64) -> Self
Sourcepub const fn negative_binomial_log(theta: f64) -> Self
pub const fn negative_binomial_log(theta: f64) -> Self
Estimated-theta NB spec: theta is the seed, refined by the inner
solver (#802 default).
Sourcepub const fn negative_binomial_log_fixed(theta: f64) -> Self
pub const fn negative_binomial_log_fixed(theta: f64) -> Self
Fixed-theta NB spec: the fit holds theta at exactly this value
(--negative-binomial-theta, issue #983).
pub const fn beta_logit(phi: f64) -> Self
pub const fn gamma_log() -> Self
pub const fn royston_parmar() -> Self
pub const fn link_function(&self) -> LinkFunction
Sourcepub fn kind(&self) -> FamilySpecKind
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.
pub fn is_binomial(&self) -> bool
pub fn is_gaussian_identity(&self) -> bool
pub fn is_royston_parmar(&self) -> bool
pub fn is_latent_cloglog(&self) -> bool
pub fn is_binomial_mixture(&self) -> bool
pub fn is_binomial_sas(&self) -> bool
pub fn is_binomial_beta_logistic(&self) -> bool
Sourcepub fn default_scale_metadata(&self) -> LikelihoodScaleMetadata
pub fn default_scale_metadata(&self) -> LikelihoodScaleMetadata
Default scale metadata for this (response, link).
Sourcepub fn pretty_name(&self) -> &'static str
pub fn pretty_name(&self) -> &'static str
Human-readable label, routed through FamilySpecKind.
pub fn supports_firth(&self) -> bool
Sourcepub const fn fixed_dispersion(&self) -> Option<f64>
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).
GaussianandGammaprofile/estimate the scale jointly with the mean, so no fixedphiis exposed here.BinomialandPoissonare unit-scale exponential-family fits, so the contract isSome(1.0). NegativeBinomial’s overdispersion lives intheta(a separate parameter / flag), not in a freephi, so it also returnsSome(1.0).Tweedie { p }carries its variance power on the family variant. Its free dispersionphilives inLikelihoodScaleMetadataand 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.RoystonParmarhas no GLM-style dispersion slot.
Trait Implementations§
Source§impl Clone for LikelihoodSpec
impl Clone for LikelihoodSpec
Source§fn clone(&self) -> LikelihoodSpec
fn clone(&self) -> LikelihoodSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LikelihoodSpec
impl Debug for LikelihoodSpec
Source§impl<'de> Deserialize<'de> for LikelihoodSpec
impl<'de> Deserialize<'de> for LikelihoodSpec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<LikelihoodSpec> for LikelihoodSpecWire
impl From<LikelihoodSpec> for LikelihoodSpecWire
Source§fn from(spec: LikelihoodSpec) -> Self
fn from(spec: LikelihoodSpec) -> Self
Source§impl PartialEq for LikelihoodSpec
impl PartialEq for LikelihoodSpec
Source§fn eq(&self, other: &LikelihoodSpec) -> bool
fn eq(&self, other: &LikelihoodSpec) -> bool
self and other values to be equal, and is used by ==.