code wiki / (root) / nx_monte_carlo.nx

nx_monte_carlo.nx

buildroot/runtime/nx_monte_carlo.nx

10201 B287 linesdepth 4pulls 6 transitivereach 2 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_monte_carlo.nx -- Monte Carlo verifier with statistical bounds. First substrate primitive grounded in CLASSICAL STATISTICAL THEORY per cardinal feedback-loras-and-negatives-are-patches-not- systems: User: "inputs from classifiers lead to known outputs all with statistical measurement i mean monte carlo or other multivariate systems prove this" The substrate doesn't invent predictability. It APPLIES the techniques (Monte Carlo, multivariate statistics, classification theory) the AI field abandoned for deep-learning opacity. ===== What this primitive does ================================== Given: - sample_fn : generates one measurement (i64 scalar) - n_samples : how many to draw - target_q10 : the target mean (in caller's chosen units) - tol_q10 : tolerance bound (output mean must be within target +/- tol) - seed : PRNG seed for reproducibility Returns: - empirical mean - empirical variance (Welford 1962 online algorithm) - verdict: TARGET_MET / OFF_TARGET / INSUFFICIENT_SAMPLES - the t-statistic for the test (caller can compute confidence intervals + decide their own threshold if 95% default is wrong for their use) ===== Statistical method ========================================= One-sample t-test (Student 1908, Welch 1947 variant for unequal variance not needed here since we test against fixed target): t = (mean - target) / (sd / sqrt(n)) |t| < critical_value for given confidence + (n-1) dof -> mean is

dependencies 5 imports · 1 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_isqrt.nx nx_prng.nx nx_monte_carlo.nx nx_multivariate.nx

imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_isqrt.nxnx_prng.nx

imported by: nx_multivariate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_monte_carlo_verify sys_mmap nx_prng_init _mc_welford_update nx_isqrt_q10 nx_isqrt nx_mc_verdict_is_valid

structs

91struct NxMonteCarloResult

consts

77const NX_MC_TARGET_MET: nx_int = 0
78const NX_MC_OFF_TARGET: nx_int = 1
79const NX_MC_INSUFFICIENT_SAMPLES: nx_int = 2
80const NX_MC_ERR_BAD_PARAMS: nx_int = 3
81const NX_MC_N_VERDICTS: nx_int = 4
101const NX_MC_RESULT_BYTES: nx_int = 56 // 7 fields * 8
108const NX_MC_T_95: nx_int = 2007 // 1.96 Q10
109const NX_MC_T_99: nx_int = 2640 // 2.58 Q10 (large-n approx)
110const NX_MC_Q10: nx_int = 1024
114const NX_MC_MIN_N: nx_int = 30

functions

83func nx_mc_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
120func _mc_welford_update(n_old: nx_int, mean_old: i64, M2_old: i64,
146func nx_monte_carlo_verify(
249func _mc_test_sampler(prng: *i64) -> i64
calls 1: nx_prng_range
254func main() -> i64