mixle.stats.combinator.censored module¶
Censoring combinator: a censored observation is known only to lie in an interval.
CensoredDistribution wraps a base distribution and scores censored observations – ones
that are not observed exactly but are known only to fall in some interval [a, b]. Such an
observation contributes its interval probability mass
P(a <= X <= b) = F(b) - F(a)
to the likelihood, where F is the base distribution’s CDF. This is distinct from truncation:
truncation renormalizes the density over a restricted support (the observation is exact but the
support is limited), whereas censoring keeps the original distribution and only coarsens what was
observed. Survival-analysis right/left/interval censoring (and Tobit-style bounds) are all this
combinator.
Data type: each observation is one of
a scalar
x– an exact (uncensored) observation, scored by the base density;
- a pair
(a, b)– interval-censored, scored bylog(F(b) - F(a));use
a = -inffor left censoring,b = +inffor right.
The base distribution must expose cdf. Estimation of the base parameters under censoring has no
generic closed form (the censored MLE couples the bounds with the base parameters), so the supplied
estimator fits the base on the exact observations only and re-wraps; document and prefer a
dedicated censored MLE when the censored fraction is large.
- class CensoredDistribution(base, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionA base distribution whose observations may be interval/left/right censored.
- density(x)[source]
Return the contribution of
x(density for exact, interval mass for censored).
- log_density(x)[source]
Log-likelihood contribution of
x.Exact observation
x->log p_base(x); interval(a, b)->log(F(b) - F(a)).
- seq_log_density(x)[source]
Per-row censored log-densities for an encoded batch.
- sampler(seed=None)[source]
Return a sampler that draws exact values from the base (sampling is uncensored).
- Parameters:
seed (int | None)
- Return type:
CensoredSampler
- estimator(pseudo_count=None)[source]
Return an estimator that fits the base on the exact observations, re-wrapping with censoring.
The censored MLE has no generic closed form (the bounds couple with the base parameters), so this fits the base distribution on the exact (uncensored) observations and re-wraps. Use it when the censored fraction is modest; prefer a dedicated censored MLE otherwise.
- Parameters:
pseudo_count (float | None)
- Return type:
CensoredEstimator
- dist_to_encoder()[source]
Return the data encoder (exact observations + censoring intervals split out).
- Return type:
CensoredDataEncoder
- class CensoredSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw exact values from the base distribution (the sampler is not censored).
- Parameters:
dist (CensoredDistribution)
seed (int | None)
- class CensoredAccumulator(base_accumulator, keys=None)[source]
Bases:
SingleChildAccumulatorAccumulate base sufficient statistics over the exact (uncensored) observations only.
- Parameters:
base_accumulator (SequenceEncodableStatisticAccumulator)
keys (str | None)
- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- acc_to_encoder()[source]
- Return type:
DataSequenceEncoder
- class CensoredAccumulatorFactory(base_factory, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for
CensoredAccumulator.- Parameters:
base_factory (StatisticAccumulatorFactory)
keys (str | None)
- make()[source]
- Return type:
CensoredAccumulator
- class CensoredEstimator(base_estimator, name=None, keys=None)[source]
Bases:
ParameterEstimatorFit the base on the exact observations, re-wrap with censoring.
- accumulator_factory()[source]
- Return type:
CensoredAccumulatorFactory
- class CensoredDataEncoder(dist=None, base_encoder=None)[source]
Bases:
MaskedBaseEncoderSplit a batch into exact observations (base-encoded) and censoring intervals.
Encoded form is
(exact_enc, exact_idx, lows, highs, cens_idx)whereexact_idx/cens_idxare the original positions of the exact / censored rows soseq_log_densitycan scatter results back into the right order.- Parameters:
dist (CensoredDistribution | None)
base_encoder (DataSequenceEncoder | None)
- classmethod from_base_encoder(base_encoder)[source]
- Parameters:
base_encoder (DataSequenceEncoder)
- Return type:
CensoredDataEncoder