This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Commit eaa647c
Zalenix Gardener
refactor(crossExperimentLearner): delegate stats helpers to shared ./stats module
This module shipped four hand-rolled copies of helpers that already live in docs/shared/stats.js — mean(), stddev(), linearRegression(), and four Math.min/max.apply(null, …) pairs. Two issues with the local copies:
1. Drift risk: stats.mean uses Kahan compensated summation and stats.linearRegression uses a single-pass O(n) algorithm; the local copies were the older, less stable two-pass implementations. Any future numerical fix to stats.js silently skipped this module.
2. Stack-overflow risk: Math.min/max.apply(null, arr) spreads the array as function arguments, which can throw RangeError on inputs > ~100k items (already noted in stats.minMax JSDoc).
Changes:
- Drop local mean/stddev/linearRegression definitions; import from ./stats.
- Keep linearRegression as a thin wrapper that clamps r2 to [0, +inf): all downstream confidence/rationale code in this module assumes r2 ∈ [0, 1].
- Keep local percentile() unchanged — it takes a 0..1 fraction whereas stats.percentile takes 0..100; swapping would silently break GOLDEN_PERCENTILE / FAILURE_PERCENTILE thresholds.
- Keep local pearsonCorrelation — its MIN_SAMPLES_FOR_CORRELATION gate is recommendation-engine policy, not a general stats primitive.
- Replace 4 Math.min/max.apply pairs with cached minMax() calls (recommend, getDeltaProfile, analyze).
Net diff: −37 / +20 lines. Verified: jest crossExperimentLearner → 43/43 tests pass; broader pattern run (8 suites, 296 tests) all green; node -c clean.1 parent a3ccf74 commit eaa647c
1 file changed
Lines changed: 29 additions & 39 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 107 | + | |
| 108 | + | |
122 | 109 | | |
123 | 110 | | |
124 | 111 | | |
| |||
378 | 365 | | |
379 | 366 | | |
380 | 367 | | |
381 | | - | |
| 368 | + | |
| 369 | + | |
382 | 370 | | |
383 | 371 | | |
384 | 372 | | |
| |||
456 | 444 | | |
457 | 445 | | |
458 | 446 | | |
459 | | - | |
460 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
461 | 450 | | |
462 | 451 | | |
463 | 452 | | |
| |||
542 | 531 | | |
543 | 532 | | |
544 | 533 | | |
545 | | - | |
546 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
547 | 537 | | |
548 | 538 | | |
549 | 539 | | |
| |||
0 commit comments