mixle.stats.directional.kent module¶
Kent (Fisher-Bingham FB5) distribution on the 2-sphere.
The Kent distribution is the elliptical analogue of the von Mises-Fisher law on S^2 (unit vectors in
R^3). Its density at a unit vector x is
f(x) = c(kappa, beta)^{-1} exp( kappa * (g1 . x) + beta * [(g2 . x)^2 - (g3 . x)^2] ),
where G = [g1, g2, g3] is a 3 x 3 orthonormal orientation (g1 the mean direction, g2 the
major axis, g3 the minor axis), kappa > 0 is the concentration and 0 <= 2 beta < kappa the
ovalness. beta = 0 recovers von Mises-Fisher (circular contours); beta -> kappa/2 gives highly
elliptical (girdle-like) contours. It is the standard model for asymmetric clusters of orientations
(palaeomagnetism, structural geology, spherical data).
Normalizer (verified to 1e-12 against arbitrary-precision integration over S^2):
c(kappa, beta) = 2 pi sum_{j>=0} [Gamma(j+1/2)/Gamma(j+1)] beta^{2j} (2/kappa)^{2j+1/2} I_{2j+1/2}(kappa),
evaluated in log space with exponentially scaled Bessel functions for numerical stability. Sampling is by
exact von Mises-Fisher-envelope rejection; kappa, beta and the orientation are fit by Kent’s moment
method (mean direction + tangential scatter eigenvectors) followed by a maximum-likelihood refinement of
(kappa, beta).
Reference: Kent, “The Fisher-Bingham distribution on the sphere”, J. Royal Statistical Society B 44 (1982); Mardia & Jupp, Directional Statistics (2000), ch. 9.
- class KentDistribution(gamma, kappa, beta, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionKent (FB5) distribution on
S^2with orientationgamma(3x3), concentration and ovalness.- density(x)[source]
Return the probability density or mass at a single observation.
Concrete default: exponentiate
log_density(the abstract method subclasses must provide). Leaves with a cheaper closed form may override this.
- log_density(x)[source]
Return the log-density at a unit 3-vector
x.
- seq_log_density(x)[source]
Return vectorized log-density for a sequence-encoded
(n, 3)array of unit vectors.
- classmethod compute_capabilities()[source]
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized log-density for
(N, 3)unit vectors.
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
KentSampler
- estimator(pseudo_count=None)[source]
Return an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
KentEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
KentDataEncoder
- class KentSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample by von Mises-Fisher-envelope rejection (exact).
- Parameters:
dist (KentDistribution)
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.
- class KentAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate
(count, sum_x (3,), sum_xx (3,3))– the sufficient statistics for the moment fit.- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
- 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:
KentDataEncoder
- class KentAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for KentAccumulator.
- make()[source]
- Return type:
KentAccumulator