@cloudglides/nox 1.1.5 → 2.0.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/README.md +9 -9
- package/example/src/App.css +89 -84
- package/example/src/App.jsx +375 -151
- package/package.json +7 -6
- package/src/core.browser.js +10 -2
- package/src/core.js +32 -4
- package/src/generators/logistic.js +30 -25
- package/src/generators/mixer.js +7 -7
- package/src/generators/mt19937.js +10 -7
- package/src/generators/pcg64.js +23 -12
- package/src/generators/splitmix64.js +12 -6
- package/src/generators/tent.js +12 -7
- package/src/generators/xorshift64.js +6 -3
- package/src/index.d.ts +68 -4
- package/src/index.js +154 -2
- package/src/rng.browser.js +21 -10
- package/src/rng.js +95 -82
- package/src/utils/arrays.js +149 -0
- package/src/utils/bits.js +146 -21
- package/src/utils/categorical.js +68 -31
- package/src/utils/combinatorics.js +113 -69
- package/src/utils/confidence.js +145 -0
- package/src/utils/decomposition.js +204 -0
- package/src/utils/distributions-advanced.js +122 -0
- package/src/utils/distributions-extra.js +102 -11
- package/src/utils/distributions-special.js +77 -20
- package/src/utils/distributions.js +99 -35
- package/src/utils/effects.js +172 -0
- package/src/utils/entropy.browser.js +29 -26
- package/src/utils/entropy.js +18 -8
- package/src/utils/helpers.js +64 -0
- package/src/utils/hypothesis.js +167 -0
- package/src/utils/integration.js +137 -0
- package/src/utils/interpolation.js +221 -0
- package/src/utils/matrix.js +242 -0
- package/src/utils/noise.js +36 -22
- package/src/utils/odesolvers.js +176 -0
- package/src/utils/optimization.js +215 -0
- package/src/utils/precomputed.js +166 -0
- package/src/utils/probability.js +199 -0
- package/src/utils/regression.js +170 -0
- package/src/utils/resampling.js +112 -0
- package/src/utils/rootfinding.js +158 -0
- package/src/utils/sampling.js +86 -77
- package/src/utils/seed.js +10 -4
- package/src/utils/seeding.js +24 -12
- package/src/utils/sequence.js +116 -32
- package/src/utils/state.js +48 -36
- package/src/utils/statistics.js +64 -2
- package/src/utils/stochastic.js +91 -31
- package/src/utils/stratified.js +108 -0
- package/src/utils/timeseries.js +166 -0
- package/src/utils/transforms.js +146 -0
- package/test/comprehensive-new.js +126 -0
- package/test/comprehensive.js +4 -3
- package/test/error-handling.js +49 -0
- package/test/new-features.js +52 -0
- package/IMPROVEMENTS.md +0 -58
package/example/src/App.jsx
CHANGED
|
@@ -1,175 +1,399 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
rng, deterministic, normal, exponential, poisson, uniform,
|
|
4
|
+
shuffle, sample, pick, weightedPick,
|
|
5
|
+
meanTest, varianceTest, kolmogorovSmirnovTest,
|
|
6
|
+
cohensD, correlation, cramersV,
|
|
7
|
+
bootstrapCI, meanCI,
|
|
8
|
+
tTest, welchTTest, oneWayAnova,
|
|
9
|
+
LinearRegression, MultipleRegression,
|
|
10
|
+
diff, lag, sma, ema, acf,
|
|
11
|
+
matrixAdd, matrixMul, determinant, inverse,
|
|
12
|
+
trapezoidal, simpsons, numericalDerivative,
|
|
13
|
+
LinearInterpolator, CubicSplineInterpolator,
|
|
14
|
+
bisection, newtonRaphson, brent,
|
|
15
|
+
rk4,
|
|
16
|
+
svd, qr, cholesky,
|
|
17
|
+
zscore, standardize, minMaxScale,
|
|
18
|
+
sum, mean, min, max, unique,
|
|
19
|
+
dirichlet, mixture,
|
|
20
|
+
gradientDescent, adam
|
|
21
|
+
} from '@cloudglides/nox'
|
|
3
22
|
import './App.css'
|
|
4
23
|
|
|
24
|
+
const FORMAT = (n) => typeof n === 'number' ? n.toFixed(4) : n
|
|
25
|
+
|
|
5
26
|
export default function App() {
|
|
6
|
-
const [
|
|
7
|
-
const [results, setResults] = useState({})
|
|
8
|
-
|
|
9
|
-
const runBasic = () => {
|
|
10
|
-
const r = rng()
|
|
11
|
-
setResults({
|
|
12
|
-
float: r.nextFloat().toFixed(6),
|
|
13
|
-
int: r.int(1, 100),
|
|
14
|
-
bool: r.bool(0.5),
|
|
15
|
-
range: r.range(10, 20, 2),
|
|
16
|
-
choice: r.choice(['apple', 'banana', 'cherry'])
|
|
17
|
-
})
|
|
18
|
-
}
|
|
27
|
+
const [results, setResults] = useState(null)
|
|
19
28
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const handlers = {
|
|
30
|
+
basics: () => {
|
|
31
|
+
const r = rng()
|
|
32
|
+
setResults({
|
|
33
|
+
title: 'Basic Operations',
|
|
34
|
+
data: [
|
|
35
|
+
['nextFloat', FORMAT(r.nextFloat())],
|
|
36
|
+
['int(1-100)', r.int(1, 100)],
|
|
37
|
+
['bool(0.5)', r.bool(0.5) ? 'true' : 'false'],
|
|
38
|
+
['choice', r.choice(['A', 'B', 'C', 'D'])],
|
|
39
|
+
['range(1-10, step 2)', r.range(1, 10, 2).join(', ')]
|
|
40
|
+
]
|
|
41
|
+
})
|
|
42
|
+
},
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
distributions: () => {
|
|
45
|
+
const r = rng()
|
|
46
|
+
const normals = Array.from({length: 5}, () => FORMAT(normal(r)))
|
|
47
|
+
const exponentials = Array.from({length: 5}, () => FORMAT(exponential(r)))
|
|
48
|
+
const dir = dirichlet(r, [1, 2, 3]).map(FORMAT)
|
|
49
|
+
setResults({
|
|
50
|
+
title: 'Distributions',
|
|
51
|
+
data: [
|
|
52
|
+
['normal(5)', normals.join(', ')],
|
|
53
|
+
['exponential(5)', exponentials.join(', ')],
|
|
54
|
+
['poisson(λ=3)', [poisson(r, 3), poisson(r, 3), poisson(r, 3)].join(', ')],
|
|
55
|
+
['dirichlet[1,2,3]', dir.join(', ')]
|
|
56
|
+
]
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
sampling: () => {
|
|
61
|
+
const r = rng()
|
|
62
|
+
const arr = [1, 2, 3, 4, 5]
|
|
63
|
+
const weights = [0.1, 0.2, 0.3, 0.2, 0.2]
|
|
64
|
+
setResults({
|
|
65
|
+
title: 'Sampling Methods',
|
|
66
|
+
data: [
|
|
67
|
+
['shuffle', shuffle(arr, r).join(', ')],
|
|
68
|
+
['sample(3)', sample(arr, 3, r).join(', ')],
|
|
69
|
+
['pick', pick(arr, r)],
|
|
70
|
+
['weightedPick', weightedPick(arr, weights, r)],
|
|
71
|
+
['unique', unique([1, 2, 2, 3, 3, 3]).join(', ')]
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
statistics: () => {
|
|
77
|
+
const r = rng()
|
|
78
|
+
const data = r.floats(100).map(x => x * 10)
|
|
79
|
+
const mean_val = mean(data)
|
|
80
|
+
const std = Math.sqrt(data.reduce((s, x) => s + (x - mean_val) ** 2, 0) / data.length)
|
|
81
|
+
|
|
82
|
+
const data2 = r.floats(50).map(x => x * 8)
|
|
83
|
+
const d = cohensD(data, data2)
|
|
84
|
+
const corr = correlation(data.slice(0, 50), data2.slice(0, 50))
|
|
85
|
+
|
|
86
|
+
setResults({
|
|
87
|
+
title: 'Statistics & Effect Sizes',
|
|
88
|
+
data: [
|
|
89
|
+
['mean', FORMAT(mean_val)],
|
|
90
|
+
['min', FORMAT(min(data))],
|
|
91
|
+
['max', FORMAT(max(data))],
|
|
92
|
+
["Cohen's d", FORMAT(d)],
|
|
93
|
+
['correlation', FORMAT(corr)],
|
|
94
|
+
['KS-test', FORMAT(kolmogorovSmirnovTest(data.map(x => x / 10)))]
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
hypothesis: () => {
|
|
100
|
+
const r = rng()
|
|
101
|
+
const group1 = r.floats(30).map(x => 5 + x * 2)
|
|
102
|
+
const group2 = r.floats(30).map(x => 5.5 + x * 2)
|
|
103
|
+
|
|
104
|
+
const t_result = tTest(group1, group2)
|
|
105
|
+
const w_result = welchTTest(group1, group2)
|
|
106
|
+
|
|
107
|
+
const groups = [group1, group2]
|
|
108
|
+
const anova = oneWayAnova(groups)
|
|
109
|
+
|
|
110
|
+
setResults({
|
|
111
|
+
title: 'Hypothesis Testing',
|
|
112
|
+
data: [
|
|
113
|
+
['t-test (t, df)', `${FORMAT(t_result.t)}, ${t_result.df}`],
|
|
114
|
+
["Welch's t-test", FORMAT(w_result.t)],
|
|
115
|
+
['ANOVA (F, df)', `${FORMAT(anova.f)}, ${anova.dfB}/${anova.dfW}`],
|
|
116
|
+
['meanCI(group1)', `[${FORMAT(meanCI(group1, 1).lower)}, ${FORMAT(meanCI(group1, 1).upper)}]`]
|
|
117
|
+
]
|
|
118
|
+
})
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
regression: () => {
|
|
122
|
+
const x = [1, 2, 3, 4, 5]
|
|
123
|
+
const y = [2.1, 3.9, 6.2, 7.8, 10.1]
|
|
124
|
+
|
|
125
|
+
const model = new LinearRegression(x, y)
|
|
126
|
+
|
|
127
|
+
const xMulti = [[1, 2], [2, 3], [3, 4], [4, 5]]
|
|
128
|
+
const yMulti = [2, 5, 9, 13]
|
|
129
|
+
const modelMulti = new MultipleRegression(xMulti, yMulti)
|
|
130
|
+
|
|
131
|
+
setResults({
|
|
132
|
+
title: 'Regression Models',
|
|
133
|
+
data: [
|
|
134
|
+
['Linear: slope', FORMAT(model.slope)],
|
|
135
|
+
['Linear: intercept', FORMAT(model.intercept)],
|
|
136
|
+
['Linear: R²', FORMAT(model.rSquared)],
|
|
137
|
+
['Linear: RMSE', FORMAT(model.rmse)],
|
|
138
|
+
['Multiple R²', FORMAT(modelMulti.rSquared)],
|
|
139
|
+
['Multiple adj-R²', FORMAT(modelMulti.adjRSquared)]
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
timeseries: () => {
|
|
145
|
+
const r = rng()
|
|
146
|
+
const ts = Array.from({length: 20}, (_, i) => 10 + i * 0.5 + (r.nextFloat() - 0.5) * 2)
|
|
147
|
+
|
|
148
|
+
const diffed = diff(ts, 1)
|
|
149
|
+
const lagged = lag(ts, 2).slice(2)
|
|
150
|
+
const sma_vals = sma(ts, 3).filter(x => x !== null)
|
|
151
|
+
const ema_vals = ema(ts, 3)
|
|
152
|
+
const acf_vals = acf(ts, 5)
|
|
153
|
+
|
|
154
|
+
setResults({
|
|
155
|
+
title: 'Time Series Analysis',
|
|
156
|
+
data: [
|
|
157
|
+
['original (first 5)', ts.slice(0, 5).map(FORMAT).join(', ')],
|
|
158
|
+
['diff(order=1)', diffed.slice(0, 5).map(FORMAT).join(', ')],
|
|
159
|
+
['SMA(window=3)', sma_vals.slice(0, 5).map(FORMAT).join(', ')],
|
|
160
|
+
['EMA(window=3)', ema_vals.slice(0, 5).map(FORMAT).join(', ')],
|
|
161
|
+
['ACF (lag 0-2)', acf_vals.slice(0, 3).map(FORMAT).join(', ')]
|
|
162
|
+
]
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
matrix: () => {
|
|
167
|
+
const A = [[1, 2], [3, 4]]
|
|
168
|
+
const B = [[5, 6], [7, 8]]
|
|
169
|
+
|
|
170
|
+
const sum = matrixAdd(A, B)
|
|
171
|
+
const prod = matrixMul(A, B)
|
|
172
|
+
const det = determinant(A)
|
|
173
|
+
const inv = inverse(A)
|
|
174
|
+
|
|
175
|
+
setResults({
|
|
176
|
+
title: 'Matrix Operations',
|
|
177
|
+
data: [
|
|
178
|
+
['A+B[0][0]', FORMAT(sum[0][0])],
|
|
179
|
+
['A*B[0][0]', FORMAT(prod[0][0])],
|
|
180
|
+
['det(A)', FORMAT(det)],
|
|
181
|
+
['inv(A)[0][1]', FORMAT(inv[0][1])],
|
|
182
|
+
['trace(A)', FORMAT(1 + 4)]
|
|
183
|
+
]
|
|
184
|
+
})
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
decomposition: () => {
|
|
188
|
+
const A = [[1, 2], [3, 4]]
|
|
189
|
+
|
|
190
|
+
const {U, S, VT} = svd(A, 10)
|
|
191
|
+
const {Q, R} = qr(A)
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
const L = cholesky([[4, 2], [2, 3]])
|
|
195
|
+
setResults({
|
|
196
|
+
title: 'Matrix Decompositions',
|
|
197
|
+
data: [
|
|
198
|
+
['SVD S[0]', FORMAT(S[0])],
|
|
199
|
+
['SVD S[1]', FORMAT(S[1])],
|
|
200
|
+
['QR R[0][0]', FORMAT(R[0][0])],
|
|
201
|
+
['QR R[0][1]', FORMAT(R[0][1])],
|
|
202
|
+
['Cholesky L[0][0]', FORMAT(L[0][0])],
|
|
203
|
+
['Cholesky L[1][0]', FORMAT(L[1][0])]
|
|
204
|
+
]
|
|
205
|
+
})
|
|
206
|
+
} catch {
|
|
207
|
+
setResults({
|
|
208
|
+
title: 'Matrix Decompositions',
|
|
209
|
+
data: [
|
|
210
|
+
['SVD S[0]', FORMAT(S[0])],
|
|
211
|
+
['QR R[0][0]', FORMAT(R[0][0])],
|
|
212
|
+
['Cholesky', 'Not positive definite']
|
|
213
|
+
]
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
integration: () => {
|
|
219
|
+
const f = (x) => Math.sin(x)
|
|
220
|
+
const a = 0, b = Math.PI
|
|
221
|
+
|
|
222
|
+
const trap = trapezoidal(f, a, b, 100)
|
|
223
|
+
const simp = simpsons(f, a, b, 100)
|
|
224
|
+
const deriv1 = numericalDerivative(f, 1)
|
|
225
|
+
const deriv2 = numericalDerivative(Math.cos, 0)
|
|
226
|
+
|
|
227
|
+
setResults({
|
|
228
|
+
title: 'Numerical Integration & Derivatives',
|
|
229
|
+
data: [
|
|
230
|
+
['∫sin(x) [0,π] exact', '2.0000'],
|
|
231
|
+
['∫sin(x) trapezoidal', FORMAT(trap)],
|
|
232
|
+
['∫sin(x) Simpson', FORMAT(simp)],
|
|
233
|
+
['d/dx sin(x) at x=1', FORMAT(deriv1)],
|
|
234
|
+
['d/dx cos(x) at x=0', FORMAT(deriv2)]
|
|
235
|
+
]
|
|
236
|
+
})
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
interpolation: () => {
|
|
240
|
+
const x = [0, 1, 2, 3, 4]
|
|
241
|
+
const y = [0, 1, 4, 9, 16]
|
|
242
|
+
|
|
243
|
+
const linear = new LinearInterpolator(x, y)
|
|
244
|
+
const cubic = new CubicSplineInterpolator(x, y)
|
|
245
|
+
|
|
246
|
+
const x_interp = 1.5
|
|
247
|
+
const y_linear = linear.evaluate(x_interp)
|
|
248
|
+
const y_cubic = cubic.evaluate(x_interp)
|
|
249
|
+
|
|
250
|
+
setResults({
|
|
251
|
+
title: 'Interpolation',
|
|
252
|
+
data: [
|
|
253
|
+
['x points', x.join(', ')],
|
|
254
|
+
['y points', y.join(', ')],
|
|
255
|
+
[`Linear at x=${x_interp}`, FORMAT(y_linear)],
|
|
256
|
+
[`Cubic spline at x=${x_interp}`, FORMAT(y_cubic)],
|
|
257
|
+
['Expected (x²) at 1.5', FORMAT(1.5 * 1.5)]
|
|
258
|
+
]
|
|
259
|
+
})
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
rootfinding: () => {
|
|
263
|
+
const f = (x) => x ** 2 - 4
|
|
264
|
+
const df = (x) => 2 * x
|
|
265
|
+
|
|
266
|
+
const bisect = bisection(f, 1, 3, 1e-6)
|
|
267
|
+
const newton = newtonRaphson(f, df, 3, 1e-6)
|
|
268
|
+
const brentResult = brent(f, 1, 3, 1e-6)
|
|
269
|
+
|
|
270
|
+
setResults({
|
|
271
|
+
title: 'Root Finding Methods',
|
|
272
|
+
data: [
|
|
273
|
+
['f(x) = x² - 4, root is x=2'],
|
|
274
|
+
['bisection: root', FORMAT(bisect.root)],
|
|
275
|
+
['bisection: iterations', bisect.iterations],
|
|
276
|
+
['Newton-Raphson: root', FORMAT(newton.root)],
|
|
277
|
+
['Newton-Raphson: iterations', newton.iterations],
|
|
278
|
+
['Brent: root', FORMAT(brentResult.root)],
|
|
279
|
+
['Brent: iterations', brentResult.iterations]
|
|
280
|
+
]
|
|
281
|
+
})
|
|
282
|
+
},
|
|
37
283
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
284
|
+
ode: () => {
|
|
285
|
+
const dydt = (t, y) => -y
|
|
286
|
+
const y0 = 1
|
|
287
|
+
const result = rk4(dydt, y0, 0, 2, 0.1)
|
|
288
|
+
|
|
289
|
+
const analytical = Math.exp(-2)
|
|
290
|
+
|
|
291
|
+
setResults({
|
|
292
|
+
title: 'ODE Solver (dy/dt = -y, y(0)=1)',
|
|
293
|
+
data: [
|
|
294
|
+
['Solver method', 'RK4 (4th order)'],
|
|
295
|
+
['Time steps', result.t.length],
|
|
296
|
+
['t values', result.t.slice(0, 5).map(FORMAT).join(', ')],
|
|
297
|
+
['y values', result.y.slice(0, 5).map(FORMAT).join(', ')],
|
|
298
|
+
['y(2) numerical', FORMAT(result.y[result.y.length - 1])],
|
|
299
|
+
['y(2) analytical', FORMAT(analytical)]
|
|
300
|
+
]
|
|
301
|
+
})
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
transforms: () => {
|
|
305
|
+
const r = rng()
|
|
306
|
+
const data = r.floats(20).map(x => x * 10 + 5)
|
|
307
|
+
|
|
308
|
+
const z = zscore(data)
|
|
309
|
+
const std = standardize(data)
|
|
310
|
+
const scaled = minMaxScale(data)
|
|
311
|
+
|
|
312
|
+
setResults({
|
|
313
|
+
title: 'Data Transformations',
|
|
314
|
+
data: [
|
|
315
|
+
['original: mean', FORMAT(mean(data))],
|
|
316
|
+
['original: min', FORMAT(min(data))],
|
|
317
|
+
['original: max', FORMAT(max(data))],
|
|
318
|
+
['z-score: mean', FORMAT(mean(z).toFixed(10))],
|
|
319
|
+
['z-score: std', FORMAT(Math.sqrt(z.reduce((s, x) => s + x * x, 0) / z.length))],
|
|
320
|
+
['minmax: min', FORMAT(min(scaled))],
|
|
321
|
+
['minmax: max', FORMAT(max(scaled))]
|
|
322
|
+
]
|
|
323
|
+
})
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
optimization: () => {
|
|
327
|
+
const f = (x) => (x - 3) ** 2 + 2
|
|
328
|
+
const df = (x) => 2 * (x - 3)
|
|
329
|
+
|
|
330
|
+
const gd = gradientDescent(f, df, 0, 0.1, 100, 1e-6)
|
|
331
|
+
const adamResult = adam(f, df, 0, 0.1, 100, 0.9, 0.999, 1e-8, 1e-6)
|
|
332
|
+
|
|
333
|
+
setResults({
|
|
334
|
+
title: 'Optimization Methods',
|
|
335
|
+
data: [
|
|
336
|
+
['Minimize: f(x) = (x-3)² + 2, min at x=3'],
|
|
337
|
+
['Gradient Descent x', FORMAT(gd.x)],
|
|
338
|
+
['Gradient Descent iterations', gd.iterations],
|
|
339
|
+
['Gradient Descent value', FORMAT(gd.value)],
|
|
340
|
+
['Adam x', FORMAT(adamResult.x)],
|
|
341
|
+
['Adam iterations', adamResult.iterations],
|
|
342
|
+
['Adam value', FORMAT(adamResult.value)]
|
|
343
|
+
]
|
|
344
|
+
})
|
|
345
|
+
}
|
|
49
346
|
}
|
|
50
347
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
seq2: seq2.map(x => x.toFixed(4)).join(', '),
|
|
59
|
-
identical: JSON.stringify(seq1) === JSON.stringify(seq2) ? 'YES' : 'NO'
|
|
60
|
-
})
|
|
348
|
+
const categoryGroups = {
|
|
349
|
+
'Core': ['basics', 'distributions', 'sampling'],
|
|
350
|
+
'Statistics': ['statistics', 'hypothesis'],
|
|
351
|
+
'Modeling': ['regression', 'timeseries'],
|
|
352
|
+
'Numerics': ['integration', 'interpolation', 'rootfinding', 'ode'],
|
|
353
|
+
'Linear Algebra': ['matrix', 'decomposition'],
|
|
354
|
+
'Advanced': ['optimization', 'transforms']
|
|
61
355
|
}
|
|
62
356
|
|
|
63
357
|
return (
|
|
64
358
|
<div className="app">
|
|
65
359
|
<header>
|
|
66
|
-
<h1>nox
|
|
67
|
-
<p>
|
|
360
|
+
<h1>nox</h1>
|
|
361
|
+
<p>Comprehensive RNG and Numerical Computing Library</p>
|
|
68
362
|
</header>
|
|
69
363
|
|
|
70
|
-
<div className="tabs">
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
<button className={tab === 'stats' ? 'active' : ''} onClick={() => setTab('stats')}>
|
|
81
|
-
Statistics
|
|
82
|
-
</button>
|
|
83
|
-
<button className={tab === 'deterministic' ? 'active' : ''} onClick={() => setTab('deterministic')}>
|
|
84
|
-
Deterministic
|
|
85
|
-
</button>
|
|
86
|
-
</div>
|
|
87
|
-
|
|
88
|
-
<div className="content">
|
|
89
|
-
{tab === 'basic' && (
|
|
90
|
-
<div className="section">
|
|
91
|
-
<h2>Basic RNG Operations</h2>
|
|
92
|
-
<button onClick={runBasic} className="action-btn">Run</button>
|
|
93
|
-
<div className="results">
|
|
94
|
-
{results.float && (
|
|
95
|
-
<div>
|
|
96
|
-
<p><strong>nextFloat():</strong> {results.float}</p>
|
|
97
|
-
<p><strong>int(1, 100):</strong> {results.int}</p>
|
|
98
|
-
<p><strong>bool(0.5):</strong> {results.bool ? 'true' : 'false'}</p>
|
|
99
|
-
<p><strong>range(10, 20, 2):</strong> {results.range}</p>
|
|
100
|
-
<p><strong>choice():</strong> {results.choice}</p>
|
|
101
|
-
</div>
|
|
102
|
-
)}
|
|
103
|
-
</div>
|
|
104
|
-
</div>
|
|
105
|
-
)}
|
|
106
|
-
|
|
107
|
-
{tab === 'batch' && (
|
|
108
|
-
<div className="section">
|
|
109
|
-
<h2>Batch Operations</h2>
|
|
110
|
-
<button onClick={runBatch} className="action-btn">Run</button>
|
|
111
|
-
<div className="results">
|
|
112
|
-
{results.floats && (
|
|
113
|
-
<div>
|
|
114
|
-
<p><strong>floats(5):</strong> [{results.floats}]</p>
|
|
115
|
-
<p><strong>ints(5, 100):</strong> [{results.ints}]</p>
|
|
116
|
-
<p><strong>bools(5):</strong> [{results.bools}]</p>
|
|
117
|
-
</div>
|
|
118
|
-
)}
|
|
119
|
-
</div>
|
|
120
|
-
</div>
|
|
121
|
-
)}
|
|
122
|
-
|
|
123
|
-
{tab === 'distributions' && (
|
|
124
|
-
<div className="section">
|
|
125
|
-
<h2>Statistical Distributions</h2>
|
|
126
|
-
<button onClick={runDistributions} className="action-btn">Run</button>
|
|
127
|
-
<div className="results">
|
|
128
|
-
{results.normal && (
|
|
129
|
-
<div>
|
|
130
|
-
<p><strong>Normal(0, 1):</strong> [{results.normal}]</p>
|
|
131
|
-
<p><strong>Exponential(1):</strong> [{results.exponential}]</p>
|
|
132
|
-
</div>
|
|
133
|
-
)}
|
|
134
|
-
</div>
|
|
135
|
-
</div>
|
|
136
|
-
)}
|
|
137
|
-
|
|
138
|
-
{tab === 'stats' && (
|
|
139
|
-
<div className="section">
|
|
140
|
-
<h2>Statistical Tests</h2>
|
|
141
|
-
<button onClick={runStats} className="action-btn">Run on 1000 samples</button>
|
|
142
|
-
<div className="results">
|
|
143
|
-
{results.mean && (
|
|
144
|
-
<div>
|
|
145
|
-
<p><strong>Mean (expected 0.5):</strong> {results.mean}</p>
|
|
146
|
-
<p><strong>Variance (expected 0.083333):</strong> {results.variance}</p>
|
|
147
|
-
<p><strong>KS Test (α=0.05):</strong> {results.ksPass}</p>
|
|
148
|
-
</div>
|
|
149
|
-
)}
|
|
364
|
+
<div className="tabs-container">
|
|
365
|
+
{Object.entries(categoryGroups).map(([category, items]) => (
|
|
366
|
+
<div key={category} className="category">
|
|
367
|
+
<h3>{category}</h3>
|
|
368
|
+
<div className="tabs">
|
|
369
|
+
{items.map(key => (
|
|
370
|
+
<button key={key} onClick={handlers[key]}>
|
|
371
|
+
{key.charAt(0).toUpperCase() + key.slice(1).replace(/([A-Z])/g, ' $1')}
|
|
372
|
+
</button>
|
|
373
|
+
))}
|
|
150
374
|
</div>
|
|
151
375
|
</div>
|
|
152
|
-
)}
|
|
153
|
-
|
|
154
|
-
{tab === 'deterministic' && (
|
|
155
|
-
<div className="section">
|
|
156
|
-
<h2>Deterministic Mode</h2>
|
|
157
|
-
<button onClick={runDeterministic} className="action-btn">Run with seed=42</button>
|
|
158
|
-
<div className="results">
|
|
159
|
-
{results.seq1 && (
|
|
160
|
-
<div>
|
|
161
|
-
<p><strong>Sequence 1:</strong> [{results.seq1}]</p>
|
|
162
|
-
<p><strong>Sequence 2:</strong> [{results.seq2}]</p>
|
|
163
|
-
<p><strong>Identical:</strong> {results.identical}</p>
|
|
164
|
-
</div>
|
|
165
|
-
)}
|
|
166
|
-
</div>
|
|
167
|
-
</div>
|
|
168
|
-
)}
|
|
376
|
+
))}
|
|
169
377
|
</div>
|
|
170
378
|
|
|
379
|
+
{results && (
|
|
380
|
+
<div className="content">
|
|
381
|
+
<h2>{results.title}</h2>
|
|
382
|
+
<div className="results">
|
|
383
|
+
{results.data.map(([label, value], i) => (
|
|
384
|
+
<div key={i} className="result-row">
|
|
385
|
+
<span className="label">{label}:</span>
|
|
386
|
+
<span className="value">{value}</span>
|
|
387
|
+
</div>
|
|
388
|
+
))}
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
)}
|
|
392
|
+
|
|
171
393
|
<footer>
|
|
172
|
-
<
|
|
394
|
+
<a href="https://github.com/cloudglides/nox" target="_blank" rel="noreferrer">GitHub</a>
|
|
395
|
+
<span>·</span>
|
|
396
|
+
<a href="https://npmjs.com/package/@cloudglides/nox" target="_blank" rel="noreferrer">npm</a>
|
|
173
397
|
</footer>
|
|
174
398
|
</div>
|
|
175
399
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudglides/nox",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Unpredictable random number generator with multiple algorithms and distributions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"default": "./src/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "node test/basic.js",
|
|
17
|
+
"bench": "node test/benchmark.js"
|
|
18
|
+
},
|
|
15
19
|
"keywords": [
|
|
16
20
|
"random",
|
|
17
21
|
"rng",
|
|
@@ -21,11 +25,8 @@
|
|
|
21
25
|
],
|
|
22
26
|
"author": "",
|
|
23
27
|
"license": "ISC",
|
|
28
|
+
"packageManager": "pnpm@10.24.0",
|
|
24
29
|
"publishConfig": {
|
|
25
30
|
"access": "public"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"test": "node test/basic.js",
|
|
29
|
-
"bench": "node test/benchmark.js"
|
|
30
31
|
}
|
|
31
|
-
}
|
|
32
|
+
}
|
package/src/core.browser.js
CHANGED
|
@@ -2,9 +2,17 @@ export { rng, RNG } from './rng.browser.js';
|
|
|
2
2
|
export { deterministic } from './presets.browser.js';
|
|
3
3
|
|
|
4
4
|
export { normal, exponential, uniform, poisson } from './utils/distributions.js';
|
|
5
|
+
export { beta, gamma, chi2 } from './utils/distributions-extra.js';
|
|
6
|
+
export { weibull, lognormal, rayleigh, cauchy } from './utils/distributions-special.js';
|
|
5
7
|
export { shuffle, pick, sample } from './utils/sequence.js';
|
|
6
8
|
export { saveState, restoreState, cloneGenerator } from './utils/state.js';
|
|
7
9
|
export { weightedPick, weightedSample, reservoirSample } from './utils/sampling.js';
|
|
8
|
-
export { meanTest, varianceTest, kolmogorovSmirnovTest } from './utils/statistics.js';
|
|
9
|
-
|
|
10
|
+
export { meanTest, varianceTest, kolmogorovSmirnovTest, chiSquareTest, entropy, autocorrelation, runTest } from './utils/statistics.js';
|
|
10
11
|
export { combined, clearCryptoCache } from './utils/entropy.browser.js';
|
|
12
|
+
export { brownianMotion, ornsteinUhlenbeck, geometricBrownian } from './utils/stochastic.js';
|
|
13
|
+
export { categorical, multinomial, categorical2D } from './utils/categorical.js';
|
|
14
|
+
export { perlin2D, valueNoise } from './utils/noise.js';
|
|
15
|
+
export { combinations, permutations, kPermutations, randomCombination, randomPermutation } from './utils/combinatorics.js';
|
|
16
|
+
export { rotateBits, extractBits, hammingWeight, bitRange } from './utils/bits.js';
|
|
17
|
+
export { SeedSequence, seedMultiple } from './utils/seeding.js';
|
|
18
|
+
export { seedFromTime, seedFromEntropy } from './utils/seed.js';
|
package/src/core.js
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
export { rng, RNG } from './rng.js';
|
|
2
2
|
export { deterministic } from './presets.js';
|
|
3
3
|
|
|
4
|
-
export { normal, exponential, uniform, poisson } from './utils/distributions.js';
|
|
5
|
-
export {
|
|
4
|
+
export { normal, exponential, uniform, poisson, normals, exponentials } from './utils/distributions.js';
|
|
5
|
+
export { beta, gamma, chi2, binomial, geometric } from './utils/distributions-extra.js';
|
|
6
|
+
export { weibull, lognormal, rayleigh, cauchy } from './utils/distributions-special.js';
|
|
7
|
+
export { dirichlet, dirichlets, mixture, mixtures, studentT, studentTs, betaBinomial } from './utils/distributions-advanced.js';
|
|
8
|
+
export { shuffle, pick, sample, sampleWithReplacement, permute, range, cycle } from './utils/sequence.js';
|
|
6
9
|
export { saveState, restoreState, cloneGenerator } from './utils/state.js';
|
|
7
10
|
export { weightedPick, weightedSample, reservoirSample } from './utils/sampling.js';
|
|
8
|
-
export { meanTest, varianceTest, kolmogorovSmirnovTest } from './utils/statistics.js';
|
|
9
|
-
|
|
11
|
+
export { meanTest, varianceTest, kolmogorovSmirnovTest, chiSquareTest, entropy, autocorrelation, runTest, skewness, kurtosis, median, quantile } from './utils/statistics.js';
|
|
10
12
|
export { combined, clearCryptoCache } from './utils/entropy.js';
|
|
13
|
+
export { brownianMotion, ornsteinUhlenbeck, geometricBrownian } from './utils/stochastic.js';
|
|
14
|
+
export { categorical, multinomial, categorical2D } from './utils/categorical.js';
|
|
15
|
+
export { perlin2D, valueNoise } from './utils/noise.js';
|
|
16
|
+
export { combinations, permutations, kPermutations, randomCombination, randomPermutation } from './utils/combinatorics.js';
|
|
17
|
+
export { rotateBits, extractBits, hammingWeight, bitRange, popcountNum, clz, ctz, reverseBits, setBit, clearBit, toggleBit } from './utils/bits.js';
|
|
18
|
+
export { SeedSequence, seedMultiple } from './utils/seeding.js';
|
|
19
|
+
export { seedFromTime, seedFromEntropy } from './utils/seed.js';
|
|
20
|
+
export { repeat, until, times } from './utils/helpers.js';
|
|
21
|
+
export { bootstrap, jackknife, crossValidation, permutationTest } from './utils/resampling.js';
|
|
22
|
+
export { stratifiedSample, stratifiedSampleProportional, stratify } from './utils/stratified.js';
|
|
23
|
+
export { cdf, ppf, sf } from './utils/probability.js';
|
|
24
|
+
export { WeightedDistribution, CategoricalDistribution, NormalDistribution } from './utils/precomputed.js';
|
|
25
|
+
export { bootstrapCI, meanCI, proportionCI } from './utils/confidence.js';
|
|
26
|
+
export { cohensD, hedgesG, correlation, cramersV, etaSquared, glasssDelta } from './utils/effects.js';
|
|
27
|
+
export { sum, mean, min, max, unique, chunk, flatten, zip, transpose, partition } from './utils/arrays.js';
|
|
28
|
+
export { tTest, welchTTest, mannWhitneyU, oneWayAnova } from './utils/hypothesis.js';
|
|
29
|
+
export { zscore, standardize, minMaxScale, logTransform, sqrtTransform, rank, robustScale } from './utils/transforms.js';
|
|
30
|
+
export { LinearRegression, MultipleRegression } from './utils/regression.js';
|
|
31
|
+
export { diff, lag, shift, sma, ema, acf, pacf } from './utils/timeseries.js';
|
|
32
|
+
export { matrixAdd, matrixSub, matrixMul, elementwiseMul, scalarMul, determinant, trace, norm, inverse } from './utils/matrix.js';
|
|
33
|
+
export { trapezoidal, simpsons, adaptiveSimpson, gaussQuadrature, numericalDerivative, numericalSecondDerivative } from './utils/integration.js';
|
|
34
|
+
export { LinearInterpolator, CubicSplineInterpolator, lagrangeInterpolation, polynomialFit } from './utils/interpolation.js';
|
|
35
|
+
export { bisection, newtonRaphson, secant, falsePosition, fixedPoint } from './utils/rootfinding.js';
|
|
36
|
+
export { eulerMethod, rk4, systemEuler, systemRK4, rk45Adaptive } from './utils/odesolvers.js';
|
|
37
|
+
export { svd, qr, cholesky, lu } from './utils/decomposition.js';
|
|
38
|
+
export { gradientDescent, momentumDescent, adam, simplex, brent } from './utils/optimization.js';
|