mixle.capability module¶
Capability-based feature detection for mixle objects.
Determine what an object supports rather than what class it is, so callers can dispatch on
behaviour instead of concrete class names. This generalises the pattern the engine layer already
uses (DistributionCapabilities.supports_engine / intersect_engine_ready) to every capability
facet in the type hierarchy (see docs/ABSTRACTIONS.md).
Two flavours of capability:
Method-presence capabilities are
runtime_checkableProtocol``s, so they work with ``isinstanceand with static typing/autocomplete:Conditionable,Marginalizable,LatentStructured,PosteriorPredictive,EngineResidentEStep.Declaration / derived capabilities cannot be expressed by a method name (they inspect the declaration or compose other capabilities); they subclass
PredicateCapabilityand carry acheck(obj)classmethod:Enumerable,FiniteSupport,RankableByIndex,ExponentialFamily,Neutral.
supports(obj, cap) / capabilities(obj) / require(obj, cap) are the uniform query surface
for both flavours. All mixle imports are deferred into the check methods so this module stays a
dependency-free leaf that any layer can import without cycles.
- exception CapabilityError[source]
Bases:
TypeErrorRaised by
require()when an object lacks a needed capability.
- class Conditionable(*args, **kwargs)[source]
Bases:
ProtocolSupports conditioning on a subset of coordinates:
condition(observed) -> distribution.
- class Marginalizable(*args, **kwargs)[source]
Bases:
ProtocolSupports marginalising to a subset of coordinates:
marginal(keep) -> distribution.
- class LatentStructured(*args, **kwargs)[source]
Bases:
ProtocolExposes an explicit latent posterior q(z|x):
latent_posterior(x) -> LatentPosterior.
- class PosteriorPredictive(*args, **kwargs)[source]
Bases:
ProtocolCan draw/score new data conditioned on an observation’s inferred latent state.
- class EngineResidentEStep(*args, **kwargs)[source]
Bases:
ProtocolAn accumulator that can run its E-step on the active compute engine without leaving it.
- class Transform(*args, **kwargs)[source]
Bases:
ProtocolAn invertible change of variables with a tractable Jacobian (combinator/transform.py).
- class SupportsBackendScoring(*args, **kwargs)[source]
Bases:
ProtocolA distribution that can score a batch directly on the active engine (
backend_seq_log_density).
- class SupportsBackendComponentScoring(*args, **kwargs)[source]
Bases:
ProtocolA distribution that exposes per-component engine scoring (
backend_seq_component_log_density).
- class SupportsStackedBackend(*args, **kwargs)[source]
Bases:
ProtocolA component type that can score/parameterise a homogeneous stack on the engine.
- class TemporalPointProcess(*args, **kwargs)[source]
Bases:
ProtocolAn event-time point process exposing its conditional intensity and compensator.
intensity(t, times, marks=None)is the conditional rate lambda(t) given the history; the univariate Hawkes / inhomogeneous-Poisson leaves return a float, the multivariate variant a per-mark vector.expected_count(t_start, t_end, times, marks=None)is the integrated intensity (compensator) over the window. (Birth-death is a population process, not an intensity-based point process, and is intentionally excluded.)- intensity(t, times, marks=None)[source]
- class PredicateCapability[source]
Bases:
objectBase for capabilities determined by inspecting the object rather than a method name.
- class Enumerable[source]
Bases:
PredicateCapabilityIts support can be iterated in descending-probability order (
enumerator()works).
- class FiniteSupport[source]
Bases:
PredicateCapabilityHas a finite number of distinct support points (
support_size()is an int).
- class RankableByIndex[source]
Bases:
PredicateCapabilitySupports random access by integer rank (unranking) via the count-budget seek index.
Finite-support enumerables are rankable by index through the count-DP semiring; the implication edge
finite ==> enumerable ==> rankableis exactly this composition. (Decomposable combinators over infinite-but-countable children are also rankable structurally; this conservative check covers the finite-leaf case used by the dispatch layers.)
- class Shardable[source]
Bases:
PredicateCapabilityDeclares a non-atomic model-parallel decomposition axis (
decomposition().is_shardable).The cheap string predicate gates planning; the rich
Decompositionis built only when a node is actually sharded. See~/codex/notes/model-parallel-design.md.
- class ExponentialFamily[source]
Bases:
PredicateCapabilityDeclares an exponential-family form (generated stacked kernels + conjugate estimation).
- class ConjugateUpdatable[source]
Bases:
PredicateCapabilityHas a closed-form conjugate Bayesian update (the top tier of the inference ladder).
supports(x, ConjugateUpdatable)is True iffconjugate_posterior(x, data)returns an exact closed-form posterior; otherwise Bayesian inference falls back to the numerical fitters (MAP / Laplace / MCMC / VI). Detection is the singleconjugate_posteriorregistry.
- class ExactDensity[source]
Bases:
PredicateCapabilitylog_densityreturns the exactlog p(x), not a bound or an approximation.False for models whose
log_densityis a variational lower bound (e.g. LDA / LLDA return a per-document ELBO) or a plug-in / Monte-Carlo estimate (e.g. HDPM, IBP).supports(x, ExactDensity)lets code that needs an exact likelihoodrequireit instead of silently trusting a bound. Detection:x.density_semantics()(defaultDensitySemantics.EXACT).
- class SetValued[source]
Bases:
PredicateCapabilityA distribution over sets with forced/required membership (
required/num_required).
- class HasCDF[source]
Bases:
PredicateCapabilityExposes an exact cumulative distribution function and its inverse (
cdfandquantile).The CDF/quantile pair is what lets a continuous family answer probability-ordered / rank queries through the inverse transform (the continuous analogue of enumeration).
- class HasMoments[source]
Bases:
PredicateCapabilityExposes closed-form moments (
meanandvarianceat least; optionally skewness/kurtosis).
- class HasEntropy[source]
Bases:
PredicateCapabilityExposes a closed-form (differential or Shannon)
entropy()in nats.
- class Discrete[source]
Bases:
PredicateCapabilityCountable support: the distribution is enumerable or has explicit finite support.
- class Continuous[source]
Bases:
PredicateCapabilityContinuous support: has a CDF/quantile but no countable (enumerable) support.
- class Fittable[source]
Bases:
PredicateCapabilityCan be fit from data: exposes an
estimator()(the M-step / MLE entry point).
- class Optimizable[source]
Bases:
PredicateCapabilityExposes a ranked objective over a structured space – the
Relationsurface (solve/top).Optimization-as-distribution: the object can return its optimum (
solve) and the k-best members (top/enumerator), so optimization is a first-class, capability-gated operation rather than a property of a specific class.
- class Neutral[source]
Bases:
PredicateCapabilityThe identity / no-op element of a combinator (a Null distribution, accumulator, or encoder).
- supports(obj, capability)[source]
Return whether
objprovidescapability(a Protocol or a PredicateCapability).
- capabilities(obj)[source]
Return the set of capability names
objprovides — “what can I do with this?”.
- require(obj, capability, op=None)[source]
Raise
CapabilityError(early, with a clear message) ifobjlackscapability.
- intersect_capabilities(children, caps=FACET_PRESERVING)[source]
Capabilities shared by EVERY child — what a decomposable combinator over them preserves.
- top_k(dist, k)[source]
Return the
khighest-probability(value, log_prob)pairs.Dispatches on capability, not class: a
RankableByIndexdistribution could random-access by rank, but everyEnumerabledistribution can stream its support in descending probability — so one implementation covers all of them, including user-defined ones. Raises a clearCapabilityErrorfor distributions that support neither.
- class CapabilitySpec(name, summary, kind, backed_by, home)[source]
Bases:
objectOne row of the capability vocabulary: what it means, what backs it, where it lives.
- name: str
- summary: str
- kind: str
- backed_by: str
- home: str
- catalog()[source]
Return the full capability vocabulary (every facet/contract/role), as data.
- Return type:
tuple[CapabilitySpec, …]
- describe(obj)[source]
Return a plain-English summary of what
objis and what you can do with it.The one-call answer to “what can this do?”: its category, the capabilities it has and notably lacks, the engines it runs on, and how to fit it. Works on any object; richest for distributions.
- summarize(obj)[source]
Return every closed-form summary statistic
objexposes, selected by its capabilities.The numeric companion to
describe()(which says what an object can do): mean/variance/std (plus skewness/kurtosis when present) for aHasMomentsdistribution,entropyforHasEntropy, and the median forHasCDF. Keys absent from the result are not available in closed form forobj– sosummarizenever raises on a partially-featured distribution.
- what_supports(capability, among)[source]
Return the names of the objects in
amongthat providecapability.amongis an iterable of instances (or classes for method-presence protocols) — e.g.what_supports(Conditionable, [mvn, gaussian, mixture]).