mixle.stats.rankings.thurstone module¶
Thurstone (Thurstonian) ranking model – the Gaussian random-utility model over permutations.
Each item has a latent utility U_i ~ Normal(mu_i, 1) (Case V, equal variance) and an ordering is the
descending sort of the utilities, so
p(sigma) = P( U_sigma[0] > U_sigma[1] > … > U_sigma[n-1] ).
This is the Gaussian counterpart of PlackettLuceDistribution (which is the same construction
with Gumbel noise). The probability is the Gaussian-orthant probability of the consecutive-difference
cone D_r = U_sigma[r] - U_sigma[r+1] > 0; D has mean mu_sigma[r] - mu_sigma[r+1] and a fixed
tridiagonal covariance (2 on the diagonal, -1 off it), independent of sigma. There is no
closed form for n > 3, so the likelihood is a numba Genz separation-of-variables Monte-Carlo
estimate of the orthant (low variance, always positive) seeded deterministically. Sampling is exact
(draw utilities, sort); mu is fit in closed form from the pairwise-preference marginals (the
Thurstone-Mosteller Case V estimator), identified up to an additive constant (stored mean-zero).
Data type: List[int] – a full ordering, a permutation of 0..n-1 with x[r] the item at rank
r (best first).
- class ThurstoneDistribution(mu, name=None, keys=None, n_mc=4000, seed=0)[source]
Bases:
SequenceEncodableProbabilityDistributionThurstone Case V Gaussian random-utility ranking model with mean utilities
mu.- Parameters:
- classmethod compute_capabilities()[source]
Declare the NumPy and numba execution path used by Thurstone kernels.
- density(x)[source]
Return the probability of a full ordering.
- log_density(x)[source]
Return the log-probability of one full ordering.
- seq_log_density(x)[source]
Return vectorized log-probabilities for encoded full orderings.
- sampler(seed=None)[source]
Return an exact random-utility sampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
ThurstoneSampler
- estimator(pseudo_count=None)[source]
Return a Thurstone-Mosteller estimator with this distribution’s dimension.
- Parameters:
pseudo_count (float | None)
- Return type:
ThurstoneEstimator
- dist_to_encoder()[source]
Return the dense full-ranking encoder used by vectorized methods.
- Return type:
ThurstoneDataEncoder
- class ThurstoneSampler(dist, seed=None)[source]
Bases:
DistributionSamplerExact Thurstone draws: sample utilities
U ~ Normal(mu, 1)and sort descending.- Parameters:
dist (ThurstoneDistribution)
seed (int | None)
- class ThurstoneAccumulator(dim, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the pairwise-precedence matrix
precede[i, j]= weighted count ofiranked beforej.- update(x, weight, estimate)[source]
Update pairwise-precedence counts from one full ordering.
- initialize(x, weight, rng)[source]
Initialize precedence counts from one ordering.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update pairwise-precedence counts from encoded orderings.
- seq_initialize(x, weights, rng)[source]
Initialize precedence counts from a batch of encoded orderings.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge count and pairwise-precedence statistics.
- Return type:
ThurstoneAccumulator
- value()[source]
Return accumulated observation weight and pairwise-precedence matrix.
- from_value(x)[source]
Restore accumulator state from
valueoutput.- Return type:
ThurstoneAccumulator
- 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 ranking encoder compatible with this accumulator.
- Return type:
ThurstoneDataEncoder
- class ThurstoneAccumulatorFactory(dim, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for Thurstone pairwise-precedence statistics.
- make()[source]
Create an empty Thurstone accumulator.
- Return type:
ThurstoneAccumulator
- class ThurstoneEstimator(dim, n_mc=4000, seed=0, name=None, keys=None)[source]
Bases:
ParameterEstimatorThurstone-Mosteller Case V estimator:
mu_i - mu_j = sqrt(2) * Phi^{-1}(P(i before j)).- accumulator_factory()[source]
Return a factory for Thurstone sufficient-statistic accumulators.
- Return type:
ThurstoneAccumulatorFactory