mixle.stats.combinator.transform module¶
Invertible-transform wrappers for sequence-encodable distributions.
The module implements identity, affine, exponential, logit, and custom transforms plus the distribution, sampler, accumulator, and encoder plumbing needed to apply them inside Mixle combinators.
- class IdentityTransform[source]
Bases:
objectIdentity transform y = x.
- log_abs_det_inverse_jacobian(y)[source]
Return the log absolute inverse-Jacobian determinant.
- class AffineTransform(loc=0.0, scale=1.0)[source]
Bases:
objectAffine transform y = loc + scale * x.
- forward(x)[source]
Apply the affine map to a child-space value.
- inverse(y)[source]
Map a transformed-space value back to child space.
- log_abs_det_inverse_jacobian(y)[source]
Return the constant affine inverse-Jacobian correction.
- class ExpTransform[source]
Bases:
objectExponential transform y = exp(x), mapping real x to positive y.
- inverse(y)[source]
Map a positive transformed value back to the real line.
- log_abs_det_inverse_jacobian(y)[source]
Return the log inverse-Jacobian correction for
log(y).
- class LogTransform[source]
Bases:
objectLog transform y = log(x), mapping positive x to real y.
- forward(x)[source]
Map a positive child value to the real line.
- inverse(y)[source]
Map a real transformed value back to the positive scale.
- log_abs_det_inverse_jacobian(y)[source]
Return the log inverse-Jacobian correction for
exp(y).
- class LogitTransform[source]
Bases:
objectLogistic transform y = 1 / (1 + exp(-x)), mapping real x to (0, 1).
- forward(x)[source]
Map a real value into the open unit interval.
- inverse(y)[source]
Map a unit-interval value back to the real line.
- log_abs_det_inverse_jacobian(y)[source]
Return the log inverse-Jacobian correction for the logit map.
- 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]
Return capabilities delegated from the child distribution where safe.
- compute_declaration()[source]
Return a declaration describing this distribution as a transformed child.
- 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)
- 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]
Accumulate one inverse-transformed observation when it is valid.
- seq_update(x, weights, estimate)[source]
Accumulate a batch using validity-masked child weights.
- 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]
Initialize from one inverse-transformed observation when it is valid.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_initialize(x, weights, rng)[source]
Initialize from a validity-masked encoded batch.
- combine(suff_stat)[source]
Merge child sufficient statistics.
- Parameters:
suff_stat (Any)
- Return type:
TransformAccumulator
- from_value(x)[source]
Restore the child accumulator from serialized sufficient statistics.
- Parameters:
x (Any)
- Return type:
TransformAccumulator
- scale(c)[source]
Scale delegated sufficient statistics by
c.- Parameters:
c (float)
- Return type:
TransformAccumulator
- key_merge(stats_dict)[source]
Delegate keyed statistic merging to the child accumulator.
- key_replace(stats_dict)[source]
Delegate keyed statistic replacement to the child accumulator.
- acc_to_encoder()[source]
Return the encoder associated with this accumulator.
- Return type:
TransformDataEncoder
- class TransformAccumulatorFactory(factory, transform, density_correction=None, name=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for TransformAccumulator.
- Parameters:
- make()[source]
Create a fresh transform accumulator.
- 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 the accumulator factory for inverse-transformed observations.
- Return type:
TransformAccumulatorFactory
- class TransformDataEncoder(encoder, transform, density_correction=True)[source]
Bases:
DataSequenceEncoderEncode transformed observations as inverse child data plus Jacobian terms.