Prior#
- class uvex_transients.models.core.priors.Prior[source]#
Abstract base class for one-dimensional statistical priors.
A prior represents a probability distribution over real-valued numerical coordinates. The primary purpose of a prior is to generate random samples through the
sample()method.Subclasses should be implemented as frozen dataclasses and are responsible for validating their own parameters (
_validate()) and providing the distribution’s log-density (_logpdf()). Everything else – sampling,pdf(),cdf(),logpdf(),logcdf()– is derived from_logpdfautomatically.See also
scipy.stats.sampling.NumericalInversePolynomialBacks the generic
_sample()fallback.
Notes
A minimal implementation looks like
@dataclass(frozen=True) class NormalPrior(Prior): mean: float sigma: float def _validate(self): if self.sigma <= 0: raise ValueError( "`sigma` must be positive." ) def _logpdf(self, x): return scipy.stats.norm.logpdf( x, loc=self.mean, scale=self.sigma )
This is already enough for
sample()to work, via numerical inversion of the CDF built from_logpdf. If a fast closed-form orscipy.statssampler is available, override_sample()too:def _sample(self, rng, size): return rng.normal( self.mean, self.sigma, size=size )
Methods
cdf(x)Evaluate the cumulative distribution function.
logcdf(x)Evaluate the log cumulative distribution function.
logpdf(x)Evaluate the log probability density function.
logpmf(x)Evaluate the log probability mass function.
pdf(x)Evaluate the probability density function.
pmf(x)Evaluate the probability mass function.
registry()dict[str, type[Prior]]: A copy of every concrete Prior subclass, keyed by DISTRIBUTION_NAME.
sample([size, rng])Draw random samples from the prior.
Attributes
The public-facing name of this distribution prior class.
Human-readable name of the distribution.
The
(lower, upper)support of the distribution.