The K-COS MethodReading edition

Numerical evidence and applications

Reading tools
Reading libraryFind statementsInspect Lean
Switch work

Saved reading

Read side by side

Start reading

Resources & source

Original TeX with line links · Download TeX

The wording and mathematics follow the retained manuscript. This reading format does not add a proof review or extend Lean coverage.

Skip contents and start reading

11 Numerical evidence and applications

Exact-law controls test values against independent formulas. Heterogeneous spectra test inversion across irregular coefficients. Simulated kernels test the operator pipeline. Timing measurements characterize particular implementations. These are distinct forms of evidence. The source package records the inputs and environments behind the reported experiments. The release regression and containment checks are reported in Appendix C.

11.1 Deep-tail controls

A directed enclosure includes rounding as well as analytic remainders. An analytic ledger evaluated in ordinary floating point does not. The labels in this chapter identify which conclusion a result supports. The retained timing measurements are not presented as a new hardware comparison.

The method is designed for a regime in which direct survival probabilities can underflow long before the mathematical probability becomes numerically unresolvable. The engine therefore treats \(\log p\) as the primary numerical quantity and evaluates its error bounds on that logarithmic scale.

The validation ladder spans seven qualitatively different settings:

validation regimedeepest \(\log_{10}p\)observed errorcertificatespectral size
directed-rounding \(0.02\chi^2_{80}\) control\(-5000\)enclosure width \(3.34\times10^{-11}\) decadesmultiplicative ratio \(\le 1+7.70\times10^{-11}\)80 df
large-scale positive spectrum\(-922.031162\)below stored reference resolution\(5.71\times10^{-9}\)rank 1997
strong-dependence kernel\(-457.973916\)below stored reference resolution\(5.20\times10^{-9}\)rank 996
heterogeneous inversion benchmark near \(10^{-16}\)\(-16\)\(2.88\)–\(6.52\times10^{-15}\) decadesindependent integral convergedranks 80–120
signed finite-endpoint exact control\(-200\)\(\le 2.84\times10^{-14}\) decades\(7.23\times10^{-13}\)rank 80
signed mixed multiscale\(-81.891937\)\(1.42\times10^{-12}\) decades vs full grid\(5.78\times10^{-9}\)rank 340
noncentral exact controls\(-40\)\(\le 9.26\times10^{-15}\) decadespassingup to 50 df

The analytic scaled-chi-square ladder also includes

\[ \log_{10}p=-100,-300,-1000,-5000, \]

with respective reported absolute log-probability discrepancies

\[ 2.84\times10^{-14},\quad <10^{-15},\quad 3.41\times10^{-13},\quad <10^{-15} \]

in the stored benchmark output. The corresponding analytic relative certificates remain finite throughout, reaching only

\[ 3.85\times10^{-11} \]

at \(10^{-5000}\).

A large-scale run with \(n=2000\), \(m=50{,}000\), 49,951 retained features, and quadratic-form rank 1997 produced

\[ \boxed{\log_{10}p=-922.0311624669905} \]

using 79 spectral packets and \(N=128\). Its independently evaluated full-spectrum tilted reference agreed within the stored reporting precision, while the reported relative certificate was

\[ 5.71\times10^{-9}. \]

The corrected strong-dependence case study independently reached

\[ \boxed{\log_{10}p=-457.9739160722001} \]

with a finite \(5.20\times10^{-9}\) certificate. The signed finite-endpoint control passed its analytic ledger through \(10^{-200}\), while a rank-340 mixed-sign multiscale spectrum passed its analytic ledger to

\[ \boxed{\log_{10}p=-81.89193686056221}. \]

Finally, the noncentral engine matched exact noncentral-chi-square controls from \(10^{-4}\) through \(10^{-40}\), with maximum observed discrepancy

\[ 9.26\times10^{-15} \]

decades.

Retained log-probability discrepancies across positive, signed, mixed-sign, and noncentral control families. The symmetric-log vertical scale preserves exact stored zeros without a positive display floor. These are pointwise comparisons with the stated references, not uniform error bounds.
Figure 11.1. Retained log-probability discrepancies across positive, signed, mixed-sign, and noncentral control families. The symmetric-log vertical scale preserves exact stored zeros without a positive display floor. These are pointwise comparisons with the stated references, not uniform error bounds.

