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]
- density(x)[source]
Return the probability density or mass at a single observation.
Concrete default: exponentiate
log_density(the abstract method subclasses must provide). Leaves with a cheaper closed form may override this.
- log_density(x)[source]
Return the log-density or log-mass at a single observation.
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded observations.
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
ThurstoneSampler
- estimator(pseudo_count=None)[source]
Return an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
ThurstoneEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for 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)
- sample(size=None)[source]
Draw observations.
Combinator samplers (mixture/sequence/…) accept
batched. Withbatched=True(the default) each child stream is drawn in one vectorized call instead of a per-draw Python loop – far faster. Because every child sampler owns an independentRandomState, batching consumes each stream in the same order as the loop, so the draws are identical to the legacy path.batched=Falseforces that legacy per-draw loop as a guaranteed- stable reference. Leaf samplers are already vectorized and ignore the flag.
- class ThurstoneAccumulator(dim, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the pairwise-precedence matrix
precede[i, j]= weighted count ofiranked beforej.- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
- Return type:
ThurstoneAccumulator
- value()[source]
- from_value(x)[source]
- Return type:
ThurstoneAccumulator
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- key_replace(stats_dict)[source]
Replace this accumulator’s statistics from the pooled
stats_dictentry (see key_merge).
- acc_to_encoder()[source]
- Return type:
ThurstoneDataEncoder
- class ThurstoneAccumulatorFactory(dim, keys=None)[source]
Bases:
StatisticAccumulatorFactory- make()[source]
- 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 type:
ThurstoneAccumulatorFactory