mixle.stats.rankings.generalized_mallows_model module¶
Generalized Mallows Model (GMM): Mallows with a separate dispersion per ranking stage.
The Generalized Mallows Model (Fligner & Verducci, 1986) refines the Kendall Mallows model by giving
each stage of the ranking its own dispersion. Writing an ordering’s Repeated-Insertion-Model code
J = (J_1, ..., J_{n-1}) relative to the central permutation sigma0 (J_i in {0..i} is the
back-jump of central item i; sum_i J_i is the Kendall distance), the GMM makes the stages
independent truncated-geometrics:
p(sigma) = exp(-sum_i theta_i J_i(sigma)) / Z, Z = prod_i psi_i(theta_i), psi_i(theta_i) = sum_{r=0}^{i} exp(-theta_i r) = (1 - exp(-theta_i (i+1))) / (1 - exp(-theta_i)).
Everything factorizes over stages, so the normalizer, the moments E[J_i], exact RIM sampling, and
maximum likelihood are all closed form and the per-datum statistic J is a numba kernel. The model
captures rankings that are firm at the top but loose at the bottom (decreasing theta_i) and vice
versa – structure a single-dispersion Mallows cannot represent.
Data type: List[int] – a full ordering, a permutation of 0..n-1 with x[r] the item at rank
r (best first).
- class GeneralizedMallowsModelDistribution(sigma0, theta=None, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionGeneralized Mallows Model: a Kendall Mallows model with a per-stage dispersion vector
theta.- Parameters:
- classmethod compute_capabilities()[source]
Declare the NumPy execution path used by stage-wise Mallows kernels.
- density(x)[source]
Return the probability of one ordering.
- log_density(x)[source]
Return the log-probability of one ordering.
- seq_log_density(x)[source]
Return vectorized log-probabilities for encoded orderings.
- sampler(seed=None)[source]
Return an exact repeated-insertion sampler for this model.
- Parameters:
seed (int | None)
- Return type:
GeneralizedMallowsModelSampler
- estimator(pseudo_count=None)[source]
Return a stage-wise Mallows estimator with this item count.
- Parameters:
pseudo_count (float | None)
- Return type:
GeneralizedMallowsModelEstimator
- dist_to_encoder()[source]
Return the full-ranking encoder used by vectorized methods.
- Return type:
GeneralizedMallowsModelDataEncoder
- class GeneralizedMallowsModelSampler(dist, seed=None)[source]
Bases:
DistributionSamplerExact GMM draws via the per-stage Repeated Insertion Model.
- Parameters:
dist (GeneralizedMallowsModelDistribution)
seed (int | None)
- class GeneralizedMallowsModelAccumulator(dim, reservoir=10000, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorPrecede matrix (Copeland consensus) + count + a bounded reservoir for the per-stage means.
- update(x, weight, estimate)[source]
Update consensus and reservoir statistics from one weighted ordering.
- initialize(x, weight, rng)[source]
Initialize consensus and reservoir statistics from one ordering.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update consensus and reservoir statistics from encoded orderings.
- seq_initialize(x, weights, rng)[source]
Initialize statistics from encoded orderings.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge observation weight, precedence counts, and reservoir samples.
- Return type:
GeneralizedMallowsModelAccumulator
- value()[source]
Return count, precedence matrix, and bounded reservoir contents.
- from_value(x)[source]
Restore accumulator state from
valueoutput.- Return type:
GeneralizedMallowsModelAccumulator
- 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 these sufficient statistics.
- Return type:
GeneralizedMallowsModelDataEncoder
- class GeneralizedMallowsModelAccumulatorFactory(dim, reservoir=10000, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for stage-wise Generalized Mallows statistics.
- make()[source]
Create an empty stage-wise Generalized Mallows accumulator.
- Return type:
GeneralizedMallowsModelAccumulator
- class GeneralizedMallowsModelEstimator(dim, reservoir=10000, name=None, keys=None)[source]
Bases:
ParameterEstimatorCopeland consensus for
sigma0and a per-stage moment match for eachtheta_i.- accumulator_factory()[source]
Return a factory for stage-wise Mallows sufficient-statistic accumulators.
- Return type:
GeneralizedMallowsModelAccumulatorFactory