mixle.stats.rankings.low_rank_permutation module¶
Low-rank assignment (first-order Fourier) model over permutations.
A permutation Gibbs model that scores an ordering by a low-rank item-by-rank score matrix:
p(sigma) = exp( sum_r S[sigma[r], r] ) / Z, S = U V^T (rank r << n), Z = permanent(exp(S)).
This is the maximum-entropy distribution matching first-order (item-at-rank) marginals – the
first-order term of the Fourier / coset expansion on the symmetric group – and the low-rank
factorization S = U V^T is the structured, O(n r)-parameter version of the full
MatchingDistribution. The normalizer is a permanent (#P-hard), so it is computed exactly by a
numba Ryser kernel for n <= max_exact and approximated by a numba Sinkhorn / Bethe permanent beyond
that (documented approximation). Fitting is a Sinkhorn-marginal gradient ascent on U, V toward the
empirical item-by-rank marginals.
Data type: List[int] – a full ordering, a permutation of 0..n-1 with x[r] the item at rank
r (best first).
- class LowRankPermutationDistribution(u, v, name=None, keys=None, max_exact=12, sinkhorn_iter=200)[source]
Bases:
SequenceEncodableProbabilityDistributionPermutation Gibbs model with a low-rank item-by-rank score matrix
S = U V^T.- Parameters:
- classmethod compute_capabilities()[source]
Declare the NumPy and numba execution path used by low-rank permutation 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.
- marginals()[source]
Model first-order marginals
P[item, rank](Sinkhorn doubly-stochastic transport plan).- Return type:
- sampler(seed=None)[source]
Return a Metropolis sampler for this low-rank assignment model.
- Parameters:
seed (int | None)
- Return type:
LowRankPermutationSampler
- estimator(pseudo_count=None)[source]
Return a Sinkhorn-marginal estimator with this dimension and rank.
- Parameters:
pseudo_count (float | None)
- Return type:
LowRankPermutationEstimator
- dist_to_encoder()[source]
Return the full-ranking encoder used by vectorized methods.
- Return type:
LowRankPermutationDataEncoder
- class LowRankPermutationSampler(dist, seed=None, burn=2000, thin=20)[source]
Bases:
DistributionSamplerDraw orderings via a numba Metropolis sampler on the assignment scores.
- class LowRankPermutationAccumulator(dim, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the item-by-rank count matrix
C[item, rank]– the first-order sufficient statistic.- update(x, weight, estimate)[source]
Update item-by-rank counts from one weighted ordering.
- initialize(x, weight, rng)[source]
Initialize item-by-rank counts from one weighted ordering.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update item-by-rank counts from encoded orderings.
- seq_initialize(x, weights, rng)[source]
Initialize item-by-rank counts from encoded orderings.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge observation weight and item-by-rank count statistics.
- Return type:
LowRankPermutationAccumulator
- value()[source]
Return accumulated observation weight and item-by-rank counts.
- from_value(x)[source]
Restore accumulator state from
valueoutput.- Return type:
LowRankPermutationAccumulator
- 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 item-by-rank sufficient statistics.
- Return type:
LowRankPermutationDataEncoder
- class LowRankPermutationAccumulatorFactory(dim, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for low-rank permutation sufficient statistics.
- make()[source]
Create an empty low-rank permutation accumulator.
- Return type:
LowRankPermutationAccumulator
- class LowRankPermutationEstimator(dim, rank=2, max_exact=12, sinkhorn_iter=200, max_iter=300, lr=0.5, name=None, keys=None)[source]
Bases:
ParameterEstimatorFit
U, Vby Sinkhorn-marginal gradient ascent toward the empirical item-by-rank marginals.- Parameters:
- accumulator_factory()[source]
Return a factory for low-rank permutation sufficient-statistic accumulators.
- Return type:
LowRankPermutationAccumulatorFactory