Sam Babichenko

Reading notes / Decision meshes

Adaptive mesh geometries: triangles, rectangles, and 3-D boxes

Surface and domain
xix_iscaled covariates of pool ii in [0,1]2[0,1]^2 (loan age and coupon) or [0,1]3[0,1]^3 (adding log average balance)
ηi\eta_imarginal-mean logit of pool ii, ηi=offseti+f(xi)+agi\eta_i = \mathrm{offset}_i + f(x_i) + a_{g_i}
f(xi)f(x_i)piecewise-linear (triangular) or multilinear (rectangular) mesh surface evaluated at xix_i
agia_{g_i}unpenalized population-level offset for pool ii's group, with aref=0a_{\mathrm{ref}} = 0
Vertices and surpluses
ccindex of a mesh vertex (the code writes vv)
p0,p1p_0, p_1the two birth parents of vertex cc: endpoints of the segment it bisected
hch_cheight (in logits) of vertex cc; vector hh collects free vertex heights
δc\delta_chierarchical surplus hc−12(hp0+hp1)h_c - \tfrac{1}{2}(h_{p_0} + h_{p_1}); vector δ\delta collects free surpluses
ddprior depth of a vertex: bisected segment level in rectangles (d=1d=1 for a unit segment) or generation max⁡(dp0,dp1)+1\max(d_{p_0},d_{p_1})+1 in triangles
τd2\tau_d^2prior variance of surpluses at depth dd; precision λd=1/τd2\lambda_d = 1/\tau_d^2
Nodal-coordinate solve
XXhierarchical surplus design matrix (columns follow descendants at weight 1/21/2 per generation)
BBnodal design matrix (free-vertex columns stop at free descendants; row width at most 7 in 2-D)
RRnodal-to-surplus linear map satisfying δ=Rh\delta = Rh, built from birth parents and nodal closures
PPquadratic prior precision matrix; P=R⊤diag⁡(λ)RP = R^\top \operatorname{diag}(\lambda) R in nodal coordinates
JJpenalized working information B⊤diag⁡(j)B+PB^\top \operatorname{diag}(j) B + P in nodal coordinates
rc⊤r_c^\toprow cc of RR, mapping free heights hh back to surplus δc=rc⊤h\delta_c = r_c^\top h

Context. Mortgage loan termination rates vary sharply with loan age and coupon. Early months show a seasoning ramp, coupons near market rates form a steep refinancing elbow, and older cohorts exhibit burnout. Decision meshes fit that surface on the logit scale, refining cells only where a false-discovery gate finds statistical support. The interactive explorer and its detailed walkthrough run both WebAssembly engines on synthetic coin flips. This note examines the geometry layer underneath: how triangular newest-vertex bisection compares with anisotropic dyadic rectangles, how birth-parent recursion and a nodal change of variables speed up the rectangular solver, and what genuinely changes in three dimensions.

Choosing between conforming triangles and non-conforming rectangles is a statistical decision, not purely a data-structure choice. Newest-vertex bisection keeps every triangle conforming through a completion cascade at split time. That conformity forces diagonal isotropic cuts and lets later splits erode a coarse vertex's nodal support. Anisotropic dyadic rectangles drop conformity at split time and rely on birth-parent recursion to hold continuity across hanging edges. That change eliminates triangular obsolescence, the two-node hierarchy, and retirement passes while matching held-out accuracy in half the time and extending cleanly to 3-D boxes.

