sparsax.argmax_logprob¶
-
sparsax.argmax_logprob(Ai, Aj, Ax, mean, chosen, competitors=
None, n_draws=128, seed=0, keys=None, draws='sobol')[source]¶ Log-probability that
chosenis the largest component of a sparse-precision Gaussian.For
x ~ N(mean, A^{-1})withAthe SPD precision, returnslog P(argmax_k x_k = chosen): the choice probability of a multinomial probit whose utilities form a Gaussian Markov random field (a spatial multinomial probit, say, withA = (I - ρW)'(I - ρW)). It is estimated by the GHK simulator, run on the sparse factor ofArather than on the dense covariance of the utility differences, so a draw costsO(nnz(L))rather thanO(n^2): the differences’ precision isA_{-j,-j} - v v'/c(v = (A 1)_{-j},c = 1'A1), and the rank-one term has a closed-form factor.Amust be symmetric positive definite, but the model behind it need not be symmetric: for a SAR with any weightsW, directed or not,A = M'MwithM = I - ρWis SPD wheneverMis nonsingular, so CHOLMOD always applies and no LU backend is needed. The same cached factor gives the means:M^{-1} X β = A^{-1} M' X β, onesolve().The estimate is unbiased for the probability (so slightly biased low for its log, by about half the relative variance), and its variance depends on the order in which the alternatives are drawn: those most likely to beat
chosenshould come first. Pass them ascompetitors, e.g. theK ≈ 10-30alternatives with the largestmean; they are moved to the end of the elimination order (cholmod_rowdelplus a denseK x Kblock) while everything else keeps the fill-reducing order. Without them, variance grows quickly withn.The first 256 steps of each path take scrambled Sobol points rather than independent draws, competitors first. Nested uniform scrambling, keyed on
(seed, keys[p]), keeps each point uniform on the cube, so the estimate stays unbiased and each decision-maker’s points are independent of the others’. Atn = 4,900with 30 competitors and 128 draws, the median variance of the log-probability fell 34x when the means spread widely across alternatives and 2.2x when they were nearly flat, for about 5% more time, and up to about 30% more on small problems, where more of the steps are scrambled. Keepn_drawsa power of two, which is where the points balance.Draws are a fixed function of
(seed, keys[p], draw, step), so repeated calls reproduce them and the result is a smooth function ofmean, as simulated maximum likelihood needs; the competitor lists fix the variable order, so hold them fixed while optimizing. All paths share one cached factorization ofAand run in parallel (SPARSAX_NUM_THREADS).Differentiable in
meanby reverse mode (jax.grad,jax.vjp): the handler computesd logp / d meanwith a reverse sweep through the recursion, at about the cost of the forward pass. There is no derivative with respect toA, so a gradient that flows throughAxraisesValueError: wrapAxinjax.lax.stop_gradientto hold it fixed, or difference in the parameter ofA(the draws are fixed, so the log-probability is smooth in it). There is no forward-mode rule.Memory: each worker thread holds about
2 * n * n_drawsfloat64 values of per-draw state (4 * n * n_drawswith gradients), e.g. 8 MB atn = 5000and 100 draws.- Parameters:¶
- Ai¶
COO of the SPD precision
A, as insolve().- Aj¶
COO of the SPD precision
A, as insolve().- Ax¶
COO of the SPD precision
A, as insolve().- mean¶
[n]or[n_paths, n]float64 — means ofx.- chosen¶
int or
[n_paths]int — the index whose maximality is scored.- competitors=
None¶ Noneor[n_paths, K]int — per path, the indices to draw first, most competitive first;-1marks an unused slot. Must not containchosenor repeat an index.- n_draws=
128¶ GHK draws per path (static); a power of two suits
"sobol".- seed=
0¶ integer seed (static).
- keys=
None¶ Noneor[n_paths]int — per-path keys for the draws (defaultarange(n_paths)). Give each decision-maker a stable key to keep their draws fixed across calls and batchings.- draws=
'sobol'¶ "sobol"(default) or"iid", independent draws throughout (static).
- Returns:¶
[n_paths]float64 log-probabilities, or a scalar for 1Dmean.