mixle.ppl._result module¶
Shared typing contract for the inference result objects attached to RandomVariable.result.
The fitters (inference.py, vmp.py, regression.py) each attach a result object to a
fitted RV via RandomVariable._bound(..., result=...). There are several concrete result
classes — Posterior, ConjugatePosterior, ConjugateMixturePosterior,
HierarchicalPosterior (inference.py), MixtureVMPResult / GraphResult / _VMPFit
(vmp.py), and RegressionResult / LMMResult / LocationScaleResult (regression.py) — and
they are consumed duck-typed in mixle.ppl.core (getattr(r, "summary", None),
hasattr(r, "samples"), getattr(r, "predictive", None), getattr(r, "build", None),
r.pointwise_log_likelihood(...)).
PosteriorResult is the structural (typing.Protocol) capture of that optional common
surface. It is intentionally a contract, not a base class: the concrete result classes keep their
distinct bodies and need not inherit it; it exists so that RandomVariable.result and the
fitters’ return annotations can name the shared surface instead of bare Any. Every member is
optional at the call site (the consumers probe with hasattr/getattr/callable), which is
why the Protocol carries the union of probed members rather than a strict required set.
This module imports only typing (+ numpy for an annotation), so core.py can import it at
module load without an import cycle through inference/regression/vmp (which import core at module
level).
- class PosteriorResult(*args, **kwargs)[source]
Bases:
ProtocolStructural contract for a fitted RV’s
.result.Captures the union surface that
mixle.ppl.core(and the diagnostics) probe on a result object. All members are optional in practice — consumers guard every access withhasattr/getattr/callable— so a concrete result need only implement the slice it supports (e.g. a point-estimateRegressionResulthassummary/predictbut nosamples; a_VIResultis a bare raw-result holder).acceptance_rateandpredictiveare the two attributes every concrete result sets (Nonewhen not applicable).Because the members are independently optional, this union protocol is intentionally not the right gate for an individual probe site: a
runtime_checkableisinstanceagainst it requires every member to be present, which onlyPosteriorsatisfies (the conjugate / hierarchical / regression / vmp results all lackpointwise_log_likelihoodand several lacksamplesorpredictive). Per-capability probes therefore dispatch on the narrow single-method protocols below, each of which is exactly equivalent to the lenienthasattr/callableprobe it replaces.- samples(param=..., *args, **kwargs)[source]
Parameter / latent draws (read by
RandomVariable.posterior).
- class Summarizable(*args, **kwargs)[source]
Bases:
ProtocolA result that can report a posterior / fit
summary()(read byRandomVariable.summary).Narrow, single-method facet of
PosteriorResult:supports(r, Summarizable)is exactly the oldcallable(getattr(r, "summary", None))probe for any result whosesummaryis a method (every concrete result class is).