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) -> LikelihoodSpec
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.
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<LikelihoodSpec, IllegalLikelihoodCell>
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.
pub const fn gaussian_identity() -> LikelihoodSpec
pub const fn binomial_logit() -> LikelihoodSpec
pub const fn binomial_probit() -> LikelihoodSpec
pub const fn binomial_cloglog() -> LikelihoodSpec
pub const fn binomial_latent_cloglog( state: LatentCLogLogState, ) -> LikelihoodSpec
pub const fn binomial_sas(state: SasLinkState) -> LikelihoodSpec
pub const fn binomial_beta_logistic(state: SasLinkState) -> LikelihoodSpec
pub fn binomial_mixture(state: MixtureLinkState) -> LikelihoodSpec
pub const fn poisson_log() -> LikelihoodSpec
pub const fn tweedie_log(p: f64) -> LikelihoodSpec
Sourcepub const fn negative_binomial_log(theta: f64) -> LikelihoodSpec
pub const fn negative_binomial_log(theta: f64) -> LikelihoodSpec
Estimated-theta NB spec: theta is the seed, refined by the inner
solver (#802 default).
Sourcepub const fn negative_binomial_log_fixed(theta: f64) -> LikelihoodSpec
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).
pub const fn beta_logit(phi: f64) -> LikelihoodSpec
pub const fn gamma_log() -> LikelihoodSpec
pub const fn royston_parmar() -> LikelihoodSpec
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<LikelihoodSpec, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<LikelihoodSpec, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<LikelihoodSpec> for LikelihoodSpecWire
impl From<LikelihoodSpec> for LikelihoodSpecWire
Source§fn from(spec: LikelihoodSpec) -> LikelihoodSpecWire
fn from(spec: LikelihoodSpec) -> LikelihoodSpecWire
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 ==.Source§impl Serialize for LikelihoodSpec
impl Serialize for LikelihoodSpec
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for LikelihoodSpec
Source§impl TryFrom<LikelihoodSpecWire> for LikelihoodSpec
impl TryFrom<LikelihoodSpecWire> for LikelihoodSpec
Source§type Error = IllegalLikelihoodCell
type Error = IllegalLikelihoodCell
Source§fn try_from(
wire: LikelihoodSpecWire,
) -> Result<LikelihoodSpec, <LikelihoodSpec as TryFrom<LikelihoodSpecWire>>::Error>
fn try_from( wire: LikelihoodSpecWire, ) -> Result<LikelihoodSpec, <LikelihoodSpec as TryFrom<LikelihoodSpecWire>>::Error>
Auto Trait Implementations§
impl Freeze for LikelihoodSpec
impl RefUnwindSafe for LikelihoodSpec
impl Send for LikelihoodSpec
impl Sync for LikelihoodSpec
impl Unpin for LikelihoodSpec
impl UnsafeUnpin for LikelihoodSpec
impl UnwindSafe for LikelihoodSpec
Blanket Implementations§
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> 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,
impl<T> Scalar for T
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.