nx_monte_carlo.nx
buildroot/runtime/nx_monte_carlo.nx
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
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
structs
| 91 | struct NxMonteCarloResult |
consts
| 77 | const NX_MC_TARGET_MET: nx_int = 0 |
| 78 | const NX_MC_OFF_TARGET: nx_int = 1 |
| 79 | const NX_MC_INSUFFICIENT_SAMPLES: nx_int = 2 |
| 80 | const NX_MC_ERR_BAD_PARAMS: nx_int = 3 |
| 81 | const NX_MC_N_VERDICTS: nx_int = 4 |
| 101 | const NX_MC_RESULT_BYTES: nx_int = 56 // 7 fields * 8 |
| 108 | const NX_MC_T_95: nx_int = 2007 // 1.96 Q10 |
| 109 | const NX_MC_T_99: nx_int = 2640 // 2.58 Q10 (large-n approx) |
| 110 | const NX_MC_Q10: nx_int = 1024 |
| 114 | const NX_MC_MIN_N: nx_int = 30 |
functions
| 83 | func nx_mc_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 120 | func _mc_welford_update(n_old: nx_int, mean_old: i64, M2_old: i64, called by 1: nx_monte_carlo_verify |
| 146 | func nx_monte_carlo_verify( |
| 249 | func _mc_test_sampler(prng: *i64) -> i64 calls 1: nx_prng_range |
| 254 | func main() -> i64 |