View full-size figure (new tab)

11.1.1 Independent characteristic-function inversion near \(10^{-16}\)

Closed-form controls are important, but they can hide numerical difficulties that appear only for heterogeneous spectra. An independent inversion test was therefore run on four generalized chi-square laws near

\[ P(Q\ge q)\approx10^{-16}. \]

The reference evaluates the original characteristic function directly through the central Imhof inversion identity

\[ P(Q\ge q) = \frac12 + \frac1\pi \int_0^\infty \frac{\sin\Theta(u)}{u\,R(u)}\,du, \]

where, for distinct positive coefficients \(\lambda_j\) with multiplicities \(h_j\),

\[ \Theta(u) = \frac12\sum_j h_j\arctan(\lambda_j u) - \frac12qu, \qquad R(u) = \prod_j \left(1+\lambda_j^2u^2\right)^{h_j/4}. \]

This route does not use exponential tilting, the COS expansion, spectral packets, or the K-COS error controller.

The four spectra include balanced, skewed, dominant-spike, and higher-rank cases. Each reference integral was evaluated at two truncation limits. The omitted integral after the frequency cutoff \(T>0\) was bounded using

\[ \frac1\pi \int_T^\infty\frac{du}{uR(u)} \le \frac{C}{\pi\nu}T^{-\nu}, \qquad \nu=\frac12\sum_jh_j, \qquad C=\prod_j\lambda_j^{-h_j/2}. \]
spectrumrank\(|\Delta\log_{10}p|\)relative differencereference tail bound / \(p\)
balanced80\(6.52\times10^{-15}\)\(1.50\times10^{-14}\)\(6.84\times10^{-20}\)
skewed80\(4.13\times10^{-15}\)\(9.50\times10^{-15}\)\(4.44\times10^{-18}\)
spiky80\(5.19\times10^{-15}\)\(1.20\times10^{-14}\)\(7.00\times10^{-17}\)
balanced120\(2.88\times10^{-15}\)\(6.64\times10^{-15}\)\(4.19\times10^{-29}\)

The two inversion truncations agree to between approximately

\[ 1.2\times10^{-21} \quad\text{and}\quad 3.7\times10^{-17} \]

decades across the four cases. Thus the slow reference is numerically stable at a scale well below the observed K-COS-versus-inversion difference. Agreement between truncations is convergence evidence. The omitted-integral bound alone does not enclose quadrature discretization or numerical rounding, so this comparison is not assigned the directed-enclosure guarantee.

Independent direct-inversion checks near p=10 -16 on four heterogeneous spectra. Circles show relative K-COS/reference differences and diamonds show the reference integral-tail bound. The latter is one error component, not a complete enclosure of all reference arithmetic.
Figure 11.2. Independent direct-inversion checks near \(p=10^{-16}\) on four heterogeneous spectra. Circles show relative K-COS/reference differences and diamonds show the reference integral-tail bound. The latter is one error component, not a complete enclosure of all reference arithmetic.

View full-size figure (new tab)

This test is complementary to the exact scaled-chi-square controls. It asks whether the solver remains accurate when no single-gamma reduction is available and when an algorithmically different inversion of the full characteristic function is used as the reference.

These results have different evidentiary roles. The scaled-chi-square, finite-endpoint signed, Laplace signed, and noncentral cases provide analytic controls. The heterogeneous inversion battery, large-scale, strong-dependence, and rank-340 mixed-sign cases test irregular spectra for which no single-gamma closed form is available. Together they test correctness against known distributions, representation compression, and stability on the intended high-rank numerical regime. The low-rank Laplace example also records a deliberate certificate failure boundary rather than conflating numerical agreement with certification.

11.2 Signed and noncentral controls

Exact finite-endpoint control.

For

\[ Q=-0.02\,\chi^2_{80}, \]

the right tail is a lower chi-square tail with finite upper endpoint zero. The signed engine agrees with the exact distribution through

