mixle.stats.directional.von_mises module¶
Create, estimate, and sample from a von Mises distribution on the circle (angular data).
Defines the VonMisesDistribution, VonMisesSampler, VonMisesAccumulatorFactory, VonMisesAccumulator, VonMisesEstimator, and the VonMisesDataEncoder classes for use with mixle.
Data type: (float): an angle in radians. The VonMisesDistribution with mean direction mu and concentration kappa >= 0 has log-density
log(f(theta; mu, kappa)) = kappa * cos(theta - mu) - log(2*pi*I_0(kappa)),
the circular analogue of a Gaussian (kappa = 0 is uniform on the circle; large kappa concentrates near
mu). This is the one-dimensional companion to von_mises_fisher (the von
Mises-Fisher distribution on a sphere).
It is a two-parameter exponential family with sufficient statistics (cos theta, sin theta):
- log(f) = eta1*cos(theta) + eta2*sin(theta) + log_const,
eta1 = kappa*cos(mu), eta2 = kappa*sin(mu), log_const = -log(2*pi*I_0(kappa)).
The natural parameters and normalizer are precomputed (the Bessel term I_0 lives only in the scalar
log_const), so the per-row score is linear in the encoded cos/sin fields and lowers cleanly
to generated NumPy, Torch, and Numba kernels.
Reference: Mardia & Jupp, Directional Statistics (Wiley, 2000).
- class VonMisesDistribution(mu, kappa, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionVon Mises distribution on the circle with mean direction mu and concentration kappa >= 0.
- classmethod compute_capabilities()[source]
- classmethod compute_declaration()[source]
- static backend_legacy_sufficient_statistics(x, params, engine)[source]
Return per-row (count, cos, sin) sufficient statistics in accumulator order.
- static exp_family_sufficient_statistics(x, engine)[source]
Return von Mises sufficient statistics
T(x) = (cos x, sin x).
- static exp_family_natural_parameters(params, engine)[source]
Return von Mises natural parameters
eta = (kappa cos mu, kappa sin mu).
- static exp_family_log_partition(params, engine)[source]
Return von Mises log partition
A = log(2 pi I_0(kappa)) = -log_const.
- static exp_family_from_natural(eta)[source]
Return the von Mises with natural parameters
eta = (kappa cos mu, kappa sin mu).- Parameters:
eta (Any)
- Return type:
VonMisesDistribution
- static backend_log_density_from_params(cos_t, sin_t, eta1, eta2, log_const, engine)[source]
Engine-neutral von Mises log-density from natural parameters (linear in cos/sin).
- density(x)[source]
Return the probability density at a single angle.
- log_density(x)[source]
Return the log-density at a single angle (radians).
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded (cos, sin) observations.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized log-density for encoded data.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked natural parameters for a homogeneous mixture kernel.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of von Mises log densities.
- classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]
Return stacked sufficient statistics using engine-resident arrays.
- sampler(seed=None)[source]
Return a sampler for drawing angles from this distribution.
- Parameters:
seed (int | None)
- Return type:
VonMisesSampler
- estimator(pseudo_count=None)[source]
Return an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
VonMisesEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
VonMisesDataEncoder
- class VonMisesSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw iid angles from a von Mises distribution.
- Parameters:
dist (VonMisesDistribution)
seed (int | None)
- class VonMisesAccumulator(keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate weighted count and circular moments (sum of cos / sin) for von Mises estimation.
- Parameters:
keys (str | None)
- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (float)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- Parameters:
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:
VonMisesDataEncoder
- class VonMisesAccumulatorFactory(keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for VonMisesAccumulator.
- Parameters:
keys (str | None)
- make()[source]
- Return type:
VonMisesAccumulator
- class VonMisesEstimator(pseudo_count=None, suff_stat=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorMaximum-likelihood estimator for the von Mises mean direction and concentration.
The MLE is
mu = atan2(sum sin, sum cos)andkappa = A^{-1}(R)whereRis the mean resultant length andA(kappa) = I_1(kappa) / I_0(kappa).- Parameters:
- accumulator_factory()[source]
- Return type:
VonMisesAccumulatorFactory