Setting. Scale each pool's covariates scaled covariates of pool ii in [0,1]2[0,1]^2 (loan age and coupon) or [0,1]3[0,1]^3 (adding log average balance) to [0,1]2[0,1]^2 (or [0,1]3[0,1]^3 in three dimensions). The mesh models pool ii's marginal-mean logit of loan-count termination probability asηi=offseti+f(xi)+agi.\eta_i = \mathrm{offset}_i + f(x_i) + a_{g_i}.Here offseti\mathrm{offset}_i is a fixed training baseline or external logit offset, and unpenalized population-level indicator offset for pool ii's group, fitted jointly with the surface, with reference group aref=0a_{\mathrm{ref}} = 0 is an unpenalized population-level shift fitted jointly with the surface (aref=0a_{\mathrm{ref}}=0). The mesh surface piecewise-linear surface on triangles or multilinear (bilinear/trilinear) surface on rectangles and boxes is stored at its vertices. Every non-root vertex a vertex of the mesh, created by bisecting a segment with endpoints p0p_0 and p1p_1 sits at the midpoint of an edge with endpoints the two birth parents of vertex cc, always the endpoints of the segment it bisected, and writes its logit height the surface height in logits at vertex cc as parent average plus surplus:hc=hp0+hp12+δc.h_c = \frac{h_{p_0} + h_{p_1}}{2} + \delta_c.A welded vertex holds δc=0\delta_c = 0 at zero statistical cost. A free vertex carries a Gaussian prior δc∼N(0,τd2)\delta_c \sim \mathcal{N}(0, \tau_d^2) indexed by its depth the prior depth of vertex cc: the bisected segment's refinement level in rectangles (d=1d=1 for a unit segment), or generation max⁡(dp0,dp1)+1\max(d_{p_0},d_{p_1})+1 in triangles, shrinking fine departures toward linear parent interpolation.

Step 1

Triangular newest-vertex bisection and the complications it forces. In the triangular engine, every face is a right isosceles triangle cut only at the midpoint of its hypotenuse (newest-vertex bisection). Asking for a midpoint on a short leg triggers a recursive splitting neighboring faces along their hypotenuses first so every active vertex remains a corner of every incident triangle, leaving no hanging nodes cascade across neighboring faces until the requested edge becomes a hypotenuse. Every vertex born from that cascade starts welded (δc=0\delta_c = 0) and waits on the candidate frontier. The mesh stays strictly conforming and triangles stay right isosceles.

That geometric guarantee imposes four burdens on the statistical layer. First, diagonal isotropic cuts cannot refine a steep coupon elbow without also cutting along loan age, adding extra faces; the triangular code also carries a 5.0 aspect-ratio guard that rectangles drop. Second, once free midpoints surround a coarse vertex in the triangular nodal basis, that vertex plays two incompatible roles: the linear interpolation anchor for its children and a shrinking hat on its remaining one-ring star. Splitting it into a moving a surrounded vertex's coarse role into a virtual coarse node with its original parent stencil, while re-attaching the geometric vertex below it as a welded fine child at the child's scale (a virtual coarse node keeping the coarse stencil, plus a fine geometric node attached below it as a welded child) improved 2020 single-issuer held-out deviance by −0.42%-0.42\% (SE 0.08%0.08\%). Third, later splits can empty a free coefficient's training support, forcing a deepest-first retirement pass that checks hierarchical column norms and verifies prediction invariance to 10−910^{-9} logits. Fourth, rows in the hierarchical surplus design reach width 16 on the pooled benchmark.

Step 2

Anisotropic dyadic rectangles and birth-parent continuity. The rectangular engine places cells on a 2242^{24}-per-axis integer dyadic grid and cuts a leaf cell at the midline of one chosen axis (xx, yy, or zz). Every axis of every leaf cell is offered to the gate as a separate candidate (through midpoints of its perpendicular edges), so axis choice becomes a statistical decision with no aspect-ratio cap. Every new chord endpoint has canonical birth parents on the integer grid: a point on a vertical cell boundary at odd integer grid coordinate y=(2m+1)2ky = (2m+1)2^k can only arise from bisecting [y−2k,y+2k][y - 2^k, y + 2^k].