\[ \boxed{p=10^{-200}}, \]

with maximum observed log-probability error about \(2.84\times10^{-14}\) decades and certificates around \(10^{-12}\).

Mixed-sign high-rank analytic-ledger control.

A deterministic rank-340 multiscale spectrum with 180 positive and 160 negative coefficients was tested from approximately \(10^{-14}\) to

\[ \boxed{p\approx10^{-81.891937}}. \]

At the deepest point the packetized solver used 35 packets, \(N=4096\), and reported a relative certificate

\[ 5.78\times10^{-9}. \]

Its log-probability differed from the unpacketized full-spectrum signed solver by about \(1.42\times10^{-12}\) decades. Independent exponential-tilt importance sampling placed the discrepancy at about \(1.41\) Monte Carlo standard errors.

Retained low-rank limitation.

For independent \(Y_1,Y_2\sim\chi^2_2\), the quadratic form

\[ Q=0.07(Y_1-Y_2) \]

is Laplace distributed with scale \(0.14\), so for \(q\ge0\),

\[ P(Q\ge q)=\frac12e^{-q/0.14}. \]

The computed values agree with this exact law through \(10^{-200}\) to roughly \(10^{-9}\) decades or better. However, the implemented analytic COS-series certificate rejects these low-rank mixed cases because the tilted characteristic function decays only as \(|t|^{-2}\). The implementation reports this as a certificate failure rather than silently accepting the numerical value.

The negative finite-endpoint and rank-340 mixed-sign controls meet the requested analytic tolerance. The rank-four Laplace controls do not, despite close numerical agreement with their exact law. The horizontal line is the requested tolerance. These analytic-ledger results do not enclose floating-point roundoff.
Figure 11.3. The negative finite-endpoint and rank-340 mixed-sign controls meet the requested analytic tolerance. The rank-four Laplace controls do not, despite close numerical agreement with their exact law. The horizontal line is the requested tolerance. These analytic-ledger results do not enclose floating-point roundoff.

View full-size figure (new tab)

Absolute log-probability discrepancies for three scaled noncentral chi-square families, labeled by degrees of freedom and noncentrality. Recorded zeros remain at zero. All analytic truncation checks pass, but this comparison is not a directed probability enclosure.
Figure 11.4. Absolute log-probability discrepancies for three scaled noncentral chi-square families, labeled by degrees of freedom and noncentrality. Recorded zeros remain at zero. All analytic truncation checks pass, but this comparison is not a directed probability enclosure.

View full-size figure (new tab)

11.3 Rare-variant kernel case study

The preceding sections establish operator identities and certified numerical bounds. This section tests the same machinery on the project's existing rare-variant SKAT simulation layer, including explicit LD structure, covariates, per-variant standardization, rare-variant weighting, and the phenotype-space score statistic.

11.3.1 Simulation provenance and implementation correction

Two established genotype generators were used.

The first is a latent-Gaussian block-LD generator. Within a genomic block, alleles are obtained by thresholding correlated Gaussian latent variables at variant-specific minor-allele frequencies.

The second is a copy-LD generator in which haplotype states persist along a block with high probability and are occasionally redrawn. The simulator must initialize its genotype accumulator to zero before adding haplotypes. Allocating the accumulator with np.empty and then applying += would make the output depend on unspecified memory contents. All copy-LD results reported here use explicit zero initialization. Results from an uninitialized accumulator are excluded from the evidence record.

11.3.2 Tested LD regimes

Four deterministic scenarios were evaluated.

Table 11.1. Synthetic rare-variant simulation scenarios. Adjacent \(r^2\) is computed within the simulated LD blocks after variant standardization.
scenario\(n\)\(m\)rankmedian adjacent \(r^2\)effective rank
latent LD, moderate60030005960.0069441.9
latent LD, strong60030005960.1140240.3
copy LD, strong60030005960.8298200.1
copy LD, large100050009960.8179353.0

Effective rank here is the participation ratio

\[ r_{\rm eff}=\frac{(\sum_j\lambda_j)^2}{\sum_j\lambda_j^2}. \]

