mixle.stats.combinator.transform module¶
Fixed invertible-transform wrapper for sequence-encodable distributions.
- class AffineTransform(loc=0.0, scale=1.0)[source]
Bases:
objectAffine transform y = loc + scale * x.
- class ExpTransform[source]
Bases:
objectExponential transform y = exp(x), mapping real x to positive y.
- class LogitTransform[source]
Bases:
objectLogistic transform y = 1 / (1 + exp(-x)), mapping real x to (0, 1).
- class TransformDistribution(dist, transform=None, density_correction=None, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionPush a child distribution through a fixed invertible transform.
Observations live in transformed space. For fixed continuous transforms, log-density uses the inverse transform and adds the inverse-Jacobian term. The transform is not learned; estimation inverse-transforms observations and delegates sufficient statistics to the child estimator.
- Parameters:
- compute_capabilities()[source]
- compute_declaration()[source]
- density(x)[source]
Return the probability density or mass at a single observation.
- log_density(x)[source]
Return the log-density or log-mass at a single observation.
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded observations.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized log-density for inverse-encoded observations.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked child parameters for homogeneous fixed-transform mixtures.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of transformed child log densities.
- classmethod backend_stacked_sufficient_statistics_with_estimator(x, weights, params, engine, estimator)[source]
Return child legacy statistics for valid inverse-transformed observations.
- gradient_fit_state(engine, torch, leaves, recurse, tensor_param)[source]
Return distribution-owned state for autograd fitting.
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
TransformSampler
- estimator(pseudo_count=None)[source]
Return an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
TransformEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
TransformDataEncoder
- enumerator()[source]
Return an enumerator over the distribution support when available.
- Return type:
TransformEnumerator
- class TransformEnumerator(dist)[source]
Bases:
DistributionEnumeratorEnumerate transformed child support for discrete child distributions.
- Parameters:
dist (TransformDistribution)
- class TransformSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSampler that transforms draws from the child distribution.
- Parameters:
dist (TransformDistribution)
seed (int | None)
- sample(size=None)[source]
Draw observations.
Combinator samplers (mixture/sequence/…) accept
batched. Withbatched=True(the default) each child stream is drawn in one vectorized call instead of a per-draw Python loop – far faster. Because every child sampler owns an independentRandomState, batching consumes each stream in the same order as the loop, so the draws are identical to the legacy path.batched=Falseforces that legacy per-draw loop as a guaranteed- stable reference. Leaf samplers are already vectorized and ignore the flag.- Parameters:
size (int | None)
- class TransformAccumulator(accumulator, transform, density_correction=None, name=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulator that delegates inverse-transformed observations to the child.
- Parameters:
- update(x, weight, estimate)[source]
- seq_update(x, weights, estimate)[source]
- seq_update_engine(x, weights, estimate, engine)[source]
Engine-resident E-step: the validity-masked weights are formed on the active engine and the child accumulator is routed through the engine. Matches seq_update.
- initialize(x, weight, rng)[source]
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_initialize(x, weights, rng)[source]
- scale(c)[source]
Scale linear sufficient statistics in-place by
c.The structural default is correct for ordinary weighted sums, nested tuples/lists/dicts, and numeric arrays. Families whose
value()payload includes non-linear metadata such as support bounds must override this method and leave that metadata unscaled.- Parameters:
c (float)
- Return type:
TransformAccumulator
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- key_replace(stats_dict)[source]
Replace this accumulator’s statistics from the pooled
stats_dictentry (see key_merge).
- acc_to_encoder()[source]
- Return type:
TransformDataEncoder
- class TransformAccumulatorFactory(factory, transform, density_correction=None, name=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for TransformAccumulator.
- Parameters:
- make()[source]
- Return type:
TransformAccumulator
- class TransformEstimator(estimator, transform=None, density_correction=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorEstimator for fixed-transform distributions.
- Parameters:
- accumulator_factory()[source]
- Return type:
TransformAccumulatorFactory
- class TransformDataEncoder(encoder, transform, density_correction=True)[source]
Bases:
DataSequenceEncoderEncode transformed observations as inverse child data plus Jacobian terms.