Sam Babichenko

Reading notes / Decision meshes

Mean-neutral pool effects and the centered-mode estimator

Overdispersed binomial model
ni,kin_i, k_iloans at risk and observed loan terminations in pool ii; random count KiK_i
ηi,pi\eta_i, p_imarginal-mean logit ηi\eta_i and marginal termination probability pi=logistic⁡(ηi)p_i = \operatorname{logistic}(\eta_i)
Ui,vU_i, vGaussian pool random effect Ui∼N(0,v)U_i \sim \mathcal{N}(0, v) with common pool variance vv
AiA_imean-neutral logit location A(ηi,v)A(\eta_i, v) solving EU[logistic⁡(Ai+Ui)]=logistic⁡(ηi)\mathbb{E}_U[\operatorname{logistic}(A_i + U_i)] = \operatorname{logistic}(\eta_i)
Ai′A'_iderivative ∂Ai/∂ηi=pi(1−pi)/EU[πi(1−πi)]\partial A_i / \partial \eta_i = p_i(1-p_i) / \mathbb{E}_U[\pi_i(1-\pi_i)], where πi=logistic⁡(Ai+Ui)\pi_i = \operatorname{logistic}(A_i + U_i)
Centered-mode estimating equation
u^i\hat u_iconditional MAP mode of UiU_i, solving u^i=v[ki−nilogistic⁡(Ai+u^i)]\hat u_i = v[k_i - n_i \operatorname{logistic}(A_i + \hat u_i)]
ri,mir_i, m_imode residual ri=ki−nilogistic⁡(Ai+u^i)r_i = k_i - n_i \operatorname{logistic}(A_i + \hat u_i) and its repeated-sample mean mi=EU,K[ri(Ki)]m_i = \mathbb{E}_{U,K}[r_i(K_i)]
r~i,si\tilde r_i, s_icentered residual r~i=ri−mi\tilde r_i = r_i - m_i (the code writes ziz_i) and weighted score si=Ai′r~is_i = A'_i \tilde r_i
ji,Vij_i, V_iexpected negative score derivative ji=−E[∂si/∂ηi]j_i = -\mathbb{E}[\partial s_i / \partial \eta_i] (at fixed data-generating ηi\eta_i) and score variance Vi=Var⁡(si)V_i = \operatorname{Var}(s_i)
X,θ,PX, \theta, Pdesign matrix, surface plus level coefficients, and quadratic prior precision matrix
Quadrature and dispersion equation
QQKrawtchouk count quadrature order for ni>128n_i \gt 128 (6 for surface moments, 8 for dispersion moments)
dj,ejd_j, e_jdiagonal and off-diagonal entries of the Q×QQ\times Q symmetric tridiagonal Krawtchouk Jacobi matrix
σz,i2,qi\sigma_{z,i}^2, q_iunfitted second moment E[r~i2]\mathbb{E}[\tilde r_i^2] and first-order refit-corrected expectation qiq_i
ℓi,Si\ell_i, S_isurface leverage xi⊤J−1xix_i^\top J^{-1} x_i and sandwich variance xi⊤J−1ΩJ−1xix_i^\top J^{-1} \Omega J^{-1} x_i
bη,i,wib_{\eta,i}, w_ishrinkage bias xi⊤J−1Pθx_i^\top J^{-1} P \theta and variance-equation weight (∂σz,i2/∂v)/Var⁡(r~i2)(\partial \sigma_{z,i}^2 / \partial v)/\operatorname{Var}(\tilde r_i^2)

Context. Agency mortgage pools share two traits that break standard logistic regression. First, pools at the same loan age and coupon still differ persistently in unobserved borrower and servicer mix, producing strong binomial overdispersion. Second, pool sizes span four orders of magnitude, from 25 loans up to roughly 10510^5 loans in giant multi-issuer pools. Plain binomial maximum likelihood lets a handful of huge pools dominate both fitting and evaluation, while naive random-effects approximations attenuate the surface or bias average predicted rates upward.