Dropping conformity introduces a second weld species alongside regular statistical welds. A a vertex sitting in the interior of a coarser neighbor's edge; held at δc=0\delta_c = 0 so the fine side matches the coarse edge's linear trace sits inside an unsplit neighbor's edge. Because a bilinear (or trilinear) function restricted to an edge is linear, evaluating vertex heights in birth order via hc=12(hp0+hp1)h_c = \frac{1}{2}(h_{p_0} + h_{p_1}) forces the fine side to match the coarse edge's linear trace identically. Continuity holds across every shared edge from birth-parent recursion alone, with no stored master-slave constraint chains and no 2:1 balance requirement. Promoting a hanging vertex triggers an inert release split of its coarse neighbor first, paying geometric splits only for vertices the gate actually admits.

Step 3

The inert-split lemma eliminates retirement and two-node splits. A dyadic bisection whose newly created vertices all hold δc=0\delta_c = 0 reproduces the parent cell's multilinear surface identically. On each bisected edge, the parent's linear trace at the midpoint equals the average of its endpoints, so every child sub-rectangle inherits corner values matching the parent bilinear function. Because a bilinear function on a rectangle is uniquely determined by its four corners, the refined surface agrees with the unsplit surface pointwise.

In the hierarchical surplus basis, a free coefficient's column propagates into its descendants at weight 1/21/2 per generation and stays fixed after birth. A release split plus promoting one hanging vertex therefore adds exactly one new design column while leaving every existing coefficient's column untouched. Later refinement cannot strip away an existing coefficient's support, so dormancy, retirement passes, and the two-node hierarchy vanish. A rectangular counterpart of the fine-node split was built and tested on the 2020 year battery. It gave −0.07%-0.07\% (SE 0.04%0.04\%) single-issuer and +0.8%+0.8\% pooled with only two admissions on the benchmark, confirming that the two-node problem belonged to the triangular nodal basis.

Step 4

Fitting in nodal coordinates with a transformed penalty. Fixed hierarchical columns carry one computational cost: a pool can sit under many overlapping hats across levels, pushing surplus design rows to width 28 on the 2020 benchmark. In the the basis indexed by free vertex heights hh, where each free vertex's column propagates downward through welded descendants and stops at free descendants BB, each free vertex's influence propagates downward through welded descendants and stops at free descendants. Equivalently, each welded vertex's height expands upward through welded ancestors until hitting free ancestors (its nodal closure). Design row width drops from 28 to at most 7 in two dimensions.

A linear change of variables preserves the exact hierarchical prior while using the sparse nodal design BB. Order free vertices with roots first and children by ascending depth. Build the nodal-to-surplus matrix the p×pp\times p matrix mapping free vertex heights hh to hierarchical surpluses δ=Rh\delta = Rh row by row: each root row has 11 on its diagonal (δc=hc\delta_c = \htmlData{gr=g6}{h_c}), and each free child row places +1+1 at column cc while subtracting 12w\tfrac{1}{2}w at column kk for every free ancestor kk with weight ww in the nodal closures of p0p_0 and p1p_1:δ=Rh,P=R⊤diag⁡(λ)R.\delta = Rh, \qquad P = R^\top \operatorname{diag}(\lambda) R.Here λc=1/τd2\lambda_c = 1/\htmlData{gr=gn4}{\tau_d^2} for free children at depth dd, and λc=1\lambda_c = 1 (SD 1 logit) for the rectangular roots (four in 2-D, eight in 3-D). With p≈60p \approx 60 to 150150 free vertices, forming the dense p×pp\times p penalty PP costs almost nothing. Gram and candidate-scoring products scale with row width squared and fall from about 1.2 s to 0.1 s on a single-threaded pooled fit, with bit-identical admissions and held-out deviances across all 72 battery fits. For EM depth-variance updates, each surplus and posterior variance convert back via δ^c=rc⊤h^\hat\delta_c = r_c^\top \hat h and Vcc=rc⊤J−1rcV_{cc} = r_c^\top J^{-1} r_c, where rc⊤r_c^\top is row cc of RR and J=B⊤diag⁡(j)B+PJ = B^\top \operatorname{diag}(j) B + P.

Step 5

