mixle.stats.rankings.ewens module¶
Ewens distribution over permutations – the canonical cycle-structure (random-permutation) law.
A permutation is weighted by its number of cycles:
p(sigma) = theta^{cycles(sigma)} / Z, Z = theta (theta + 1) … (theta + n - 1) = Gamma(theta+n)/Gamma(theta).
theta = 1 is uniform over the n! permutations; theta -> 0 concentrates on single n-cycles
(few cycles); large theta concentrates on the identity (every point a fixed cycle). This is the
permutation form of the Ewens sampling formula (population genetics, random-permutation theory); its
induced partition by cycle sizes is what ChineseRestaurantProcessDistribution models.
Sufficient statistic: the cycle count, computed from the shared Cayley kernel
(cycles = n - cayley_distance(sigma, identity)). Sampling is an exact numba Chinese-restaurant /
Feller construction; theta is fit by matching the mean cycle count E[cycles] = sum_i theta/(theta+i).
Data type: List[int] – a permutation of 0..n-1 read as a function i -> sigma[i] (cycles of
that map are what the model scores).
- class EwensDistribution(dim, theta=1.0, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionEwens distribution over permutations of
0..n-1with cycle-weight parametertheta > 0.- classmethod compute_capabilities()[source]
Declare the NumPy and numba execution path used by Ewens kernels.
- density(x)[source]
Return the probability of one permutation.
- log_density(x)[source]
Return the log-probability of one permutation.
- seq_log_density(x)[source]
Return vectorized log-probabilities for encoded permutations.
- sampler(seed=None)[source]
Return an exact Ewens permutation sampler.
- Parameters:
seed (int | None)
- Return type:
EwensSampler
- estimator(pseudo_count=None)[source]
Return a cycle-count moment estimator for this dimension.
- Parameters:
pseudo_count (float | None)
- Return type:
EwensEstimator
- dist_to_encoder()[source]
Return the permutation encoder used by vectorized methods.
- Return type:
EwensDataEncoder
- class EwensSampler(dist, seed=None)[source]
Bases:
DistributionSamplerExact Ewens draws via the numba Chinese-restaurant construction.
- Parameters:
dist (EwensDistribution)
seed (int | None)
- class EwensAccumulator(dim, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the total (weighted) cycle count and observation weight.
- update(x, weight, estimate)[source]
Update cycle-count statistics from one weighted permutation.
- initialize(x, weight, rng)[source]
Initialize cycle-count statistics from one weighted permutation.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update cycle-count statistics from encoded permutations.
- seq_initialize(x, weights, rng)[source]
Initialize cycle-count statistics from encoded permutations.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge cycle-count totals and observation weight from another accumulator.
- Return type:
EwensAccumulator
- value()[source]
Return total weighted cycle count and total observation weight.
- from_value(x)[source]
Restore accumulator state from
valueoutput.- Return type:
EwensAccumulator
- key_merge(stats_dict)[source]
Merge this accumulator into
stats_dictunder its configured key.
- key_replace(stats_dict)[source]
Replace this accumulator’s state from keyed statistics when present.
- acc_to_encoder()[source]
Return the encoder compatible with Ewens cycle-count statistics.
- Return type:
EwensDataEncoder
- class EwensAccumulatorFactory(dim, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for Ewens cycle-count statistics.
- make()[source]
Create an empty Ewens accumulator.
- Return type:
EwensAccumulator
- class EwensEstimator(dim, theta=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorFit
thetaby matching the mean cycle countE[cycles] = sum_i theta/(theta+i).- accumulator_factory()[source]
Return a factory for Ewens sufficient-statistic accumulators.
- Return type:
EwensAccumulatorFactory