mixle.stats.combinator.exponential_tilt module¶
Exponential-tilting combinator: reweight a base distribution by exp(theta . T(x)).
ExponentialTiltedDistribution wraps a base distribution and applies an exponential change
of measure (an Esscher transform):
p_theta(x) = exp(theta . T(x)) * p_base(x) / Z(theta), Z(theta) = E_base[exp(theta . T(X))],
where T is a sufficient statistic and Z(theta) the moment/cumulant generating function.
This single operation covers several classic use cases:
general tilt – an arbitrary statistic
T(default identityT(x) = x);tempering / power –
T(x) = log p_base(x)givesp_theta ~ p_base^{1+theta}(annealed importance sampling, parallel tempering);Esscher / MGF tilt – continuous exponential-family bases (Gaussian, Gamma, …) whose
Z(theta)is closed form (rare-event importance sampling, actuarial pricing).
The normalizer Z(theta) is resolved in three ways, in order: an explicit user
log_normalizer (the CGF); a registered analytic tilt for the base family (identity statistic
only – these also yield the exact in-family tilted distribution, so sampling is exact); otherwise
exact enumeration Z = sum_a p(a) exp(theta . T(a)) for an enumerable base. It pairs with the
support tools (the tilted normalizer is the same sum the enumeration bounds reason about) and sits
beside TruncatedDistribution – truncation is the
degenerate tilt whose statistic is a {0, -inf} indicator.
- class TiltResult(log_normalizer, closed_form=None)[source]
Bases:
objectResult of resolving the tilt normalizer:
log Z(theta)and, when the tilt closes in the base family, the exact tilted distribution (same family) for exact sampling.- Parameters:
log_normalizer (float)
closed_form (SequenceEncodableProbabilityDistribution | None)
- log_normalizer: float
- closed_form: SequenceEncodableProbabilityDistribution | None = None
- register_exponential_tilt(dist_type, fn)[source]
Register an analytic identity-statistic tilt
fn(base, theta) -> TiltResultfordist_type.
- registered_tilt_families()[source]
Return the names of base families with a registered analytic tilt.
- tilt_log_normalizer(base, theta, statistic_kind, statistic_fn, user_normalizer)[source]
Resolve
log Z(theta)(and any closed-form tilted distribution) for a base + statistic.Resolution order: explicit
user_normalizer-> registered analytic tilt (identity statistic only) -> exact enumeration over an enumerable base. Raises if none applies.
- class ExponentialTiltedDistribution(base, theta, statistic=None, log_normalizer=None, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionA base distribution reweighted by
exp(theta . T(x))and renormalized byZ(theta).- Parameters:
- density(x)[source]
Return the tilted probability/density at
x.
- log_density(x)[source]
Return
log p_base(x) + theta . T(x) - log Z.
- seq_log_density(x)[source]
Return per-row tilted log-densities for an encoded batch.
- closed_form()[source]
Return the in-family tilted distribution when the tilt closes in the base family, else None.
- Return type:
SequenceEncodableProbabilityDistribution | None
- sampler(seed=None)[source]
Return a sampler (exact for registered/enumerable bases; SIR otherwise).
- Parameters:
seed (int | None)
- Return type:
ExponentialTiltedSampler
- estimator(pseudo_count=None, fit='theta')[source]
Return an estimator.
fit='theta'fits the tilt by the exponential-family score equationE_theta[T] = mean(T(data))(base + statistic fixed);fit='base'holdsthetafixed and refits the base on the data, re-tilting (the fixed-tilt analogue of the truncation estimator).
- dist_to_encoder()[source]
Return the data encoder (base encoding plus the precomputed statistic per row).
- Return type:
ExponentialTiltedDataEncoder
- support_size()[source]
Tilting preserves the support, so the cardinality is the base’s.
- Return type:
int | None
- enumerator()[source]
Enumerate the support in descending tilted-probability order.
- Return type:
ExponentialTiltedEnumerator
- class ExponentialTiltedEnumerator(dist)[source]
Bases:
DistributionEnumeratorReweight the base enumeration by
theta . T(a) - log Zand re-sort descending.- Parameters:
dist (ExponentialTiltedDistribution)
- class ExponentialTiltedSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample the tilted distribution: exact via the closed-form / enumerated tilted pmf, else SIR.
- Parameters:
dist (ExponentialTiltedDistribution)
seed (int | None)
- class ExponentialTiltedAccumulator(dim, base_accumulator, keys=None)[source]
Bases:
SingleChildAccumulatorAccumulate the count and the weighted sum of the statistic
T(the exp-family score data).Carries extra scalar statistics
(sum_t, count)alongside the bare child value, so it overrides the delegation trio; onlykey_merge/key_replace(which forward to the child) are inherited.- 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
- 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:
ExponentialTiltedAccumulator
- acc_to_encoder()[source]
- Return type:
DataSequenceEncoder
- class ExponentialTiltedAccumulatorFactory(dim, base_factory, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for
ExponentialTiltedAccumulator.- make()[source]
- Return type:
ExponentialTiltedAccumulator
- class ExponentialTiltedEstimator(prototype, pseudo_count=None, fit='theta', max_iter=60, tol=1e-8)[source]
Bases:
ParameterEstimatorFit the tilt by the exp-family score equation (
fit='theta') or refit the base (fit='base').- Parameters:
- accumulator_factory()[source]
- Return type:
ExponentialTiltedAccumulatorFactory
- class ExponentialTiltedDataEncoder(dist)[source]
Bases:
MaskedBaseEncoderEncode observations via the base encoder, plus the precomputed statistic
Tper row.- Parameters:
dist (ExponentialTiltedDistribution)