mixle.stats.combinator.finite_stochastic_transform module¶
Finite stochastic-transform combinator: push a finite discrete source through a noisy channel.
FiniteStochasticTransformDistribution models Y | X = x ~ Categorical(kernel[x, :]) where the
source X ~ dist ranges over {0, ..., m-1} and only the output Y in {0, ..., n-1} is
observed. It is the stochastic analogue of TransformDistribution:
the transform is a fixed m x n row-stochastic kernel (a confusion matrix / discrete channel)
rather than a deterministic invertible map, so the source marginal is
P(Y = y) = sum_x P(X = x) * kernel[x, y].
Estimation recovers the source dist from observed Y without inverting the channel. The
naive route – solve kernel^T p_X = P_hat(Y) for p_X (an m x n (pseudo-)inverse, O(m^3),
ill-conditioned, and blind to the simplex / to a structured source) – is short-circuited two ways:
The data’s only sufficient statistic is the length-
nvector of output counts, so the work is collapsed from theNobservations to thendistinct outputs up front (onebincount).The deconvolution is then a single E-step on those counts: the posterior responsibilities
R[x, y] = P(X = x) kernel[x, y] / P(Y = y)give the expected source countsc = R @ n_yby a matrix-vector product (O(n*m), independent ofN), which are fed straight to the source’s own estimator. Iteratingfitis EM / Richardson-Lucy deconvolution – monotone, constraint-aware, and reusing whatever (possibly structured) estimator the source provides.
- class FiniteStochasticTransformDistribution(dist, kernel, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionFinite discrete source pushed through a fixed finite stochastic kernel (noisy channel).
- Parameters:
- log_density(x)[source]
Return
log P(Y = x)for an integer outputx in {0, ..., n-1}.
- seq_log_density(x)[source]
Return per-observation
log P(Y = y)for an encoded batch of outputs.
- sampler(seed=None)[source]
Return a sampler drawing
X ~ distthenY ~ Categorical(kernel[X]).- Parameters:
seed (int | None)
- Return type:
FiniteStochasticTransformSampler
- estimator(pseudo_count=None)[source]
Return an estimator that recovers the source via the channel-inversion-free E-step.
- Parameters:
pseudo_count (float | None)
- Return type:
FiniteStochasticTransformEstimator
- dist_to_encoder()[source]
Return the data encoder for integer outputs.
- Return type:
FiniteStochasticTransformDataEncoder
- enumerator()[source]
Enumerate the finite outputs
yin descendingP(Y = y)order.- Return type:
FiniteStochasticTransformEnumerator
- class FiniteStochasticTransformEnumerator(dist)[source]
Bases:
DistributionEnumeratorEnumerate the finite output support in descending marginal probability.
- Parameters:
dist (FiniteStochasticTransformDistribution)
- class FiniteStochasticTransformSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample
Xfrom the source, thenYfrom that source state’s kernel row.- Parameters:
dist (FiniteStochasticTransformDistribution)
seed (int | None)
- class FiniteStochasticTransformAccumulator(source_accumulator, kernel, keys=None)[source]
Bases:
SingleChildAccumulatorAccumulate expected source counts via one channel E-step over aggregated output counts.
- Parameters:
- update(x, weight, estimate)[source]
- seq_update(x, weights, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_initialize(x, weights, rng)[source]
- Parameters:
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- acc_to_encoder()[source]
- Return type:
FiniteStochasticTransformDataEncoder
- class FiniteStochasticTransformAccumulatorFactory(source_factory, kernel, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for
FiniteStochasticTransformAccumulator.- make()[source]
- Return type:
FiniteStochasticTransformAccumulator
- class FiniteStochasticTransformEstimator(source_estimator, kernel, name=None, keys=None)[source]
Bases:
ParameterEstimatorEstimator for a fixed-kernel finite stochastic transform (recovers the source).
- accumulator_factory()[source]
- Return type:
FiniteStochasticTransformAccumulatorFactory