It measures spectral concentration, not an integer count of nonzero directions. The corresponding spectra therefore span a substantial range of concentration: stronger LD reduces effective rank even when the nominal quadratic-form rank remains close to the sample residual dimension.

Nonzero and effective rank across four synthetic dependence scenarios. Connectors pair the two quantities for each scenario. Stronger dependence changes spectral concentration substantially even when nonzero rank is unchanged.
Figure 11.5. Nonzero and effective rank across four synthetic dependence scenarios. Connectors pair the two quantities for each scenario. Stronger dependence changes spectral concentration substantially even when nonzero rank is unchanged.

View full-size figure (new tab)

11.3.3 Streaming directly from raw genotype blocks

The raw genotype matrix was streamed in resident variant blocks of widths 31, 127, and 509. Within each block the implementation performs

\[ \begin{aligned} G_b&\longrightarrow G_b-\bar G_b \longrightarrow \widetilde G_b,\\ \widetilde G_b&\longrightarrow M_X\widetilde G_b \longrightarrow A_b=M_X\widetilde G_bW_b^{1/2} \longrightarrow A_bA_b^\top, \end{aligned} \]

where \(\widetilde G_b\) denotes the centered and scaled block. The full weighted factor is never materialized.

Across all four LD scenarios and all three resident block sizes, the largest relative discrepancy against the fully materialized kernel was

\[ \boxed{6.61\times10^{-16}}. \]
Retained raw-genotype streaming discrepancies across synthetic dependence regimes and resident block widths. Marker shapes distinguish the scenarios in grayscale as well as color. The plotted differences are at floating-point summation scale.
Figure 11.6. Retained raw-genotype streaming discrepancies across synthetic dependence regimes and resident block widths. Marker shapes distinguish the scenarios in grayscale as well as color. The plotted differences are at floating-point summation scale.

View full-size figure (new tab)

This test is stronger than applying the streamed identity to a precomputed factor because the centering, variance scaling, covariate projection, and rare-variant weights are all performed inside the block loop.

11.3.4 Phenotype-space equivalence

For each scenario, 100 Gaussian null residual draws were evaluated in three ways. Under the standardized Gaussian null, write \(e=M_Xz\) with \(z\sim N(0,I)\). Because \(M_XA=A\), the statistic used here is \(Q=\frac12 z^\top Kz\), so its nonzero mixture coefficients are \(\frac12\lambda_j(K)\). The factor \(\frac12\) belongs to this case-study normalization, not to the general quadratic-form definition.

  1. directly through the factor,

    \[ Q=\frac12\|A^\top e\|_2^2. \]
  2. through the sample kernel,

    \[ Q=\frac12 e^\top Ke. \]
  3. through the eigencoordinates of \(K\).

The worst relative discrepancy across all draws and all scenarios was

\[ \boxed{8.32\times10^{-16}}. \]

Thus the simulated phenotype path, the streamed kernel, and the generalized \(\chi^2\) spectral representation agree to floating-point precision.

11.3.5 Deep tails on simulated LD spectra

For every scenario, tail queries were generated at tilt fractions 0.90, 0.97, and 0.99 of the positive singularity. K-COS was compared with a higher-resolution full-spectrum tilted reference.

The large corrected copy-LD case was then pushed further, to fractions 0.995, 0.997, 0.999, and 0.9995. The deepest tested reference value was

\[ \boxed{\log_{10}p=-457.973916}. \]

At that point the displayed K-COS and high-resolution full-spectrum values were identical. Across the complete realistic-LD battery, the largest absolute discrepancy was

\[ \boxed{3.21\times10^{-12}\ \text{decades}}. \]
Absolute differences between K-COS and refined full-spectrum tilted references on the synthetic dependence scenarios. The corrected large copy-LD controls extend through approximately 10 -458 . Zeros are plotted at zero rather than assigned an artificial positive floor.
Figure 11.7. Absolute differences between K-COS and refined full-spectrum tilted references on the synthetic dependence scenarios. The corrected large copy-LD controls extend through approximately \(10^{-458}\). Zeros are plotted at zero rather than assigned an artificial positive floor.

View full-size figure (new tab)