Decision meshes resolve both problems with two linked devices. A mean-neutral location shift A(ηi,v)A(\eta_i, v) keeps average termination rates separate from pool dispersion, and a centered conditional-mode estimating equation removes penalized quasi-likelihood (PQL) bias while capping every pool's effective information near 1/v1/v. The interactive explorer and detailed walkthrough show overdispersed coin flips visually. This note derives the exact equations, the Krawtchouk quadrature rule for large nin_i, and the refit-corrected dispersion equation for vv.

Setting. Pool ii has number of loans at risk in pool ii during the observation month loans at risk and observed number of loan terminations in pool ii (random count KiK_i) loan terminations. The model targets loan-count termination probability (distinct from balance-weighted SMM) through a Gaussian pool random effect unobserved pool-level logit shock Ui∼N(0,v)U_i \sim \mathcal{N}(0, v) capturing persistent overdispersion with common variance vv:Ki∣Ui∼Binomial⁡(ni, πi),πi=logistic⁡(Ai+Ui),Ui∼N(0,v).\begin{aligned}K_i \mid U_i &\sim \operatorname{Binomial}(n_i,\, \pi_i),\\\pi_i &= \operatorname{logistic}(A_i + U_i),\\U_i &\sim \mathcal{N}(0, v).\end{aligned}Here logistic⁡(u)=(1+e−u)−1\operatorname{logistic}(u) = (1 + e^{-u})^{-1}. The location AiA_i=A(ηi,v){}=A(\eta_i, v) is defined implicitly from the surface's marginal-mean logit marginal-mean logit ηi=offseti+f(xi)+agi\eta_i = \mathrm{offset}_i + f(x_i) + a_{g_i}, giving predicted probability pi=logistic⁡(ηi)p_i = \operatorname{logistic}(\eta_i) for a new pool (with pi=logistic⁡(ηi)p_i = \operatorname{logistic}(\eta_i)) byEU ⁣[logistic⁡(Ai+Ui)]=logistic⁡(ηi).\mathbb{E}_{U}\!\big[\operatorname{logistic}(A_i + U_i)\big] = \operatorname{logistic}(\eta_i).

Step 1

Why mean-neutral centering removes Jensen's-inequality bias. At monthly prepayment rates around p∈[0.01,0.03]p \in [0.01, 0.03], the logistic map sits deep in its convex tail (logistic⁡′′(u)=p(1−p)(1−2p)>0\operatorname{logistic}''(u) = p(1-p)(1-2p) \gt 0). Adding a zero-mean Gaussian UiU_i directly to ηi\eta_i inflates the average termination rate by roughly 12vp\tfrac{1}{2} v p via Jensen's inequality. On the logit scale, staying mean-neutral shifts the conditional intercept down to Ai≈ηi−12vA_i \approx \eta_i - \tfrac{1}{2} v. Without this shift, changing the dispersion estimate vv drags the surface level up or down and mixes dispersion with mean calibration. With AiA_i solved numerically by Gauss-Hermite quadrature, a new pool's marginal prediction is simply pi=logistic⁡(ηi)p_i = \operatorname{logistic}(\eta_i). Implicit differentiation of the defining identity yields the location sensitivity directly:Ai′=∂Ai∂ηi=pi(1−pi)EU[πi(1−πi)],A'_i = \frac{\partial A_i}{\partial \eta_i} = \frac{p_i(1-p_i)}{\mathbb{E}_U[\pi_i(1-\pi_i)]},where πi=logistic⁡(Ai+Ui)\pi_i = \operatorname{logistic}(A_i + U_i).

Step 2

