@cloudglides/nox 1.1.3 → 1.1.5
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/example/package.json +1 -1
- package/example/pnpm-lock.yaml +1006 -0
- package/example/src/App.css +63 -55
- package/example/src/index.css +13 -19
- package/example/vite.config.js +1 -1
- package/package.json +13 -8
- package/src/generators/logistic.js +30 -18
- package/src/generators/mixer.js +43 -19
- package/src/generators/mt19937.js +5 -1
- package/src/generators/pcg64.js +11 -6
- package/src/generators/splitmix64.js +11 -6
- package/src/generators/tent.js +35 -23
- package/src/generators/xorshift64.js +11 -6
- package/src/index.d.ts +5 -5
- package/src/rng.browser.js +81 -75
- package/src/rng.js +79 -73
- package/src/utils/distributions.js +21 -19
- package/src/utils/sampling.js +64 -56
- package/src/utils/sequence.js +45 -36
- package/src/utils/statistics.js +61 -45
- package/example/package-lock.json +0 -1636
package/src/utils/statistics.js
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
1
|
export const chiSquareTest = (data, bins = 10) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
3
|
+
throw new Error('Data must be non-empty array');
|
|
4
|
+
}
|
|
5
|
+
if (bins <= 0 || !Number.isInteger(bins)) {
|
|
6
|
+
throw new Error('Bins must be positive integer');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const histogram = new Array(bins).fill(0);
|
|
10
|
+
for (const val of data) {
|
|
11
|
+
const idx = Math.floor(val * bins);
|
|
12
|
+
histogram[Math.min(idx, bins - 1)]++;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const expected = data.length / bins;
|
|
16
|
+
let chi2 = 0;
|
|
17
|
+
for (const count of histogram) {
|
|
18
|
+
chi2 += ((count - expected) ** 2) / expected;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return { chi2, expected, histogram };
|
|
22
|
+
};
|
|
16
23
|
|
|
17
24
|
export const entropy = (data, bins = 10) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
26
|
+
throw new Error('Data must be non-empty array');
|
|
27
|
+
}
|
|
28
|
+
if (bins <= 0) {
|
|
29
|
+
throw new Error('Bins must be positive');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const histogram = new Array(bins).fill(0);
|
|
33
|
+
for (const val of data) {
|
|
34
|
+
const idx = Math.floor(val * bins);
|
|
35
|
+
histogram[Math.min(idx, bins - 1)]++;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let ent = 0;
|
|
39
|
+
for (const count of histogram) {
|
|
40
|
+
if (count > 0) {
|
|
41
|
+
const pi = count / data.length;
|
|
42
|
+
ent -= pi * Math.log2(pi);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return ent;
|
|
46
|
+
};
|
|
34
47
|
|
|
35
48
|
export const autocorrelation = (data, lag) => {
|
|
36
49
|
if (lag < 0 || lag >= data.length) throw new Error('Lag out of range');
|
|
@@ -110,18 +123,21 @@ export const meanTest = (data, expectedMean = 0.5) => {
|
|
|
110
123
|
};
|
|
111
124
|
|
|
112
125
|
export const varianceTest = (data, expectedVariance = 1 / 12) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
127
|
+
throw new Error('Data must be non-empty array');
|
|
128
|
+
}
|
|
129
|
+
if (data.length < 2) {
|
|
130
|
+
throw new Error('Data must have at least 2 elements');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const mean = data.reduce((a, b) => a + b, 0) / data.length;
|
|
134
|
+
const sampleVariance = data.reduce((a, v) => a + (v - mean) ** 2, 0) / (data.length - 1);
|
|
135
|
+
const chi2 = (data.length - 1) * sampleVariance / expectedVariance;
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
variance: sampleVariance,
|
|
139
|
+
expectedVariance,
|
|
140
|
+
chi2Statistic: chi2,
|
|
141
|
+
degreesOfFreedom: data.length - 1
|
|
142
|
+
};
|
|
143
|
+
};
|