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 by log(F(b) - F(a));

    use a = -inf for left censoring, b = +inf for 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: SequenceEncodableProbabilityDistribution

A base distribution whose observations may be interval/left/right censored.

Parameters:
  • base (SequenceEncodableProbabilityDistribution)

  • name (str | None)

  • keys (str | None)

density(x)[source]

Return the contribution of x (density for exact, interval mass for censored).

Parameters:

x (Any)

Return type:

float

log_density(x)[source]

Log-likelihood contribution of x.

Exact observation x -> log p_base(x); interval (a, b) -> log(F(b) - F(a)).

Parameters:

x (Any)

Return type:

float

seq_log_density(x)[source]

Per-row censored log-densities for an encoded batch.

Parameters:

x (tuple[Any, ndarray, ndarray, ndarray, ndarray])

Return type:

ndarray

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: DistributionSampler

Draw exact values from the base distribution (the sampler is not censored).

Parameters:
  • dist (CensoredDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw exact value(s) from the base distribution.

Parameters:

size (int | None)

class CensoredAccumulator(base_accumulator, keys=None)[source]

Bases: SingleChildAccumulator

Accumulate base sufficient statistics over the exact (uncensored) observations only.

Parameters:
  • base_accumulator (SequenceEncodableStatisticAccumulator)

  • keys (str | None)

update(x, weight, estimate)[source]
Parameters:
  • x (Any)

  • weight (float)

  • estimate (CensoredDistribution | None)

Return type:

None

initialize(x, weight, rng)[source]
Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]
Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]
Parameters:
Return type:

None

acc_to_encoder()[source]
Return type:

DataSequenceEncoder

class CensoredAccumulatorFactory(base_factory, keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory for CensoredAccumulator.

Parameters:
  • base_factory (StatisticAccumulatorFactory)

  • keys (str | None)

make()[source]
Return type:

CensoredAccumulator

class CensoredEstimator(base_estimator, name=None, keys=None)[source]

Bases: ParameterEstimator

Fit the base on the exact observations, re-wrap with censoring.

Parameters:
  • base_estimator (ParameterEstimator)

  • name (str | None)

  • keys (str | None)

accumulator_factory()[source]
Return type:

CensoredAccumulatorFactory

estimate(nobs, suff_stat)[source]
Parameters:
Return type:

CensoredDistribution

class CensoredDataEncoder(dist=None, base_encoder=None)[source]

Bases: MaskedBaseEncoder

Split a batch into exact observations (base-encoded) and censoring intervals.

Encoded form is (exact_enc, exact_idx, lows, highs, cens_idx) where exact_idx / cens_idx are the original positions of the exact / censored rows so seq_log_density can 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

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Sequence[Any])

Return type:

tuple[Any, ndarray, ndarray, ndarray, ndarray]