@mindpeeker/negentropy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -0
- package/dist/estimators/entropy.d.ts +22 -0
- package/dist/estimators/entropy.d.ts.map +1 -0
- package/dist/estimators/entropy.js +78 -0
- package/dist/estimators/entropy.js.map +1 -0
- package/dist/estimators/frequency.d.ts +18 -0
- package/dist/estimators/frequency.d.ts.map +1 -0
- package/dist/estimators/frequency.js +57 -0
- package/dist/estimators/frequency.js.map +1 -0
- package/dist/estimators/negentropy.d.ts +62 -0
- package/dist/estimators/negentropy.d.ts.map +1 -0
- package/dist/estimators/negentropy.js +104 -0
- package/dist/estimators/negentropy.js.map +1 -0
- package/dist/estimators/pipeline.d.ts +25 -0
- package/dist/estimators/pipeline.d.ts.map +1 -0
- package/dist/estimators/pipeline.js +30 -0
- package/dist/estimators/pipeline.js.map +1 -0
- package/dist/estimators/vasicek.d.ts +18 -0
- package/dist/estimators/vasicek.d.ts.map +1 -0
- package/dist/estimators/vasicek.js +57 -0
- package/dist/estimators/vasicek.js.map +1 -0
- package/dist/estimators/windowed.d.ts +27 -0
- package/dist/estimators/windowed.d.ts.map +1 -0
- package/dist/estimators/windowed.js +66 -0
- package/dist/estimators/windowed.js.map +1 -0
- package/dist/experiment/batch.d.ts +15 -0
- package/dist/experiment/batch.d.ts.map +1 -0
- package/dist/experiment/batch.js +179 -0
- package/dist/experiment/batch.js.map +1 -0
- package/dist/experiment/composite.d.ts +12 -0
- package/dist/experiment/composite.d.ts.map +1 -0
- package/dist/experiment/composite.js +26 -0
- package/dist/experiment/composite.js.map +1 -0
- package/dist/experiment/registration.d.ts +20 -0
- package/dist/experiment/registration.d.ts.map +1 -0
- package/dist/experiment/registration.js +54 -0
- package/dist/experiment/registration.js.map +1 -0
- package/dist/experiment/session.d.ts +47 -0
- package/dist/experiment/session.d.ts.map +1 -0
- package/dist/experiment/session.js +245 -0
- package/dist/experiment/session.js.map +1 -0
- package/dist/experiment/types.d.ts +68 -0
- package/dist/experiment/types.d.ts.map +1 -0
- package/dist/experiment/types.js +2 -0
- package/dist/experiment/types.js.map +1 -0
- package/dist/extract/accounting.d.ts +52 -0
- package/dist/extract/accounting.d.ts.map +1 -0
- package/dist/extract/accounting.js +130 -0
- package/dist/extract/accounting.js.map +1 -0
- package/dist/extract/condition.d.ts +23 -0
- package/dist/extract/condition.d.ts.map +1 -0
- package/dist/extract/condition.js +50 -0
- package/dist/extract/condition.js.map +1 -0
- package/dist/extract/debias.d.ts +25 -0
- package/dist/extract/debias.d.ts.map +1 -0
- package/dist/extract/debias.js +80 -0
- package/dist/extract/debias.js.map +1 -0
- package/dist/extract/health.d.ts +44 -0
- package/dist/extract/health.d.ts.map +1 -0
- package/dist/extract/health.js +115 -0
- package/dist/extract/health.js.map +1 -0
- package/dist/extract/toeplitz.d.ts +19 -0
- package/dist/extract/toeplitz.d.ts.map +1 -0
- package/dist/extract/toeplitz.js +83 -0
- package/dist/extract/toeplitz.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/bytes.d.ts +6 -0
- package/dist/internal/bytes.d.ts.map +1 -0
- package/dist/internal/bytes.js +36 -0
- package/dist/internal/bytes.js.map +1 -0
- package/dist/internal/kahan.d.ts +7 -0
- package/dist/internal/kahan.d.ts.map +1 -0
- package/dist/internal/kahan.js +15 -0
- package/dist/internal/kahan.js.map +1 -0
- package/dist/internal/prng.d.ts +7 -0
- package/dist/internal/prng.d.ts.map +1 -0
- package/dist/internal/prng.js +16 -0
- package/dist/internal/prng.js.map +1 -0
- package/dist/internal/special.d.ts +36 -0
- package/dist/internal/special.d.ts.map +1 -0
- package/dist/internal/special.js +258 -0
- package/dist/internal/special.js.map +1 -0
- package/dist/internal/welford.d.ts +13 -0
- package/dist/internal/welford.d.ts.map +1 -0
- package/dist/internal/welford.js +30 -0
- package/dist/internal/welford.js.map +1 -0
- package/dist/numerics.d.ts +32 -0
- package/dist/numerics.d.ts.map +1 -0
- package/dist/numerics.js +32 -0
- package/dist/numerics.js.map +1 -0
- package/dist/stats/calibration.d.ts +14 -0
- package/dist/stats/calibration.d.ts.map +1 -0
- package/dist/stats/calibration.js +41 -0
- package/dist/stats/calibration.js.map +1 -0
- package/dist/stats/cumdev.d.ts +15 -0
- package/dist/stats/cumdev.d.ts.map +1 -0
- package/dist/stats/cumdev.js +38 -0
- package/dist/stats/cumdev.js.map +1 -0
- package/dist/stats/network.d.ts +29 -0
- package/dist/stats/network.d.ts.map +1 -0
- package/dist/stats/network.js +119 -0
- package/dist/stats/network.js.map +1 -0
- package/dist/stats/pvalues.d.ts +11 -0
- package/dist/stats/pvalues.d.ts.map +1 -0
- package/dist/stats/pvalues.js +18 -0
- package/dist/stats/pvalues.js.map +1 -0
- package/dist/stats/trials.d.ts +34 -0
- package/dist/stats/trials.d.ts.map +1 -0
- package/dist/stats/trials.js +149 -0
- package/dist/stats/trials.js.map +1 -0
- package/dist/stats/zscores.d.ts +10 -0
- package/dist/stats/zscores.d.ts.map +1 -0
- package/dist/stats/zscores.js +26 -0
- package/dist/stats/zscores.js.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Special-functions core. Everything downstream (p-values, envelopes, probit
|
|
3
|
+
* mapping) keys off these. Accuracy target: relative error ≤ 1e-12 for the
|
|
4
|
+
* incomplete gamma over df up to ~10^4 — tail p-values must be trustworthy,
|
|
5
|
+
* which rules out the Abramowitz–Stegun/Wilson–Hilferty shortcuts used for
|
|
6
|
+
* coarse pass/fail elsewhere in the SDK.
|
|
7
|
+
*/
|
|
8
|
+
/** Natural log of the gamma function. Domain: x > 0 (reflection handles (0, 0.5)). */
|
|
9
|
+
export declare function lnGamma(x: number): number;
|
|
10
|
+
/** Regularized lower incomplete gamma P(a, x) = γ(a, x)/Γ(a). */
|
|
11
|
+
export declare function gammaP(a: number, x: number): number;
|
|
12
|
+
/** Regularized upper incomplete gamma Q(a, x) = 1 − P(a, x). */
|
|
13
|
+
export declare function gammaQ(a: number, x: number): number;
|
|
14
|
+
/** Complementary error function, via erfc(x) = Q(½, x²) — accurate deep into the tail. */
|
|
15
|
+
export declare function erfc(x: number): number;
|
|
16
|
+
/** Standard normal CDF Φ(z). */
|
|
17
|
+
export declare function normCdf(z: number): number;
|
|
18
|
+
/** Standard normal survival function 1 − Φ(z), accurate for large z. */
|
|
19
|
+
export declare function normSf(z: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Inverse standard normal CDF (probit). Wichura's algorithm AS 241 (PPND16),
|
|
22
|
+
* ~1e-15 relative accuracy — the algorithm behind R's qnorm.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normPpf(p: number): number;
|
|
25
|
+
/** Chi-square survival function P(X > x) for df k. */
|
|
26
|
+
export declare function chi2Sf(x: number, k: number): number;
|
|
27
|
+
/** Chi-square CDF P(X ≤ x) for df k. */
|
|
28
|
+
export declare function chi2Cdf(x: number, k: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Chi-square quantile (inverse CDF): the x with P(X ≤ x) = p. Newton's method
|
|
31
|
+
* on ln(CDF) — which stays quadratically convergent on the exponentially
|
|
32
|
+
* decaying tail where plain-space Newton overshoots and crawls — seeded with
|
|
33
|
+
* Wilson–Hilferty and safeguarded by a maintained bisection bracket.
|
|
34
|
+
*/
|
|
35
|
+
export declare function chi2Ppf(p: number, k: number): number;
|
|
36
|
+
//# sourceMappingURL=special.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special.d.ts","sourceRoot":"","sources":["../../src/internal/special.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQzC;AA0CD,iEAAiE;AACjE,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,gEAAgE;AAChE,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,0FAA0F;AAC1F,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAItC;AAED,gCAAgC;AAChC,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,wEAAwE;AACxE,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAgFzC;AAED,sDAAsD;AACtD,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,wCAAwC;AACxC,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIpD;AAQD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA+BpD"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Special-functions core. Everything downstream (p-values, envelopes, probit
|
|
3
|
+
* mapping) keys off these. Accuracy target: relative error ≤ 1e-12 for the
|
|
4
|
+
* incomplete gamma over df up to ~10^4 — tail p-values must be trustworthy,
|
|
5
|
+
* which rules out the Abramowitz–Stegun/Wilson–Hilferty shortcuts used for
|
|
6
|
+
* coarse pass/fail elsewhere in the SDK.
|
|
7
|
+
*/
|
|
8
|
+
const EPS = 1e-15;
|
|
9
|
+
const FPMIN = 1e-300;
|
|
10
|
+
const MAX_ITER = 10_000;
|
|
11
|
+
const LN_SQRT_2PI = 0.9189385332046727; // ln(√(2π))
|
|
12
|
+
// Lanczos g=7, n=9 (Godfrey coefficients — ~1e-15 relative error)
|
|
13
|
+
const LANCZOS_G = 7;
|
|
14
|
+
const LANCZOS = [
|
|
15
|
+
0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.3234287776531,
|
|
16
|
+
-176.6150291621406, 12.507343278686905, -0.13857109526572012, 9.984369578019572e-6,
|
|
17
|
+
1.5056327351493116e-7,
|
|
18
|
+
];
|
|
19
|
+
/** Natural log of the gamma function. Domain: x > 0 (reflection handles (0, 0.5)). */
|
|
20
|
+
export function lnGamma(x) {
|
|
21
|
+
if (!Number.isFinite(x) || x <= 0)
|
|
22
|
+
throw new RangeError(`lnGamma: x must be > 0, got ${x}`);
|
|
23
|
+
if (x < 0.5)
|
|
24
|
+
return Math.log(Math.PI / Math.sin(Math.PI * x)) - lnGamma(1 - x);
|
|
25
|
+
const xm1 = x - 1;
|
|
26
|
+
let a = LANCZOS[0];
|
|
27
|
+
for (let i = 1; i < LANCZOS.length; i++)
|
|
28
|
+
a += LANCZOS[i] / (xm1 + i);
|
|
29
|
+
const t = xm1 + LANCZOS_G + 0.5;
|
|
30
|
+
return LN_SQRT_2PI + (xm1 + 0.5) * Math.log(t) - t + Math.log(a);
|
|
31
|
+
}
|
|
32
|
+
/** exp(−x + a·ln x − lnΓ(a)) — the prefactor shared by both gamma branches. */
|
|
33
|
+
function gammaPrefactor(a, x) {
|
|
34
|
+
return Math.exp(-x + a * Math.log(x) - lnGamma(a));
|
|
35
|
+
}
|
|
36
|
+
/** Series expansion for P(a, x), valid (fast) for x < a + 1. */
|
|
37
|
+
function gammaPSeries(a, x) {
|
|
38
|
+
let ap = a;
|
|
39
|
+
let del = 1 / a;
|
|
40
|
+
let sum = del;
|
|
41
|
+
for (let i = 0; i < MAX_ITER; i++) {
|
|
42
|
+
ap += 1;
|
|
43
|
+
del *= x / ap;
|
|
44
|
+
sum += del;
|
|
45
|
+
if (Math.abs(del) < Math.abs(sum) * EPS)
|
|
46
|
+
return sum * gammaPrefactor(a, x);
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`gammaP: series did not converge for a=${a}, x=${x}`);
|
|
49
|
+
}
|
|
50
|
+
/** Lentz modified continued fraction for Q(a, x), valid (fast) for x ≥ a + 1. */
|
|
51
|
+
function gammaQContinuedFraction(a, x) {
|
|
52
|
+
let b = x + 1 - a;
|
|
53
|
+
let c = 1 / FPMIN;
|
|
54
|
+
let d = 1 / b;
|
|
55
|
+
let h = d;
|
|
56
|
+
for (let i = 1; i <= MAX_ITER; i++) {
|
|
57
|
+
const an = -i * (i - a);
|
|
58
|
+
b += 2;
|
|
59
|
+
d = an * d + b;
|
|
60
|
+
if (Math.abs(d) < FPMIN)
|
|
61
|
+
d = FPMIN;
|
|
62
|
+
c = b + an / c;
|
|
63
|
+
if (Math.abs(c) < FPMIN)
|
|
64
|
+
c = FPMIN;
|
|
65
|
+
d = 1 / d;
|
|
66
|
+
const del = d * c;
|
|
67
|
+
h *= del;
|
|
68
|
+
if (Math.abs(del - 1) < EPS)
|
|
69
|
+
return h * gammaPrefactor(a, x);
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`gammaQ: continued fraction did not converge for a=${a}, x=${x}`);
|
|
72
|
+
}
|
|
73
|
+
/** Regularized lower incomplete gamma P(a, x) = γ(a, x)/Γ(a). */
|
|
74
|
+
export function gammaP(a, x) {
|
|
75
|
+
if (!(a > 0) || !(x >= 0))
|
|
76
|
+
throw new RangeError(`gammaP: need a > 0, x ≥ 0; got a=${a}, x=${x}`);
|
|
77
|
+
if (x === 0)
|
|
78
|
+
return 0;
|
|
79
|
+
return x < a + 1 ? gammaPSeries(a, x) : 1 - gammaQContinuedFraction(a, x);
|
|
80
|
+
}
|
|
81
|
+
/** Regularized upper incomplete gamma Q(a, x) = 1 − P(a, x). */
|
|
82
|
+
export function gammaQ(a, x) {
|
|
83
|
+
if (!(a > 0) || !(x >= 0))
|
|
84
|
+
throw new RangeError(`gammaQ: need a > 0, x ≥ 0; got a=${a}, x=${x}`);
|
|
85
|
+
if (x === 0)
|
|
86
|
+
return 1;
|
|
87
|
+
return x < a + 1 ? 1 - gammaPSeries(a, x) : gammaQContinuedFraction(a, x);
|
|
88
|
+
}
|
|
89
|
+
/** Complementary error function, via erfc(x) = Q(½, x²) — accurate deep into the tail. */
|
|
90
|
+
export function erfc(x) {
|
|
91
|
+
if (x < 0)
|
|
92
|
+
return 2 - erfc(-x);
|
|
93
|
+
if (x === 0)
|
|
94
|
+
return 1;
|
|
95
|
+
return gammaQ(0.5, x * x);
|
|
96
|
+
}
|
|
97
|
+
/** Standard normal CDF Φ(z). */
|
|
98
|
+
export function normCdf(z) {
|
|
99
|
+
return 0.5 * erfc(-z / Math.SQRT2);
|
|
100
|
+
}
|
|
101
|
+
/** Standard normal survival function 1 − Φ(z), accurate for large z. */
|
|
102
|
+
export function normSf(z) {
|
|
103
|
+
return 0.5 * erfc(z / Math.SQRT2);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Inverse standard normal CDF (probit). Wichura's algorithm AS 241 (PPND16),
|
|
107
|
+
* ~1e-15 relative accuracy — the algorithm behind R's qnorm.
|
|
108
|
+
*/
|
|
109
|
+
export function normPpf(p) {
|
|
110
|
+
if (!(p > 0 && p < 1))
|
|
111
|
+
throw new RangeError(`normPpf: p must be in (0, 1), got ${p}`);
|
|
112
|
+
const q = p - 0.5;
|
|
113
|
+
if (Math.abs(q) <= 0.425) {
|
|
114
|
+
const r = 0.180625 - q * q;
|
|
115
|
+
return ((q *
|
|
116
|
+
(((((((2509.0809287301227 * r + 33430.57558358813) * r + 67265.7709270087) * r +
|
|
117
|
+
45921.95393154987) *
|
|
118
|
+
r +
|
|
119
|
+
13731.69376550946) *
|
|
120
|
+
r +
|
|
121
|
+
1971.5909503065513) *
|
|
122
|
+
r +
|
|
123
|
+
133.14166789178438) *
|
|
124
|
+
r +
|
|
125
|
+
3.3871328727963665)) /
|
|
126
|
+
(((((((5226.495278852545 * r + 28729.085735721943) * r + 39307.89580009271) * r +
|
|
127
|
+
21213.794301586597) *
|
|
128
|
+
r +
|
|
129
|
+
5394.196021424751) *
|
|
130
|
+
r +
|
|
131
|
+
687.1870074920579) *
|
|
132
|
+
r +
|
|
133
|
+
42.31333070160091) *
|
|
134
|
+
r +
|
|
135
|
+
1));
|
|
136
|
+
}
|
|
137
|
+
let r = q < 0 ? p : 1 - p;
|
|
138
|
+
r = Math.sqrt(-Math.log(r));
|
|
139
|
+
let value;
|
|
140
|
+
if (r <= 5) {
|
|
141
|
+
r -= 1.6;
|
|
142
|
+
value =
|
|
143
|
+
(((((((0.0007745450142783414 * r + 0.022723844989269184) * r + 0.2417807251774506) * r +
|
|
144
|
+
1.2704582524523684) *
|
|
145
|
+
r +
|
|
146
|
+
3.6478483247632045) *
|
|
147
|
+
r +
|
|
148
|
+
5.769497221460691) *
|
|
149
|
+
r +
|
|
150
|
+
4.630337846156546) *
|
|
151
|
+
r +
|
|
152
|
+
1.4234371107496835) /
|
|
153
|
+
(((((((1.0507500716444169e-9 * r + 0.0005475938084995345) * r + 0.015198666563616457) * r +
|
|
154
|
+
0.14810397642748008) *
|
|
155
|
+
r +
|
|
156
|
+
0.6897673349851) *
|
|
157
|
+
r +
|
|
158
|
+
1.6763848301838038) *
|
|
159
|
+
r +
|
|
160
|
+
2.053191626637759) *
|
|
161
|
+
r +
|
|
162
|
+
1);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
r -= 5;
|
|
166
|
+
value =
|
|
167
|
+
(((((((2.0103343992922881e-7 * r + 0.000027115555687434876) * r + 0.0012426609473880784) * r +
|
|
168
|
+
0.026532189526576124) *
|
|
169
|
+
r +
|
|
170
|
+
0.29656057182850487) *
|
|
171
|
+
r +
|
|
172
|
+
1.7848265399172913) *
|
|
173
|
+
r +
|
|
174
|
+
5.463784911164114) *
|
|
175
|
+
r +
|
|
176
|
+
6.657904643501103) /
|
|
177
|
+
(((((((2.0442631033899397e-15 * r + 1.421511758316446e-7) * r + 0.000018463183175100548) * r +
|
|
178
|
+
0.0007868691311456133) *
|
|
179
|
+
r +
|
|
180
|
+
0.014875361290850615) *
|
|
181
|
+
r +
|
|
182
|
+
0.1369298809227358) *
|
|
183
|
+
r +
|
|
184
|
+
0.599832206555888) *
|
|
185
|
+
r +
|
|
186
|
+
1);
|
|
187
|
+
}
|
|
188
|
+
return q < 0 ? -value : value;
|
|
189
|
+
}
|
|
190
|
+
/** Chi-square survival function P(X > x) for df k. */
|
|
191
|
+
export function chi2Sf(x, k) {
|
|
192
|
+
if (!(k > 0))
|
|
193
|
+
throw new RangeError(`chi2Sf: df must be > 0, got ${k}`);
|
|
194
|
+
if (x <= 0)
|
|
195
|
+
return 1;
|
|
196
|
+
return gammaQ(k / 2, x / 2);
|
|
197
|
+
}
|
|
198
|
+
/** Chi-square CDF P(X ≤ x) for df k. */
|
|
199
|
+
export function chi2Cdf(x, k) {
|
|
200
|
+
if (!(k > 0))
|
|
201
|
+
throw new RangeError(`chi2Cdf: df must be > 0, got ${k}`);
|
|
202
|
+
if (x <= 0)
|
|
203
|
+
return 0;
|
|
204
|
+
return gammaP(k / 2, x / 2);
|
|
205
|
+
}
|
|
206
|
+
/** Chi-square density, computed in log space to survive large df. */
|
|
207
|
+
function chi2Pdf(x, k) {
|
|
208
|
+
if (x <= 0)
|
|
209
|
+
return 0;
|
|
210
|
+
return Math.exp((k / 2 - 1) * Math.log(x / 2) - x / 2 - lnGamma(k / 2)) / 2;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Chi-square quantile (inverse CDF): the x with P(X ≤ x) = p. Newton's method
|
|
214
|
+
* on ln(CDF) — which stays quadratically convergent on the exponentially
|
|
215
|
+
* decaying tail where plain-space Newton overshoots and crawls — seeded with
|
|
216
|
+
* Wilson–Hilferty and safeguarded by a maintained bisection bracket.
|
|
217
|
+
*/
|
|
218
|
+
export function chi2Ppf(p, k) {
|
|
219
|
+
if (!(k > 0))
|
|
220
|
+
throw new RangeError(`chi2Ppf: df must be > 0, got ${k}`);
|
|
221
|
+
if (!(p > 0 && p < 1))
|
|
222
|
+
throw new RangeError(`chi2Ppf: p must be in (0, 1), got ${p}`);
|
|
223
|
+
// Wilson–Hilferty seed: k(1 − 2/(9k) + z√(2/(9k)))³
|
|
224
|
+
const z = normPpf(p);
|
|
225
|
+
const h = 2 / (9 * k);
|
|
226
|
+
const cube = 1 - h + z * Math.sqrt(h);
|
|
227
|
+
let x = cube > 0 ? k * cube ** 3 : k / 2;
|
|
228
|
+
const lnP = Math.log(p);
|
|
229
|
+
// establish a bracket [lo, hi] with cdf(lo) < p < cdf(hi)
|
|
230
|
+
let lo = 0;
|
|
231
|
+
let hi = Math.max(2 * x, k + 10);
|
|
232
|
+
while (chi2Cdf(hi, k) < p) {
|
|
233
|
+
lo = hi;
|
|
234
|
+
hi *= 2;
|
|
235
|
+
if (hi > 1e308)
|
|
236
|
+
throw new Error(`chi2Ppf: bracket overflow for p=${p}, k=${k}`);
|
|
237
|
+
}
|
|
238
|
+
if (x <= lo || x >= hi)
|
|
239
|
+
x = (lo + hi) / 2;
|
|
240
|
+
for (let i = 0; i < 200; i++) {
|
|
241
|
+
const cdf = chi2Cdf(x, k);
|
|
242
|
+
if (cdf > p)
|
|
243
|
+
hi = x;
|
|
244
|
+
else
|
|
245
|
+
lo = x;
|
|
246
|
+
const pdf = chi2Pdf(x, k);
|
|
247
|
+
// Newton on g(x) = ln(cdf) − ln(p), with g' = pdf/cdf
|
|
248
|
+
let next = cdf > 0 && pdf > 0 ? x - ((Math.log(cdf) - lnP) * cdf) / pdf : Number.NaN;
|
|
249
|
+
if (!(next > lo && next < hi))
|
|
250
|
+
next = (lo + hi) / 2; // Newton left the bracket → bisect
|
|
251
|
+
const dx = Math.abs(next - x);
|
|
252
|
+
x = next;
|
|
253
|
+
if (dx < 1e-13 * Math.max(1, x))
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
return x;
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=special.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special.js","sourceRoot":"","sources":["../../src/internal/special.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,GAAG,GAAG,KAAK,CAAA;AACjB,MAAM,KAAK,GAAG,MAAM,CAAA;AACpB,MAAM,QAAQ,GAAG,MAAM,CAAA;AACvB,MAAM,WAAW,GAAG,kBAAkB,CAAA,CAAC,YAAY;AAEnD,kEAAkE;AAClE,MAAM,SAAS,GAAG,CAAC,CAAA;AACnB,MAAM,OAAO,GAAG;IACd,mBAAmB,EAAE,iBAAiB,EAAE,CAAC,kBAAkB,EAAE,iBAAiB;IAC9E,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,CAAC,mBAAmB,EAAE,oBAAoB;IAClF,qBAAqB;CACtB,CAAA;AAED,sFAAsF;AACtF,MAAM,UAAU,OAAO,CAAC,CAAS;IAC/B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,EAAE,CAAC,CAAA;IAC3F,IAAI,CAAC,GAAG,GAAG;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAC9E,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;IACjB,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAW,CAAA;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,E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E,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACzB,IAAI,GAAG,GAAG,CAAC;YAAE,EAAE,GAAG,CAAC,CAAA;;YACd,EAAE,GAAG,CAAC,CAAA;QACX,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACzB,sDAAsD;QACtD,IAAI,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAA;QACpF,IAAI,CAAC,CAAC,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;YAAE,IAAI,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA,CAAC,mCAAmC;QACvF,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;QAC7B,CAAC,GAAG,IAAI,CAAA;QACR,IAAI,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;YAAE,MAAK;IACxC,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Welford's one-pass, numerically stable mean/variance accumulator. */
|
|
2
|
+
export declare class Welford {
|
|
3
|
+
#private;
|
|
4
|
+
push(x: number): void;
|
|
5
|
+
get n(): number;
|
|
6
|
+
get mean(): number;
|
|
7
|
+
/** Sample variance (n − 1 denominator). NaN below two observations. */
|
|
8
|
+
get variance(): number;
|
|
9
|
+
/** Population variance (n denominator). NaN with no observations. */
|
|
10
|
+
get populationVariance(): number;
|
|
11
|
+
get sd(): number;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=welford.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"welford.d.ts","sourceRoot":"","sources":["../../src/internal/welford.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,qBAAa,OAAO;;IAKlB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAOrB,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,uEAAuE;IACvE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,qEAAqE;IACrE,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,IAAI,EAAE,IAAI,MAAM,CAEf;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Welford's one-pass, numerically stable mean/variance accumulator. */
|
|
2
|
+
export class Welford {
|
|
3
|
+
#n = 0;
|
|
4
|
+
#mean = 0;
|
|
5
|
+
#m2 = 0;
|
|
6
|
+
push(x) {
|
|
7
|
+
this.#n++;
|
|
8
|
+
const delta = x - this.#mean;
|
|
9
|
+
this.#mean += delta / this.#n;
|
|
10
|
+
this.#m2 += delta * (x - this.#mean);
|
|
11
|
+
}
|
|
12
|
+
get n() {
|
|
13
|
+
return this.#n;
|
|
14
|
+
}
|
|
15
|
+
get mean() {
|
|
16
|
+
return this.#mean;
|
|
17
|
+
}
|
|
18
|
+
/** Sample variance (n − 1 denominator). NaN below two observations. */
|
|
19
|
+
get variance() {
|
|
20
|
+
return this.#n < 2 ? Number.NaN : this.#m2 / (this.#n - 1);
|
|
21
|
+
}
|
|
22
|
+
/** Population variance (n denominator). NaN with no observations. */
|
|
23
|
+
get populationVariance() {
|
|
24
|
+
return this.#n < 1 ? Number.NaN : this.#m2 / this.#n;
|
|
25
|
+
}
|
|
26
|
+
get sd() {
|
|
27
|
+
return Math.sqrt(this.variance);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=welford.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"welford.js","sourceRoot":"","sources":["../../src/internal/welford.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,OAAO,OAAO;IAClB,EAAE,GAAG,CAAC,CAAA;IACN,KAAK,GAAG,CAAC,CAAA;IACT,GAAG,GAAG,CAAC,CAAA;IAEP,IAAI,CAAC,CAAS;QACZ,IAAI,CAAC,EAAE,EAAE,CAAA;QACT,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QAC5B,IAAI,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,EAAE,CAAA;QAC7B,IAAI,CAAC,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,EAAE,CAAA;IAChB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,uEAAuE;IACvE,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED,qEAAqE;IACrE,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAA;IACtD,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared numerics for @mindpeeker sibling packages.
|
|
3
|
+
*
|
|
4
|
+
* Re-export barrel behind the `@mindpeeker/negentropy/numerics` subpath. It exposes
|
|
5
|
+
* the package's fixture-validated numerical core — special functions cross-checked
|
|
6
|
+
* against scipy/mpmath to 1e-9..1e-15 relative error (see test/fixtures/special.json
|
|
7
|
+
* and scripts/fixtures/generate.py) — so sibling packages (e.g. @mindpeeker/psi,
|
|
8
|
+
* @mindpeeker/flow) can reuse it instead of duplicating delicate tail-accurate code.
|
|
9
|
+
*
|
|
10
|
+
* What lives here:
|
|
11
|
+
* - Special functions (internal/special.ts): $\ln\Gamma(x)$ via a Lanczos
|
|
12
|
+
* approximation (Godfrey $g=7$, $n=9$); the regularized incomplete gammas
|
|
13
|
+
* $P(a,x)=\gamma(a,x)/\Gamma(a)$ and $Q(a,x)=1-P(a,x)$ (series + Lentz continued
|
|
14
|
+
* fraction, per Numerical Recipes §6.2); $\mathrm{erfc}(x)=Q(\tfrac12,x^2)$;
|
|
15
|
+
* the standard normal CDF $\Phi(z)$, survival $1-\Phi(z)$, and quantile
|
|
16
|
+
* $\Phi^{-1}(p)$ (Wichura's AS 241 / PPND16); chi-square CDF/SF/quantile for
|
|
17
|
+
* df $k$ via $P(k/2, x/2)$, $Q(k/2, x/2)$, and a bracketed log-space Newton.
|
|
18
|
+
* - Compensated accumulation: KahanSum (Kahan 1965 compensated summation, $O(\varepsilon)$
|
|
19
|
+
* error on long sums) and Welford (Welford 1962 one-pass mean/variance).
|
|
20
|
+
* - Byte/bit utilities (internal/bytes.ts): toBits (MSB-first, the SDK-wide bit
|
|
21
|
+
* order), concatBytes, and the POPCOUNT per-byte one-bits table.
|
|
22
|
+
*
|
|
23
|
+
* Stability: this is a secondary entry point of @mindpeeker/negentropy and carries
|
|
24
|
+
* the same semver guarantees as the root export — additions are minor, removals or
|
|
25
|
+
* signature changes are major. Deterministic and browser-safe: no I/O, no `node:`
|
|
26
|
+
* builtins, same inputs always produce the same outputs.
|
|
27
|
+
*/
|
|
28
|
+
export { concatBytes, POPCOUNT, toBits } from './internal/bytes.js';
|
|
29
|
+
export { KahanSum } from './internal/kahan.js';
|
|
30
|
+
export { chi2Cdf, chi2Ppf, chi2Sf, erfc, gammaP, gammaQ, lnGamma, normCdf, normPpf, normSf, } from './internal/special.js';
|
|
31
|
+
export { Welford } from './internal/welford.js';
|
|
32
|
+
//# sourceMappingURL=numerics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numerics.d.ts","sourceRoot":"","sources":["../src/numerics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,MAAM,GACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/numerics.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared numerics for @mindpeeker sibling packages.
|
|
3
|
+
*
|
|
4
|
+
* Re-export barrel behind the `@mindpeeker/negentropy/numerics` subpath. It exposes
|
|
5
|
+
* the package's fixture-validated numerical core — special functions cross-checked
|
|
6
|
+
* against scipy/mpmath to 1e-9..1e-15 relative error (see test/fixtures/special.json
|
|
7
|
+
* and scripts/fixtures/generate.py) — so sibling packages (e.g. @mindpeeker/psi,
|
|
8
|
+
* @mindpeeker/flow) can reuse it instead of duplicating delicate tail-accurate code.
|
|
9
|
+
*
|
|
10
|
+
* What lives here:
|
|
11
|
+
* - Special functions (internal/special.ts): $\ln\Gamma(x)$ via a Lanczos
|
|
12
|
+
* approximation (Godfrey $g=7$, $n=9$); the regularized incomplete gammas
|
|
13
|
+
* $P(a,x)=\gamma(a,x)/\Gamma(a)$ and $Q(a,x)=1-P(a,x)$ (series + Lentz continued
|
|
14
|
+
* fraction, per Numerical Recipes §6.2); $\mathrm{erfc}(x)=Q(\tfrac12,x^2)$;
|
|
15
|
+
* the standard normal CDF $\Phi(z)$, survival $1-\Phi(z)$, and quantile
|
|
16
|
+
* $\Phi^{-1}(p)$ (Wichura's AS 241 / PPND16); chi-square CDF/SF/quantile for
|
|
17
|
+
* df $k$ via $P(k/2, x/2)$, $Q(k/2, x/2)$, and a bracketed log-space Newton.
|
|
18
|
+
* - Compensated accumulation: KahanSum (Kahan 1965 compensated summation, $O(\varepsilon)$
|
|
19
|
+
* error on long sums) and Welford (Welford 1962 one-pass mean/variance).
|
|
20
|
+
* - Byte/bit utilities (internal/bytes.ts): toBits (MSB-first, the SDK-wide bit
|
|
21
|
+
* order), concatBytes, and the POPCOUNT per-byte one-bits table.
|
|
22
|
+
*
|
|
23
|
+
* Stability: this is a secondary entry point of @mindpeeker/negentropy and carries
|
|
24
|
+
* the same semver guarantees as the root export — additions are minor, removals or
|
|
25
|
+
* signature changes are major. Deterministic and browser-safe: no I/O, no `node:`
|
|
26
|
+
* builtins, same inputs always produce the same outputs.
|
|
27
|
+
*/
|
|
28
|
+
export { concatBytes, POPCOUNT, toBits } from './internal/bytes.js';
|
|
29
|
+
export { KahanSum } from './internal/kahan.js';
|
|
30
|
+
export { chi2Cdf, chi2Ppf, chi2Sf, erfc, gammaP, gammaQ, lnGamma, normCdf, normPpf, normSf, } from './internal/special.js';
|
|
31
|
+
export { Welford } from './internal/welford.js';
|
|
32
|
+
//# sourceMappingURL=numerics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numerics.js","sourceRoot":"","sources":["../src/numerics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,MAAM,GACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Calibration, TrialSeries } from '../types.js';
|
|
2
|
+
/** Binomial(k, ½) null: mean k/2, sd √(k/4). The default when a source is trusted unbiased. */
|
|
3
|
+
export declare function theoreticalCalibration(source: string, bitsPerTrial?: number): Calibration;
|
|
4
|
+
export interface CalibrateOptions {
|
|
5
|
+
/** Minimum trials the fit demands. Default 500 — a noisy sd biases every downstream χ². */
|
|
6
|
+
minTrials?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fit empirical mean/sd on a recorded resting-state series. The calibration
|
|
10
|
+
* window must be disjoint from any window later analyzed — normalizing data
|
|
11
|
+
* with parameters fit on itself deflates every statistic.
|
|
12
|
+
*/
|
|
13
|
+
export declare function calibrate(series: TrialSeries, opts?: CalibrateOptions): Calibration;
|
|
14
|
+
//# sourceMappingURL=calibration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calibration.d.ts","sourceRoot":"","sources":["../../src/stats/calibration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAG3D,+FAA+F;AAC/F,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,YAAY,GAAE,MAA+B,GAC5C,WAAW,CASb;AAED,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,GAAE,gBAAqB,GAAG,WAAW,CA2BvF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NegentropyError } from '../errors.js';
|
|
2
|
+
import { Welford } from '../internal/welford.js';
|
|
3
|
+
import { DEFAULT_BITS_PER_TRIAL } from './trials.js';
|
|
4
|
+
/** Binomial(k, ½) null: mean k/2, sd √(k/4). The default when a source is trusted unbiased. */
|
|
5
|
+
export function theoreticalCalibration(source, bitsPerTrial = DEFAULT_BITS_PER_TRIAL) {
|
|
6
|
+
return {
|
|
7
|
+
source,
|
|
8
|
+
bitsPerTrial,
|
|
9
|
+
trials: 0,
|
|
10
|
+
mean: bitsPerTrial / 2,
|
|
11
|
+
sd: Math.sqrt(bitsPerTrial / 4),
|
|
12
|
+
basis: 'theoretical',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Fit empirical mean/sd on a recorded resting-state series. The calibration
|
|
17
|
+
* window must be disjoint from any window later analyzed — normalizing data
|
|
18
|
+
* with parameters fit on itself deflates every statistic.
|
|
19
|
+
*/
|
|
20
|
+
export function calibrate(series, opts = {}) {
|
|
21
|
+
const minTrials = opts.minTrials ?? 500;
|
|
22
|
+
if (series.sums.length < minTrials) {
|
|
23
|
+
throw new NegentropyError('insufficient_data', `calibration needs ≥ ${minTrials} trials, got ${series.sums.length}`, { source: series.source });
|
|
24
|
+
}
|
|
25
|
+
const acc = new Welford();
|
|
26
|
+
for (const sum of series.sums)
|
|
27
|
+
acc.push(sum);
|
|
28
|
+
const sd = acc.sd;
|
|
29
|
+
if (!(sd > 0)) {
|
|
30
|
+
throw new NegentropyError('insufficient_data', 'calibration series is constant — the source produced no variation to normalize against', { source: series.source });
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
source: series.source,
|
|
34
|
+
bitsPerTrial: series.bitsPerTrial,
|
|
35
|
+
trials: acc.n,
|
|
36
|
+
mean: acc.mean,
|
|
37
|
+
sd,
|
|
38
|
+
basis: 'empirical',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=calibration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calibration.js","sourceRoot":"","sources":["../../src/stats/calibration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,+FAA+F;AAC/F,MAAM,UAAU,sBAAsB,CACpC,MAAc,EACd,eAAuB,sBAAsB;IAE7C,OAAO;QACL,MAAM;QACN,YAAY;QACZ,MAAM,EAAE,CAAC;QACT,IAAI,EAAE,YAAY,GAAG,CAAC;QACtB,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QAC/B,KAAK,EAAE,aAAa;KACrB,CAAA;AACH,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAmB,EAAE,OAAyB,EAAE;IACxE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,GAAG,CAAA;IACvC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,eAAe,CACvB,mBAAmB,EACnB,uBAAuB,SAAS,gBAAgB,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EACpE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAC1B,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,OAAO,EAAE,CAAA;IACzB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI;QAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC5C,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,CAAA;IACjB,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,eAAe,CACvB,mBAAmB,EACnB,wFAAwF,EACxF,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAC1B,CAAA;IACH,CAAC;IACD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,MAAM,EAAE,GAAG,CAAC,CAAC;QACb,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,EAAE;QACF,KAAK,EAAE,WAAW;KACnB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cumulative deviation series D(t) = Σ_{s≤t} (Z(s)² − 1) — the classic GCP
|
|
3
|
+
* plot. Flat under H0 (E[D] = 0, Var[D(t)] = 2t), drifting upward when
|
|
4
|
+
* structure is present.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cumulativeDeviation(stoufferZs: ArrayLike<number>): Float64Array;
|
|
7
|
+
/**
|
|
8
|
+
* Pointwise significance envelope for the cumulative-deviation plot: at step
|
|
9
|
+
* t (1-based) the curve χ²ppf(1 − p, t) − t. IMPORTANT: this is a POINTWISE
|
|
10
|
+
* p criterion. The probability that an H0 path crosses the envelope
|
|
11
|
+
* *somewhere* in [1, T] is much larger than p — only a pre-registered
|
|
12
|
+
* endpoint (or fixed time) carries the stated significance level.
|
|
13
|
+
*/
|
|
14
|
+
export declare function significanceEnvelope(steps: number, p?: number): Float64Array;
|
|
15
|
+
//# sourceMappingURL=cumdev.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cumdev.d.ts","sourceRoot":"","sources":["../../src/stats/cumdev.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,YAAY,CAS/E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,SAAO,GAAG,YAAY,CAU1E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NegentropyError } from '../errors.js';
|
|
2
|
+
import { KahanSum } from '../internal/kahan.js';
|
|
3
|
+
import { chi2Ppf } from '../internal/special.js';
|
|
4
|
+
/**
|
|
5
|
+
* Cumulative deviation series D(t) = Σ_{s≤t} (Z(s)² − 1) — the classic GCP
|
|
6
|
+
* plot. Flat under H0 (E[D] = 0, Var[D(t)] = 2t), drifting upward when
|
|
7
|
+
* structure is present.
|
|
8
|
+
*/
|
|
9
|
+
export function cumulativeDeviation(stoufferZs) {
|
|
10
|
+
const out = new Float64Array(stoufferZs.length);
|
|
11
|
+
const acc = new KahanSum();
|
|
12
|
+
for (let t = 0; t < stoufferZs.length; t++) {
|
|
13
|
+
const z = stoufferZs[t];
|
|
14
|
+
acc.add(z * z - 1);
|
|
15
|
+
out[t] = acc.value;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Pointwise significance envelope for the cumulative-deviation plot: at step
|
|
21
|
+
* t (1-based) the curve χ²ppf(1 − p, t) − t. IMPORTANT: this is a POINTWISE
|
|
22
|
+
* p criterion. The probability that an H0 path crosses the envelope
|
|
23
|
+
* *somewhere* in [1, T] is much larger than p — only a pre-registered
|
|
24
|
+
* endpoint (or fixed time) carries the stated significance level.
|
|
25
|
+
*/
|
|
26
|
+
export function significanceEnvelope(steps, p = 0.05) {
|
|
27
|
+
if (!Number.isInteger(steps) || steps < 1) {
|
|
28
|
+
throw new NegentropyError('invalid_config', `steps must be a positive integer, got ${steps}`);
|
|
29
|
+
}
|
|
30
|
+
if (!(p > 0 && p < 1)) {
|
|
31
|
+
throw new NegentropyError('invalid_config', `envelope p must be in (0, 1), got ${p}`);
|
|
32
|
+
}
|
|
33
|
+
const out = new Float64Array(steps);
|
|
34
|
+
for (let t = 1; t <= steps; t++)
|
|
35
|
+
out[t - 1] = chi2Ppf(1 - p, t) - t;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=cumdev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cumdev.js","sourceRoot":"","sources":["../../src/stats/cumdev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA6B;IAC/D,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/C,MAAM,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAW,CAAA;QACjC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QAClB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAA;IACpB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa,EAAE,CAAC,GAAG,IAAI;IAC1D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,eAAe,CAAC,gBAAgB,EAAE,yCAAyC,KAAK,EAAE,CAAC,CAAA;IAC/F,CAAC;IACD,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,eAAe,CAAC,gBAAgB,EAAE,qCAAqC,CAAC,EAAE,CAAC,CAAA;IACvF,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;IACnE,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { StatResult } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Network variance — the GCP standard event statistic: Σₜ Z_s(t)² where
|
|
4
|
+
* Z_s(t) is the per-step Stouffer Z across sources; ~ χ²(steps) under H0.
|
|
5
|
+
* Sensitive to a common signal shared across sources and to mean shifts.
|
|
6
|
+
*/
|
|
7
|
+
export declare function netvar(zBySource: readonly Float64Array[], sources: readonly string[]): StatResult;
|
|
8
|
+
/**
|
|
9
|
+
* Device variance: Σₜ Σᵢ zᵢ(t)² ~ χ²(steps × sources) under H0. Sensitive to
|
|
10
|
+
* individual sources changing variance; blind to cross-source correlation.
|
|
11
|
+
*/
|
|
12
|
+
export declare function devvar(zBySource: readonly Float64Array[], sources: readonly string[]): StatResult;
|
|
13
|
+
export interface PairCorrelation {
|
|
14
|
+
a: string;
|
|
15
|
+
b: string;
|
|
16
|
+
/** Mean per-step product of the pair's z-scores (≈ correlation, z's being standardized). */
|
|
17
|
+
r: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Inter-source correlation: per step S(t) = Σᵢ<ⱼ zᵢzⱼ = ((Σz)² − Σz²)/2;
|
|
21
|
+
* statistic = ΣₜS(t) / √(steps·N(N−1)/2), treated as N(0,1) by the CLT.
|
|
22
|
+
* Not valid for tiny steps×pairs — expect ≥ ~100 products before trusting
|
|
23
|
+
* the normal approximation. `df` reports that product count for context; the
|
|
24
|
+
* p-value comes from the normal tail (one-sided: excess correlation).
|
|
25
|
+
*/
|
|
26
|
+
export declare function interSourceCorrelation(zBySource: readonly Float64Array[], sources: readonly string[]): StatResult & {
|
|
27
|
+
pairs: readonly PairCorrelation[];
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/stats/network.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAgC7C;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAiBjG;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAkBjG;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,4FAA4F;IAC5F,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,YAAY,EAAE,EAClC,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,UAAU,GAAG;IAAE,KAAK,EAAE,SAAS,eAAe,EAAE,CAAA;CAAE,CAqCpD"}
|