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: SequenceEncodableProbabilityDistribution

Thurstone Case V Gaussian random-utility ranking model with mean utilities mu.

Parameters:
  • mu (Sequence[float] | np.ndarray)

  • name (str | None)

  • keys (str | None)

  • n_mc (int)

  • seed (int)

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.

Parameters:

x (Sequence[int])

Return type:

float

log_density(x)[source]

Return the log-probability of one full ordering.

Parameters:

x (Sequence[int])

Return type:

float

seq_log_density(x)[source]

Return vectorized log-probabilities for encoded full orderings.

Parameters:

x (ndarray)

Return type:

ndarray

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: DistributionSampler

Exact Thurstone draws: sample utilities U ~ Normal(mu, 1) and sort descending.

Parameters:
  • dist (ThurstoneDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw one ordering or size iid orderings.

Parameters:

size (int | None)

Return type:

list[int] | list[list[int]]

class ThurstoneAccumulator(dim, keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate the pairwise-precedence matrix precede[i, j] = weighted count of i ranked before j.

Parameters:
update(x, weight, estimate)[source]

Update pairwise-precedence counts from one full ordering.

Parameters:
Return type:

None

initialize(x, weight, rng)[source]

Initialize precedence counts from one ordering.

Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]

Update pairwise-precedence counts from encoded orderings.

Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]

Initialize precedence counts from a batch of encoded orderings.

Parameters:
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 value output.

Return type:

ThurstoneAccumulator

key_merge(stats_dict)[source]

Merge this accumulator into stats_dict under its configured key.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator’s state from keyed statistics when present.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]

Return the ranking encoder compatible with this accumulator.

Return type:

ThurstoneDataEncoder

class ThurstoneAccumulatorFactory(dim, keys=None)[source]

Bases: StatisticAccumulatorFactory

Create accumulators for Thurstone pairwise-precedence statistics.

Parameters:
make()[source]

Create an empty Thurstone accumulator.

Return type:

ThurstoneAccumulator

class ThurstoneEstimator(dim, n_mc=4000, seed=0, name=None, keys=None)[source]

Bases: ParameterEstimator

Thurstone-Mosteller Case V estimator: mu_i - mu_j = sqrt(2) * Phi^{-1}(P(i before j)).

Parameters:
accumulator_factory()[source]

Return a factory for Thurstone sufficient-statistic accumulators.

Return type:

ThurstoneAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate centered latent utilities from pairwise-precedence statistics.

Parameters:

nobs (float | None)

Return type:

ThurstoneDistribution

class ThurstoneDataEncoder(dim=None)[source]

Bases: DataSequenceEncoder

Encode a sequence of orderings (permutations of 0,…,n-1) into an (N, n) integer array.

Parameters:

dim (int | None)

seq_encode(x)[source]

Validate and encode full orderings as a dense integer matrix.

Parameters:

x (Sequence[Sequence[int]])

Return type:

ndarray