Centered conditional-mode estimating equation and the 1/v1/v cap. Given trial ηi\eta_i and vv, the engine finds each pool's conditional MAP mode maximizer of the conditional log-posterior ki(Ai+u)−nilog⁡(1+eAi+u)−u2/(2v)k_i(A_i+u) - n_i\log(1+e^{A_i+u}) - u^2/(2v) for pool ii by solving the first-order conditionu^i=v[ki−nilogistic⁡(Ai+u^i)].\hat u_i = v\big[k_i - n_i \operatorname{logistic}(A_i + \hat u_i)\big].Define the mode residual rir_i=ki−nilogistic⁡(Ai+u^i){}= k_i - n_i \operatorname{logistic}(A_i + \hat u_i). It equals u^i/v\hat u_i / v for v>0v \gt 0 and stays well-defined at v=0v = 0. In classical PQL, plugging rir_i directly into a score equation biases the fitted surface toward zero because posterior shrinkage and binomial discreteness give rir_i a nonzero repeated-sample mean.

The centered-mode estimator removes that PQL attenuation by subtracting the full repeated-sample expectation mim_i=EU,K[ri(Ki)]{}= \mathbb{E}_{U,K}[r_i(K_i)]. This forms the centered residual r~i=ri−mi\tilde r_i = r_i - m_i and weighted score si=Ai′r~is_i = A'_i \tilde r_i. With design XX, coefficients θ\theta, and prior precision PP, the surface solves the penalized estimating equationX⊤s−Pθ=0X^\top s - P\theta = 0by damped Newton steps on its exact derivative. Because E[si]=0\mathbb{E}[s_i] = 0 at the true surface for every (ni,ηi,v)(n_i, \eta_i, v), the estimating equation stays unbiased in finite samples without maximizing an intractable marginal likelihood.

This mode construction automatically caps giant-pool leverage. As ni→∞n_i \to \infty, the binomial likelihood overwhelms the prior in the mode equation, pinning Ai+u^i→logit⁡(ki/ni)A_i + \hat u_i \to \operatorname{logit}(k_i/n_i) and ri=u^i/v→(logit⁡(ki/ni)−Ai)/vr_i = \hat u_i / v \to (\operatorname{logit}(k_i/n_i) - A_i)/v. The pool's residual approaches its noisy logit error divided by vv, so its effective Fisher information expected negative score derivative −E[∂si/∂ηi]-\mathbb{E}[\partial s_i / \partial \eta_i] holding the data-generating ηi\eta_i fixed, measuring how strongly pool ii informs the surface saturates near 1/v1/v instead of growing linearly as nipi(1−pi)n_i p_i(1-p_i). A 100,000-loan pool cannot drown out neighboring smaller pools. On February 2020 data across pool sizes from 25 to 10510^5 loans, the ratio of expected information jij_i to score variance repeated-sample variance Var⁡(si)=(Ai′)2E[r~i2]\operatorname{Var}(s_i) = (A'_i)^2 \mathbb{E}[\tilde r_i^2] of pool ii's centered score stays in [0.990,1.005][0.990, 1.005], within 1% of the Bartlett identity of the exact marginal score.

Step 3

Gauss-Hermite and Krawtchouk quadrature for fast exact moments. Computing mim_i, Var⁡(r~i)\operatorname{Var}(\tilde r_i), jij_i, and variance sensitivities requires integrating functions of u^i(Ki)\hat u_i(K_i) over both UiU_i and Ki∣UiK_i \mid U_i. The outer integral over Ui∼N(0,v)U_i \sim \mathcal{N}(0, v) uses Gauss-Hermite quadrature whose order adapts to vv (base 24 nodes for surface moments, base 32 for dispersion moments). For the inner binomial expectation over Ki∈{0,…,ni}K_i \in \{0, \dots, n_i\}, pools with ni≤128n_i \le 128 are enumerated directly, pruning tail probabilities below 10−1810^{-18} of the row's total weight.