For the \(n=1000\), \(m=5000\) corrected copy-LD spectrum, selected results are

tilt fraction\(\log_{10}p\)COS modes \(N\)absolute error (decades)
0.9950-65.9506692048\(4.69\times10^{-13}\)
0.9970-95.3050342048\(3.70\times10^{-14}\)
0.9990-240.6020478192\(4.94\times10^{-14}\)
0.9995-457.97391616384below stored reference resolution

11.3.6 Interpretation and boundary

This simulation block does not add a new algebraic theorem. It supplies a more demanding validation layer for the theorem chain already proved. Specifically, it shows that the exact streaming identities and the K-COS deep-tail machinery remain numerically stable under substantially different rare-variant LD structures and through the complete raw-genotype preprocessing path.

The evidence remains synthetic. These generators do not reproduce every population-genetic feature of a sequencing cohort, and this block is not an external-cohort replication. It addresses the Gaussian linear-model null. Finite-sample Bernoulli or logistic calibration remains a separate statistical problem.

11.4 Spectral-packet experiments

These tables and figures report the retained packet-planner experiments. Their analytic error bounds exclude floating-point roundoff. They measure a different numerical path from the directed positive backend, and are not reinterpreted as directed probability enclosures or new performance runs.

11.4.1 Exactly solvable chi-square stress test

To isolate the effect of exponential tilting, we first used

\[ Q=0.02\chi^2_{80}, \]

whose survival probabilities are available directly from the chi-square distribution. Table 11.2 compares a global COS calculation with query-centered tilted COS.

Table 11.2. Relative error in an exactly solvable chi-square family.
Target tail \(p\)\(N\)Global COS rel. errorTilted COS rel. error
\(10^{-6}\)64\(3.56\times10^{-8}\)\(2.71\times10^{-14}\)
\(10^{-10}\)64\(1.64\times10^{-4}\)\(6.59\times10^{-15}\)
\(10^{-10}\)128\(2.03\times10^{-6}\)\(9.05\times10^{-15}\)
\(10^{-14}\)64\(1.43\)\(3.53\times10^{-14}\)
\(10^{-14}\)128\(6.15\times10^{-2}\)\(3.87\times10^{-14}\)

The test demonstrates the numerical motivation for tilting: evaluating a small tail directly under the shifted law is substantially more stable than reconstructing a global CDF and subtracting from one. This observation is not a novelty claim for exponential tilting itself.

11.4.2 Genotype-derived spectra

The second experiment used the existing Komorebi SKAT benchmark generator. Synthetic genotype matrices were centered and scaled, then residualized against three covariates. The kernel weights were \(w_j=(1-\mathrm{MAF}_j)^{24}\), where MAF denotes minor-allele frequency. The factor used column scales \(\sqrt{w_j}\). Its positive quadratic-form spectrum was

\[ \lambda=\tfrac12\operatorname{eig}(AA^{\mathsf T}). \]

Three independent \(n=400\), \(m=1200\) genotype sets yielded numerical rank \(397\). Four upper-tail queries per spectrum were generated by choosing saddlepoint locations at fractions \(0.70,0.80,0.85,0.90\) of the transform singularity. The comparison reference used exact-spectrum tilted COS with \(N=2048\) and a large support parameter \(L=20\). The adaptive method was asked for a relative analytic tolerance of \(10^{-8}\).

Across the twelve queries:

  • every requested \(10^{-8}\) analytic certificate passed.

  • the worst observed relative error was \(6.148608\times10^{-11}\).

  • the largest returned analytic relative bound was \(7.917203\times10^{-9}\).

  • the planner selected \(N\in\{64,128\}\), \(L\in\{10,11,12,13\}\), and 11–16 packets.

Figure 11.8 plots the observed errors against the returned analytic bounds. Every point lies above the equality line because the vertical coordinate is the bound.

Twelve retained genotype-derived tail queries, redrawn from the recovered source table. The vertical coordinate is the analytic relative bound and the horizontal coordinate is observed relative error. Every point lies above equality. Marker shape identifies the source spectrum.
Figure 11.8. Twelve retained genotype-derived tail queries, redrawn from the recovered source table. The vertical coordinate is the analytic relative bound and the horizontal coordinate is observed relative error. Every point lies above equality. Marker shape identifies the source spectrum.