Two genuine obstacles in three dimensions. Extending dyadic bisection to 3-D boxes (loan age, coupon, and log average balance on an 8×8×48\times 8\times 4 starting grid with 27 free roots and depth-1 vertices) keeps two-parent edge midpoints and inert splits intact. Two properties of 2-D do break.

First, a vertex born on a fine box can land strictly inside a coarser neighbor's 2-D face (a a vertex inside a coarse leaf's 2-D face in 3-D, where two perpendicular bisection axes cross and its birth parents do not sit on an edge of the coarse box). Inside a 2-D face, two perpendicular birth axes are possible and the vertex's birth parents do not lie on an edge of the coarse box; once a neighbor splits or frees a vertex along the perpendicular axis, the birth-parent average diverges from the coarse face's trace. The closure rule inertly splits any coarse leaf along a non-birth interior axis so every hanging vertex sits on a leaf edge along its own birth axis, reducing 3-D face continuity back to the 1-D edge argument.

Second, that closure split can pass through an existing vertex along a different axis than its original birth axis. Under when a 3-D closure split passes through an existing vertex along a non-birth axis, the vertex keeps its original birth parents so existing columns stay inert, the vertex keeps its original birth parents so existing coefficients stay inert. That choice means a candidate's post-move column differs from the column read before the move in roughly half of random 3-D moves. The 3-D gate therefore scores each candidate by executing the exact dry-run move on a per-thread mesh copy, reading the realized column, and rolling back via an undo journal (with dependency-tracked column caching in the Python port).

Empirical comparison. On the 2020 Ginnie Mae single-issuer year battery (36 fits across 12 months and 3 seeds), the 2-D rectangular engine matches and slightly edges the triangular engine at −0.24%-0.24\% held-out deviance (SE 0.14%0.14\%, better in 23 of 36 fits). It uses roughly half the cells and fewer free coefficients (February 2020 seed 1: 128 cells and 59 free versus 303 faces and 84 free for triangles) in half the runtime and 60% of peak memory. Adding log average balance in 3-D across 2020 Ginnie and Fannie panels beats the 2-D surface with the same population levels in 69 of 80 cohort folds (median −2.2%-2.2\% deviance), 42 of 48 random splits (median −2.0%-2.0\%), and 13 of 16 next-month tests (median −1.3%-1.3\%).

Terms

Two weld species
Statistical welds are regular vertices at δc=0\delta_c=0; hanging vertices sit on a coarse edge and enforce continuity via hc=12(hp0+hp1)h_c=\tfrac{1}{2}(h_{p_0}+h_{p_1}) until a release split.
Inert-split lemma
A dyadic cut with all new vertices at δc=0\delta_c=0 leaves a multilinear surface identical pointwise, so release + promote adds one column without moving any existing column.
Nodal-coordinate solve
Fit free heights hh with sparse nodal design BB (width ≤7\le 7 in 2-D) and dense penalty P=R⊤diag⁡(λ)RP = R^\top \operatorname{diag}(\lambda) R where δ=Rh\delta = Rh; ~10x faster Gram/scoring, bit-identical fit.
3-D face-hanging closure
Inertly split any coarse 3-D leaf containing a vertex inside its face so every hanging vertex sits on a leaf edge along its own birth axis.
3-D relaxed rebirth
Closure splits along a non-birth axis preserve existing parents, altering pre-move candidate columns in ~50% of moves; exact dry-run scoring with an undo journal restores parity.

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.

  • 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.

  • A bias-free denoiser computes f(y)=∑kλk(y)⟨y,ek(y)⟩ek(y)f(y)=\sum_k\lambda_k(y)\langle y,e_k(y)\rangle e_k(y), shrinkage in a basis adapted to the noisy image that keeps the coefficients above the noise and suppresses the rest.

  • In least squares with pp features, ridge with its penalty tuned at each pp makes the test error fall monotonically as pp grows (Nakkiran et al.), and the lecture takes from it the rule that an explicit regularizer should be tuned until scaling is monotone again.

Threads