pyrecest.protocols is the public home for small capability contracts used by
PyRecEst components.
A protocol describes what an object can do without requiring it to inherit from a specific base class. This keeps extension points lightweight: a user-defined class can work with generic PyRecEst utilities when it implements the required methods and attributes.
The package defines common dimension protocols and broad array aliases:
SupportsDimfor objects with an intrinsic state-space dimension;SupportsInputDimfor objects with an ambient or input coordinate dimension;ArrayLikeandBackendArrayas intentionally broad aliases for backend compatible values.
It also defines distribution and filter capability protocols:
SupportsPdfandSupportsLogPdffor density evaluation;SupportsSamplingfor sample generation;SupportsMean,SupportsCovariance, andSupportsMeanAndCovariancefor moment-style summaries;SupportsDistributionConversionandSupportsDistributionApproximationfor representation conversion entry points;SupportsFilterState,SupportsPointEstimate,SupportsLinearPrediction,SupportsLinearUpdate, andSupportsHistoryRecordingfor common filter capabilities.
Protocols should stay small and capability-oriented. Instead of requiring every distribution, model, or filter to implement one large interface, PyRecEst should ask only for the capability that a function actually needs.
For example, a density utility can require SupportsPdf while a sampler utility
can require only SupportsSampling. A particle representation should not need
to implement analytic density evaluation merely to satisfy a large distribution
base interface.
The public protocols are runtime-checkable where practical:
from pyrecest.protocols import SupportsDim, SupportsPdf
class DemoDistribution:
dim = 2
def pdf(self, xs):
return 1.0
assert isinstance(DemoDistribution(), SupportsDim)
assert isinstance(DemoDistribution(), SupportsPdf)Runtime checks confirm that the required attributes or methods are present. They do not prove mathematical correctness. Protocol-specific tests should check shapes, backend behavior, and semantics separately.
Use package-level imports for public protocols:
from pyrecest.protocols import SupportsDim, SupportsPdf, SupportsSamplingSubmodule imports remain available when a smaller namespace is preferred:
from pyrecest.protocols.distributions import SupportsLogPdf