Enumerating 10510^5 counts per Gauss-Hermite node for giant pools would be prohibitively slow. For ni>128n_i \gt 128, the engine replaces enumeration with QQ-point Gaussian quadrature against the discrete Binomial⁡(ni,π)\operatorname{Binomial}(n_i, \pi) measure, whose orthogonal polynomials are the discrete polynomials orthogonal with respect to the Binomial⁡(n,π)\operatorname{Binomial}(n, \pi) probability mass function; their three-term recurrence defines a Q×QQ\times Q symmetric tridiagonal Jacobi matrix. Surface moments use Q=6Q = 6 (exact for polynomials in KiK_i up to degree 11), and dispersion moments use Q=8Q = 8 (exact up to degree 15). By Golub-Welsch, the quadrature nodes and weights are the eigenvalues and squared first-row eigenvector entries of the Q×QQ\times Q symmetric tridiagonal Jacobi matrix (j=0,…,Q−1j = 0, \dots, Q-1 on the diagonal, j=0,…,Q−2j = 0, \dots, Q-2 off-diagonal):dj=niπ+(1−2π)j,ej=π(1−π)(j+1)(ni−j).\begin{aligned}d_j &= n_i \pi + (1 - 2\pi) j,\\e_j &= \sqrt{\pi(1-\pi)(j+1)(n_i - j)}.\end{aligned}The C++ core solves these nodes in 8-wide SIMD via Aberth-Ehrlich root finding and Christoffel-Darboux weights, falling back to implicit QL whenever a lane is extreme or fails to converge. During intermediate Newton steps, rows whose ηi\eta_i moved less than 0.010.01 logit reuse linearized cached moments; the final fit certifies every row on exact moments.

Step 4

Refit-corrected dispersion equation for vv. The same quadrature supplies each pool's unfitted second moment σz,i2=E[r~i2]\sigma_{z,i}^2 = \mathbb{E}[\tilde r_i^2], the variance of its squared residual Var⁡(r~i2)\operatorname{Var}(\tilde r_i^2), and its variance sensitivity ∂σz,i2/∂v\partial \sigma_{z,i}^2 / \partial v. Comparing observed r~i2\tilde r_i^2 directly against σz,i2\sigma_{z,i}^2 would underestimate vv because fitting θ\theta pulls η^i\hat\eta_i toward the data, while prior shrinkage leaves a small squared bias in r~i\tilde r_i.