View full-size figure (new tab)

11.4.3 Tolerance ladder

At a reference tail probability near \(8.99\times10^{-15}\), the same engine was requested to meet three tolerances. Table 11.3 shows how the representation refined automatically.

Table 11.3. Adaptive refinement at an extreme-tail query.
Requested \(\tau\)\(N\)\(L\)PacketsAnalytic boundObserved error
\(10^{-6}\)1281010\(3.56\times10^{-7}\)\(3.63\times10^{-12}\)
\(10^{-8}\)1281215\(4.87\times10^{-9}\)\(9.14\times10^{-13}\)
\(10^{-10}\)2561424\(8.21\times10^{-11}\)\(5.65\times10^{-14}\)
One extreme-tail query evaluated under three requested tolerances. Increasing the accuracy request refines the packet representation and, at the tightest setting, the mode count. The returned analytic bound remains above observed error and below the requested tolerance.
Figure 11.9. One extreme-tail query evaluated under three requested tolerances. Increasing the accuracy request refines the packet representation and, at the tightest setting, the mode count. The returned analytic bound remains above observed error and below the requested tolerance.

View full-size figure (new tab)

11.4.4 Prototype runtime scaling

Table 11.4 reports median CPU timings from the Python prototype. “Adaptive total” includes planning and analytic error checks. “Compiled evaluation” measures reuse of an already compiled spectral passport at the selected grid.

Table 11.4. Prototype runtime scaling on genotype-derived spectra.
RankPacketsExact tiltedAdaptive totalCompiled eval.Compiled speedup
397136.66 ms10.45 ms0.549 ms\(12.1\times\)
7971613.32 ms11.49 ms0.604 ms\(22.0\times\)
11971721.52 ms11.24 ms0.651 ms\(33.1\times\)
Retained median CPU timings for exact tilted COS, the adaptive calculation including planning, and reuse of a compiled spectral representation. The logarithmic vertical scale keeps the much smaller reuse cost visible. First-query and reuse costs are not interchangeable.
Figure 11.10. Retained median CPU timings for exact tilted COS, the adaptive calculation including planning, and reuse of a compiled spectral representation. The logarithmic vertical scale keeps the much smaller reuse cost visible. First-query and reuse costs are not interchangeable.

View full-size figure (new tab)

Planning matters. The first adaptive query is slower at rank 397 and faster at rank 797 in this prototype. Compiled reuse measures a different cost. These timings establish no universal speedup.

11.5 Numerical verification

Table 11.5. Stored-run identifiers and actual block counts.
partitionblocksGram relative erroraction relative error
coarse 44\(2.91\times10^{-16}\)\(5.99\times10^{-16}\)
fine 6432\(3.39\times10^{-16}\)\(6.00\times10^{-16}\)
irregular9\(3.34\times10^{-16}\)\(5.87\times10^{-16}\)
singleton-front21\(2.43\times10^{-16}\)\(5.82\times10^{-16}\)
permuted, block 7329\(3.52\times10^{-16}\)\(5.89\times10^{-16}\)

Hierarchical refinement gave relative discrepancy \(3.17\times10^{-16}\). For \(H=L^\top L\) with block-bidiagonal \(L\), the smallest eigenvalue was approximately \(2.86\) and the largest norm outside the exact light cone was zero. The QR-core singular-spectrum discrepancy was \(5.89\times10^{-16}\) in relative \(\ell_2\) norm. These are finite controls, not universal floating-point error bounds.

Source and conversion record

Source SHA-256: 3977873c15691d11b77d1a89cbdd54fb5496a79eda62d7384d21615268538e02

Unsupported prose commands stop the build. The mathematical expression sequence is checked against the source, with manuscript macros expanded for display.

Conversion records

Notation in The K-COS Method

Look up a symbol without leaving this chapter. Select text before opening help to search for it.

Search this work’s notation.

    Symbols can have different meanings in different passages. Read each result in its own context.

    Open the full notation index