mixle.stats.univariate.continuous.exgaussian module¶
Evaluate, estimate, and sample from an exponentially-modified Gaussian (EMG) distribution.
Defines the ExponentiallyModifiedGaussianDistribution, ExponentiallyModifiedGaussianSampler, ExponentiallyModifiedGaussianAccumulatorFactory, ExponentiallyModifiedGaussianAccumulator, ExponentiallyModifiedGaussianEstimator, and ExponentiallyModifiedGaussianDataEncoder classes for use with mixle.
- Data type: (float): The EMG models
X = N(mu, sigma2) + Exp(rate=lam)– a Gaussian convolved with a (positive-shifting) exponential, giving a positively right-skewed real-valued density. Its stable log-density is
log f(x) = log(lam/2) - 0.5*u^2 + log(erfcx(z)),
where
u = (x - mu)/sigmaandz = (lam*sigma - u)/sqrt(2)andsigma = sqrt(sigma2). Usinglog_erfcxkeeps the right tail (largez) from underflowing.
The MLE has no closed form (the score equations couple mu, sigma2, lam), so the estimator uses a method-of-moments fit from the accumulated first three moments, which is consistent and the usual practical choice for the EMG.
- class ExponentiallyModifiedGaussianDistribution(mu, sigma2, lam, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionExponentially-modified Gaussian:
X = N(mu, sigma2) + Exp(rate=lam).- density(x)[source]
Density of the EMG at observation
x(seelog_density).
- log_density(x)[source]
Stable log-density of the EMG at
x.log f(x) = log(lam/2) - 0.5*u^2 + log_erfcx(z)withu = (x - mu)/sigmaandz = (lam*sigma - u)/sqrt(2).
- seq_ld_lambda()[source]
Return vectorized log-density callables for encoded data.
- seq_log_density(x)[source]
Vectorized EMG log-density at sequence-encoded input
x.
- classmethod compute_capabilities()[source]
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized EMG log-density for encoded data.
- cdf(x)[source]
Cumulative distribution function
P(X <= x)(exact, via scipy’s exponnorm).
- sampler(seed=None)[source]
Return an ExponentiallyModifiedGaussianSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
ExponentiallyModifiedGaussianSampler
- estimator(pseudo_count=None)[source]
Return an ExponentiallyModifiedGaussianEstimator (method-of-moments).
- Parameters:
pseudo_count (float | None)
- Return type:
ExponentiallyModifiedGaussianEstimator
- dist_to_encoder()[source]
Returns an ExponentiallyModifiedGaussianDataEncoder object.
- Return type:
ExponentiallyModifiedGaussianDataEncoder
- class ExponentiallyModifiedGaussianSampler(dist, seed=None)[source]
Bases:
DistributionSampler- Parameters:
dist (ExponentiallyModifiedGaussianDistribution)
seed (int | None)
- class ExponentiallyModifiedGaussianAccumulator(keys=None, name=None)[source]
Bases:
SequenceEncodableStatisticAccumulator- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (float)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_initialize(x, weights, rng)[source]
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- combine(suff_stat)[source]
- from_value(x)[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:
ExponentiallyModifiedGaussianAccumulator
- 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:
ExponentiallyModifiedGaussianDataEncoder
- class ExponentiallyModifiedGaussianAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactory- make()[source]
- Return type:
ExponentiallyModifiedGaussianAccumulator