mixle.stats.univariate.continuous.skew_normal module¶
Skew-normal distribution – a Gaussian with an asymmetry (shape) parameter.
The skew-normal extends the normal with a shape alpha that tilts the density without bounding it:
f(x) = (2 / omega) phi((x - xi) / omega) Phi(alpha (x - xi) / omega),
with location xi, scale omega > 0 and shape alpha (alpha = 0 recovers the normal, the
sign of alpha sets the direction of skew). It samples exactly from two standard normals, and is fit
by method of moments: the sample skewness fixes alpha through the monotone skewness-vs-shape
relation, then the variance fixes omega and the mean fixes xi.
Reference: Azzalini, ‘A class of distributions which includes the normal ones’, Scand. J. Statist. (1985).
- class SkewNormalDistribution(loc, scale, shape, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionSkew-normal distribution with location
loc, scale> 0and shapealpha.- density(x)[source]
Return the probability density at a single observation.
- log_density(x)[source]
Return the log-density at a single observation.
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded observations.
- classmethod compute_capabilities()[source]
Describe backend support for generated skew-normal scoring kernels.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized skew-normal log-density for encoded data.
- cdf(x)[source]
Cumulative distribution function
P(X <= x)(exact).
- mean()[source]
Mean E[X] = loc + scale * delta * sqrt(2/pi), delta = shape / sqrt(1 + shape^2).
- Return type:
- variance()[source]
Variance Var[X] = scale^2 (1 - 2 delta^2 / pi), delta = shape / sqrt(1 + shape^2).
- Return type:
- entropy()[source]
Differential entropy log(scale) + 0.5 log(2 pi e) - log(2) - E[log Phi(alpha Y)].
Yis the standard skew-normal(alpha);E[Y^2] = 1for every alpha (a property of the two-Gaussian stochastic representation) collapses the Gaussian part of the log-density to a closed form, leavingE[log Phi(alpha Y)]. That term has no closed form for general alpha (Arellano-Valle, Contreras-Reyes & Genton, ‘Shannon entropy and mutual information for multivariate skew-elliptical distributions’, Scand. J. Statist. 40 (2013)), so it is evaluated by adaptive quadrature against the standard skew-normal density itself.- Return type:
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
SkewNormalSampler
- estimator(pseudo_count=None)[source]
Return a method-of-moments estimator for
loc,scaleandshape.- Parameters:
pseudo_count (float | None)
- Return type:
SkewNormalEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
SkewNormalDataEncoder
- class SkewNormalSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw observations as
xi + omega (delta * abs(Z0) + sqrt(1-delta^2) Z1)withZ0, Z1standard normal.- Parameters:
dist (SkewNormalDistribution)
seed (int | None)
- class SkewNormalAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate weighted central moments for skew-normal estimation.
The sufficient statistic is stored as
(count, mean, M2, M3)whereM2 = sum_i w_i (x_i - mean)^2andM3 = sum_i w_i (x_i - mean)^3are the weighted central moments. This is mathematically equivalent to the raw power sums(sum x, sum x^2, sum x^3)but avoids the catastrophicE[x^2] - E[x]^2cancellation whenabs(mean)is large relative to the spread: each batch is centered on its own mean before squaring/cubing, and batches merge through the Pébay/West parallel-moment formulas (exact for real weights). SkewNormal is a host-only leaf (no exponential-family / engine-resident path), so changing the accumulator representation has no engine-swap parity implications.- update(x, weight, estimate)[source]
Accumulate a single weighted observation into central moments.
- initialize(x, weight, rng)[source]
Initialize statistics from one observation.
- Parameters:
x (float)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted central moments from encoded observations.
Centering the batch on its own mean removes the
E[x^2]-E[x]^2cancellation, but a SINGLE centering pass does not remove all of it: the computedmeancarries the rounding of a large-magnitude sum, and that residue enters the third moment linearly, which left the fitted shape 1.1e-3 off at offset 1e12 and 5e-7 off at the Unix-epoch offset. The second pass incentered_batch_moments()computes the residue at spread scale, where it is exact, and makes the fit shift-equivariant.
- seq_initialize(x, weights, rng)[source]
Initialize statistics from encoded observations.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge another central-moment statistic tuple.
- value()[source]
Return count, mean, second central moment sum, and third central moment sum.
- from_value(x)[source]
Replace accumulator contents from a central-moment statistic tuple.
- scale(c)[source]
Scale weight-linear statistics while preserving the weighted mean.
- Parameters:
c (float)
- Return type:
SkewNormalAccumulator
- acc_to_encoder()[source]
Return the encoder used by this accumulator.
- Return type:
SkewNormalDataEncoder
- class SkewNormalAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for SkewNormalAccumulator.
- make()[source]
Create a fresh skew-normal accumulator.
- Return type:
SkewNormalAccumulator
- class SkewNormalEstimator(pseudo_count=None, suff_stat=None, min_scale=1.0e-12, name=None, keys=None)[source]
Bases:
ParameterEstimatorMethod-of-moments estimator for skew-normal location, scale and shape.
The fit is SHIFT-EQUIVARIANT: estimating on
x + creturnsloc + cwithscaleandshapeunchanged, for any constantcthe data can carry – epoch seconds (~1.7e9), 2**31 and 1e12 included. The moments come fromSkewNormalAccumulator, which centers each batch twice for exactly this reason; a single centering pass left the fitted shape 1.1e-3 off at 1e12, silently.- Parameters:
- accumulator_factory()[source]
Return an accumulator factory for skew-normal moment statistics.
- Return type:
SkewNormalAccumulatorFactory