Expanding r~i(η^i)\tilde r_i(\hat\eta_i) to first order around the true surface gives the refit-corrected expected square first-order refit-corrected expectation of r~i2\tilde r_i^2 accounting for leverage, joint-fit sandwich covariance, and squared shrinkage bias. Define penalized information J=P+X⊤diag⁡(j)XJ = P + X^\top \operatorname{diag}(j) X and score covariance Ω=X⊤diag⁡((Ai′)2σz,i2)X\Omega = X^\top \operatorname{diag}((A'_i)^2 \sigma_{z,i}^2) X. With derivative di=ji/Ai′d_i = j_i / A'_i, leverage ℓi=xi⊤J−1xi\ell_i = x_i^\top J^{-1} x_i, sandwich variance Si=xi⊤J−1ΩJ−1xiS_i = x_i^\top J^{-1} \Omega J^{-1} x_i, and shrinkage bias bη,i=xi⊤J−1Pθb_{\eta,i} = x_i^\top J^{-1} P \theta,qi=σz,i2−2jiℓiσz,i2+di2Si+(dibη,i)2,\begin{aligned}q_i &= \sigma_{z,i}^2 - 2 j_i \ell_i \sigma_{z,i}^2\\&\quad + d_i^2 S_i + (d_i b_{\eta,i})^2,\end{aligned}clamped below at zero. The pool variance solves the weighted dispersion equation∑iwi(r~i2−qi)=0,wi=∂σz,i2/∂vVar⁡(r~i2).\sum_i w_i (\tilde r_i^2 - q_i) = 0, \qquad w_i = \frac{\partial \sigma_{z,i}^2 / \partial v}{\operatorname{Var}(\tilde r_i^2)}.Weighting by sensitivity over variance downweights tiny pools that carry almost no information about vv. Intermediate mesh-refinement rounds take one bounded variance step with a 1%1\% hold. The final fit runs an alternating secant search certified on 8-node Krawtchouk and base-32 Gauss-Hermite moments, resolving to v=0v = 0 if the dispersion score is already nonpositive at v=0v = 0.

Terms

Mean-neutral offset
Solve EU[logistic⁡(Ai+Ui)]=logistic⁡(ηi)\mathbb{E}_U[\operatorname{logistic}(A_i + U_i)] = \operatorname{logistic}(\eta_i) (Ai≈ηi−12vA_i \approx \eta_i - \tfrac{1}{2}v at low rates) so vv does not bias average predicted rates.
Centered mode equation
u^i=v[ki−nilogistic⁡(Ai+u^i)]\hat u_i = v[k_i - n_i\operatorname{logistic}(A_i+\hat u_i)], r~i=ri−E[ri]\tilde r_i = r_i - \mathbb{E}[r_i], si=Ai′r~is_i = A'_i \tilde r_i, solve X⊤s−Pθ=0X^\top s - P\theta = 0; zero PQL bias.
Giant-pool leverage cap
As ni→∞n_i\to\infty, ri=u^i/vr_i = \hat u_i/v so effective information jij_i flattens near 1/v1/v instead of growing as nipi(1−pi)n_i p_i(1-p_i); ji/Vi∈[0.990,1.005]j_i/V_i \in [0.990, 1.005].
Krawtchouk quadrature
Exact enumeration for ni≤128n_i\le 128; for ni>128n_i\gt 128, QQ-point binomial Gaussian quadrature (Q=6Q=6 surface, Q=8Q=8 dispersion) from the tridiagonal Jacobi matrix (dj,ej)(d_j, e_j).
Refit-corrected variance
∑iwi(r~i2−qi)=0\sum_i w_i(\tilde r_i^2 - q_i)=0 with qi=σz,i2−2jiℓiσz,i2+di2Si+(dibη,i)2q_i = \sigma_{z,i}^2 - 2 j_i \ell_i \sigma_{z,i}^2 + d_i^2 S_i + (d_i b_{\eta,i})^2 and wi=(∂σz,i2/∂v)/Var⁡(r~i2)w_i = (\partial\sigma_{z,i}^2/\partial v)/\operatorname{Var}(\tilde r_i^2).

Sources

Connected notes

  • Because ∥X∥2\|X\|^2 exceeds ∥θ∥2\|\theta\|^2 by about dd on average, the best factor is about 1−d/∥X∥21-d/\|X\|^2, and the James-Stein version beats the raw observation at every θ\theta once d≥3d\ge3.

  • Measuring a weight change by how far it moves a unit-RMS input gives the update −ηdout/din UV⊤-\eta\sqrt{d_{out}/d_{in}}\,UV^\top, which, when din≤doutd_{in}\le d_{out} and the gradient has full rank, moves the output of every unit-RMS input by exactly η\eta whatever the width, which is the μ\muP property, here derived from a choice of norm.

  • A trained linear-attention layer keeps the fraction Nλi/((N+1)λi+trΣ)N\lambda_i/((N+1)\lambda_i+\mathrm{tr}\Sigma) of the signal in eigendirection ii, a ridge-like shrinkage fixed at training time that does not weaken as the prompt grows; and because the layer applies a fixed matrix where least squares would invert the prompt's sample covariance, its error keeps a 1/M1/M term even on noiseless prompts.

  • The reproduction draws the reward head's weights with standard deviation 1/dmodel+11/\sqrt{d_{\rm model}+1}, shifts the reward so reference summaries score 0 on average, and whitens advantages to mean 0 and variance 1 in each batch, so the signal reaching the policy has a fixed size.

Threads