mixle.stats.rankings.paired_comparison module¶
Paired-comparison models beyond plain Bradley-Terry: Gaussian pairwise and ties.
Three canonical models that complete the pairwise-comparison family:
ThurstoneMostellerDistribution– the Gaussian (probit) pairwise modelP(i beats j) = Phi((mu_i - mu_j) / sqrt(2)); the pairwise peer ofThurstoneDistributionand the Gaussian counterpart ofBradleyTerryDistribution. Observation:(winner, loser).DavidsonDistribution– Bradley-Terry with ties (Davidson 1970): a draw has probabilitynu * sqrt(w_i w_j) / (w_i + w_j + nu sqrt(w_i w_j)). Observation:(i, j, outcome)withoutcomein{0: i wins, 1: j wins, 2: tie}.RaoKupperDistribution– Bradley-Terry with ties via a thresholdnu >= 1(Rao-Kupper 1967):P(i beats j) = w_i / (w_i + nu w_j). Same(i, j, outcome)observation.
All three treat the compared pair as a uniform draw over the C(K, 2) unordered pairs, making them
proper distributions over (canonicalized) comparison outcomes. Worths/utilities are identified up to a
shift and stored mean-zero. Fitting maximizes the comparison log-likelihood from the win/tie count
matrices (the sufficient statistic).
- class ThurstoneMostellerFitDiagnostics(method, exact_mle, graph_connected, clipped_pair_probabilities, regularized, pseudo_count, strongly_connected)[source]
Bases:
objectProvenance and identifiability evidence for the pairwise-moment fit.
- class TieModelFitDiagnostics(model, converged, status, message, iterations, objective, gradient_norm, worth_boundary_hit, tie_parameter_boundary_hit, graph_connected, regularized, pseudo_count, strongly_connected)[source]
Bases:
objectOptimizer, identifiability, and boundary evidence for a tie-model fit.
- class ThurstoneMostellerDistribution(mu, name=None, keys=None, fit_diagnostics=None)[source]
Bases:
SequenceEncodableProbabilityDistributionGaussian/probit paired-comparison model
P(i beats j) = Phi((mu_i - mu_j) / sqrt(2)).- Parameters:
- classmethod compute_capabilities()[source]
Return backend capabilities for the probit pairwise likelihood.
- density(x)[source]
Return the probability mass of one winner-loser pair.
- log_density(x)[source]
Return the JOINT log probability of one winner-loser pair.
The pair is drawn uniformly from all
K(K-1)/2unordered pairs and the winner follows the probit rule, soexp(log_density((i, j))) + exp(log_density((j, i)))is1/C(K, 2), not one.P(i beats j | compared)iswin_probability().
- win_probability(i, j)[source]
Return
P(i beats j | i and j are compared)=Phi((mu[i] - mu[j]) / sqrt(2)).
- seq_log_density(x)[source]
Score encoded winner-loser pairs.
- sampler(seed=None)[source]
Return a sampler for winner-loser comparisons.
- Parameters:
seed (int | None)
- Return type:
ThurstoneMostellerSampler
- estimator(pseudo_count=None)[source]
Return the least-squares probit paired-comparison estimator.
- Parameters:
pseudo_count (float | None)
- Return type:
ThurstoneMostellerEstimator
- dist_to_encoder()[source]
Return the encoder for winner-loser pair data.
- Return type:
PairDataEncoder
- class ThurstoneMostellerSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSampler for Thurstone-Mosteller winner-loser comparisons.
- Parameters:
dist (ThurstoneMostellerDistribution)
seed (int | None)
- class ThurstoneMostellerEstimator(dim, pseudo_count=None, name=None, keys=None)[source]
Bases:
ParameterEstimatormu_i - mu_j = sqrt(2) Phi^{-1}(P(i beats j))from the win-count matrix (least squares).pseudo_countadds that many fractional wins to every ordered pair before the moment step; seeBradleyTerryEstimatorfor how to choose it and what it does to margins. Here it also keeps a never-lost pair away from thePhi^{-1}clip (clipped_pair_probabilitiescounts the pairs that hit it).- accumulator_factory()[source]
Return the accumulator factory used by this estimator.
- Return type:
PairWinAccumulatorFactory
- class PairWinAccumulator(dim, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorWin-count matrix
wins[i, j]for (winner, loser) pair data.- update(x, weight, estimate)[source]
Accumulate one weighted winner-loser observation.
- initialize(x, weight, rng)[source]
Initialize sufficient statistics from one weighted pair.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted winner-loser pairs from an encoded batch.
- seq_initialize(x, weights, rng)[source]
Initialize sufficient statistics from an encoded weighted batch.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge serialized win-count sufficient statistics.
- Return type:
PairWinAccumulator
- value()[source]
Return serialized win-count sufficient statistics.
- from_value(x)[source]
Restore accumulator state from serialized win counts.
- Return type:
PairWinAccumulator
- acc_to_encoder()[source]
Return the encoder associated with this accumulator.
- Return type:
PairDataEncoder
- class PairWinAccumulatorFactory(dim, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for paired win-count accumulators.
- make()[source]
Create a fresh paired-win accumulator.
- Return type:
PairWinAccumulator
- class PairDataEncoder(dim=None)[source]
Bases:
DataSequenceEncoderEncode
(winner, loser)pairs into an(N, 2)integer array.- Parameters:
dim (int | None)
- class DavidsonDistribution(log_w, nu=1.0, name=None, keys=None, fit_diagnostics=None)[source]
Bases:
_BaseTieDistributionBradley-Terry with ties (Davidson 1970); tie mass
nu sqrt(w_i w_j).- Parameters:
- class DavidsonEstimator(dim, pseudo_count=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorMaximum-likelihood Davidson worths and tie parameter (L-BFGS on the count matrices).
pseudo_countadds that many fractional wins to every ordered pair and that many ties to every unordered pair; seeBradleyTerryEstimatorfor how to choose it. Without it, data in which some competitor never lost (or never won) has no finite fit and the estimator raisesValueErrorrather than return a boundary worth.- accumulator_factory()[source]
Return the accumulator factory used by this estimator.
- Return type:
_TieAccumulatorFactory
- class RaoKupperDistribution(log_w, nu=1.5, name=None, keys=None, fit_diagnostics=None)[source]
Bases:
_BaseTieDistributionBradley-Terry with ties via a threshold
nu >= 1(Rao-Kupper 1967).- Parameters:
- class RaoKupperEstimator(dim, pseudo_count=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorMaximum-likelihood Rao-Kupper worths and threshold (L-BFGS on the count matrices).
pseudo_countadds that many fractional wins to every ordered pair and that many ties to every unordered pair; seeBradleyTerryEstimatorfor how to choose it. Without it, data in which some competitor never lost (or never won) has no finite fit and the estimator raisesValueErrorrather than return a boundary worth.- accumulator_factory()[source]
Return the accumulator factory used by this estimator.
- Return type:
_TieAccumulatorFactory