mixle.stats.rankings.bradley_terry module¶
Bradley-Terry model for paired comparisons.
Each observation is an ordered pair (winner, loser) drawn from K items; the model gives every
item a latent worth w_i = exp(log_w_i) and sets
P(i beats j) = w_i / (w_i + w_j) = sigmoid(log_w_i - log_w_j).
Treating the compared pair as a uniform draw over the C(K, 2) unordered pairs makes this a proper
distribution over ordered pairs:
p(winner, loser) = (1 / C(K, 2)) * sigmoid(log_w[winner] - log_w[loser]).
Worths are identified up to a global scale, so log_w is stored centered (mean zero). Estimation is
the Zermelo / minorization-maximization fixed point (Hunter 2004), a few low-cost numba iterations over the
K x K win-count matrix – the sufficient statistic. Unlike PlackettLuceDistribution (full
orderings) this consumes pairwise data directly.
Data type: Tuple[int, int] – (winner, loser) item indices in 0..K-1 (winner != loser).
- class BradleyTerryDistribution(log_w, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionBradley-Terry paired-comparison model with centered log-worths
log_w.- classmethod compute_capabilities()[source]
Declare the NumPy and numba execution path used by Bradley-Terry kernels.
- density(x)[source]
Return the probability of one
(winner, loser)comparison.
- log_density(x)[source]
Return the log-probability of one
(winner, loser)comparison.
- seq_log_density(x)[source]
Return vectorized log-probabilities for encoded pairwise comparisons.
- sampler(seed=None)[source]
Return a sampler for paired-comparison outcomes.
- Parameters:
seed (int | None)
- Return type:
BradleyTerrySampler
- estimator(pseudo_count=None)[source]
Return an MM estimator with this distribution’s item count.
- Parameters:
pseudo_count (float | None)
- Return type:
BradleyTerryEstimator
- dist_to_encoder()[source]
Return the pairwise-comparison encoder used by vectorized methods.
- Return type:
BradleyTerryDataEncoder
- class BradleyTerrySampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw
(winner, loser)pairs: a uniform unordered pair, then a Bradley-Terry outcome.- Parameters:
dist (BradleyTerryDistribution)
seed (int | None)
- class BradleyTerryAccumulator(dim, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the
K x Kwin-count matrix:wins[i, j]= weighted count ofibeatingj.- update(x, weight, estimate)[source]
Update the win-count matrix from one weighted comparison.
- initialize(x, weight, rng)[source]
Initialize win counts from one weighted comparison.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update win counts from encoded pairwise comparisons.
- seq_initialize(x, weights, rng)[source]
Initialize win counts from encoded pairwise comparisons.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge observation count and win-count matrix statistics.
- Return type:
BradleyTerryAccumulator
- value()[source]
Return accumulated observation weight and win-count matrix.
- from_value(x)[source]
Restore accumulator state from
valueoutput.- Return type:
BradleyTerryAccumulator
- 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 Bradley-Terry win-count statistics.
- Return type:
BradleyTerryDataEncoder
- class BradleyTerryAccumulatorFactory(dim, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for Bradley-Terry win-count statistics.
- make()[source]
Create an empty Bradley-Terry accumulator.
- Return type:
BradleyTerryAccumulator
- class BradleyTerryEstimator(dim, pseudo_count=None, max_iter=500, tol=1e-10, name=None, keys=None)[source]
Bases:
ParameterEstimatorMaximum-likelihood log-worths via the Zermelo / MM fixed point (Hunter 2004).
- Parameters:
- accumulator_factory()[source]
Return a factory for Bradley-Terry sufficient-statistic accumulators.
- Return type:
BradleyTerryAccumulatorFactory