pragmastat 5.0.0 → 5.2.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 +2 -2
- package/dist/assumptions.d.ts +33 -0
- package/dist/assumptions.d.ts.map +1 -0
- package/dist/assumptions.js +63 -0
- package/dist/assumptions.js.map +1 -0
- package/dist/estimators.d.ts +29 -0
- package/dist/estimators.d.ts.map +1 -1
- package/dist/estimators.js +88 -44
- package/dist/estimators.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/rng.d.ts +26 -0
- package/dist/rng.d.ts.map +1 -1
- package/dist/rng.js +41 -0
- package/dist/rng.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -3
- package/dist/utils.js.map +1 -1
- package/dist/xoshiro256.d.ts +2 -0
- package/dist/xoshiro256.d.ts.map +1 -1
- package/dist/xoshiro256.js +17 -0
- package/dist/xoshiro256.js.map +1 -1
- package/package.json +12 -13
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Install from npm:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm i pragmastat@5.
|
|
6
|
+
npm i pragmastat@5.2.0
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v5.
|
|
9
|
+
Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v5.2.0/ts
|
|
10
10
|
|
|
11
11
|
Pragmastat on npm: https://www.npmjs.com/package/pragmastat
|
|
12
12
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assumption validation framework for Pragmastat estimators.
|
|
3
|
+
*
|
|
4
|
+
* Assumption IDs (canonical priority order):
|
|
5
|
+
* 1. validity - non-empty input with finite defined real values
|
|
6
|
+
* 2. positivity - values must be strictly positive
|
|
7
|
+
* 3. sparity - sample must be non tie-dominant (Spread > 0)
|
|
8
|
+
*
|
|
9
|
+
* When multiple assumptions are violated, the violation with highest priority
|
|
10
|
+
* is reported. For two-sample functions, subject X is checked before Y.
|
|
11
|
+
*/
|
|
12
|
+
export declare const AssumptionId: {
|
|
13
|
+
readonly VALIDITY: "validity";
|
|
14
|
+
readonly POSITIVITY: "positivity";
|
|
15
|
+
readonly SPARITY: "sparity";
|
|
16
|
+
};
|
|
17
|
+
export type AssumptionId = (typeof AssumptionId)[keyof typeof AssumptionId];
|
|
18
|
+
export type Subject = 'x' | 'y';
|
|
19
|
+
export interface Violation {
|
|
20
|
+
id: AssumptionId;
|
|
21
|
+
subject: Subject;
|
|
22
|
+
}
|
|
23
|
+
export declare class AssumptionError extends Error {
|
|
24
|
+
readonly violation: Violation;
|
|
25
|
+
constructor(violation: Violation);
|
|
26
|
+
static validity(_functionName: string, subject: Subject): AssumptionError;
|
|
27
|
+
static positivity(_functionName: string, subject: Subject): AssumptionError;
|
|
28
|
+
static sparity(_functionName: string, subject: Subject): AssumptionError;
|
|
29
|
+
}
|
|
30
|
+
export declare function checkValidity(values: number[], subject: Subject, functionName: string): void;
|
|
31
|
+
export declare function checkPositivity(values: number[], subject: Subject, functionName: string): void;
|
|
32
|
+
export declare function checkSparity(values: number[], subject: Subject, functionName: string): void;
|
|
33
|
+
//# sourceMappingURL=assumptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assumptions.d.ts","sourceRoot":"","sources":["../src/assumptions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE5E,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC;AAEhC,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,YAAY,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAMhC,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;IAIzE,MAAM,CAAC,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;IAI3E,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;CAGzE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAO5F;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAI9F;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAQ3F"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssumptionError = exports.AssumptionId = void 0;
|
|
4
|
+
exports.checkValidity = checkValidity;
|
|
5
|
+
exports.checkPositivity = checkPositivity;
|
|
6
|
+
exports.checkSparity = checkSparity;
|
|
7
|
+
const fastSpread_1 = require("./fastSpread");
|
|
8
|
+
/**
|
|
9
|
+
* Assumption validation framework for Pragmastat estimators.
|
|
10
|
+
*
|
|
11
|
+
* Assumption IDs (canonical priority order):
|
|
12
|
+
* 1. validity - non-empty input with finite defined real values
|
|
13
|
+
* 2. positivity - values must be strictly positive
|
|
14
|
+
* 3. sparity - sample must be non tie-dominant (Spread > 0)
|
|
15
|
+
*
|
|
16
|
+
* When multiple assumptions are violated, the violation with highest priority
|
|
17
|
+
* is reported. For two-sample functions, subject X is checked before Y.
|
|
18
|
+
*/
|
|
19
|
+
exports.AssumptionId = {
|
|
20
|
+
VALIDITY: 'validity',
|
|
21
|
+
POSITIVITY: 'positivity',
|
|
22
|
+
SPARITY: 'sparity',
|
|
23
|
+
};
|
|
24
|
+
class AssumptionError extends Error {
|
|
25
|
+
constructor(violation) {
|
|
26
|
+
super(`${violation.id}(${violation.subject})`);
|
|
27
|
+
this.name = 'AssumptionError';
|
|
28
|
+
this.violation = violation;
|
|
29
|
+
}
|
|
30
|
+
static validity(_functionName, subject) {
|
|
31
|
+
return new AssumptionError({ id: exports.AssumptionId.VALIDITY, subject });
|
|
32
|
+
}
|
|
33
|
+
static positivity(_functionName, subject) {
|
|
34
|
+
return new AssumptionError({ id: exports.AssumptionId.POSITIVITY, subject });
|
|
35
|
+
}
|
|
36
|
+
static sparity(_functionName, subject) {
|
|
37
|
+
return new AssumptionError({ id: exports.AssumptionId.SPARITY, subject });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.AssumptionError = AssumptionError;
|
|
41
|
+
function checkValidity(values, subject, functionName) {
|
|
42
|
+
if (values.length === 0) {
|
|
43
|
+
throw AssumptionError.validity(functionName, subject);
|
|
44
|
+
}
|
|
45
|
+
if (!values.every((v) => Number.isFinite(v))) {
|
|
46
|
+
throw AssumptionError.validity(functionName, subject);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function checkPositivity(values, subject, functionName) {
|
|
50
|
+
if (values.some((v) => v <= 0)) {
|
|
51
|
+
throw AssumptionError.positivity(functionName, subject);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function checkSparity(values, subject, functionName) {
|
|
55
|
+
if (values.length < 2) {
|
|
56
|
+
throw AssumptionError.sparity(functionName, subject);
|
|
57
|
+
}
|
|
58
|
+
const spread = (0, fastSpread_1.fastSpread)(values);
|
|
59
|
+
if (spread <= 0) {
|
|
60
|
+
throw AssumptionError.sparity(functionName, subject);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=assumptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assumptions.js","sourceRoot":"","sources":["../src/assumptions.ts"],"names":[],"mappings":";;;AAmDA,sCAOC;AAED,0CAIC;AAED,oCAQC;AA1ED,6CAA0C;AAE1C;;;;;;;;;;GAUG;AAEU,QAAA,YAAY,GAAG;IAC1B,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;CACV,CAAC;AAWX,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,SAAoB;QAC9B,KAAK,CAAC,GAAG,SAAS,CAAC,EAAE,IAAI,SAAS,CAAC,OAAO,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,aAAqB,EAAE,OAAgB;QACrD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,EAAE,oBAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,aAAqB,EAAE,OAAgB;QACvD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,EAAE,oBAAY,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,aAAqB,EAAE,OAAgB;QACpD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,EAAE,oBAAY,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACpE,CAAC;CACF;AApBD,0CAoBC;AAED,SAAgB,aAAa,CAAC,MAAgB,EAAE,OAAgB,EAAE,YAAoB;IACpF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,eAAe,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,MAAM,eAAe,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAED,SAAgB,eAAe,CAAC,MAAgB,EAAE,OAAgB,EAAE,YAAoB;IACtF,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,eAAe,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED,SAAgB,YAAY,CAAC,MAAgB,EAAE,OAAgB,EAAE,YAAoB;IACnF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,eAAe,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IACD,MAAM,MAAM,GAAG,IAAA,uBAAU,EAAC,MAAM,CAAC,CAAC;IAClC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAChB,MAAM,eAAe,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
package/dist/estimators.d.ts
CHANGED
|
@@ -11,14 +11,24 @@ export declare function center(x: number[]): number;
|
|
|
11
11
|
/**
|
|
12
12
|
* Calculate the Spread - median of all pairwise absolute differences |x[i] - x[j]|
|
|
13
13
|
* Uses fast O(n log n) algorithm.
|
|
14
|
+
*
|
|
15
|
+
* Assumptions:
|
|
16
|
+
* sparity(x) - sample must be non tie-dominant (Spread > 0)
|
|
17
|
+
*
|
|
14
18
|
* @param x Array of sample values
|
|
15
19
|
* @returns The spread estimate
|
|
20
|
+
* @throws AssumptionError if sample is empty, contains NaN/Inf, or is tie-dominant
|
|
16
21
|
*/
|
|
17
22
|
export declare function spread(x: number[]): number;
|
|
18
23
|
/**
|
|
19
24
|
* Calculate the RelSpread - ratio of Spread to absolute Center
|
|
25
|
+
*
|
|
26
|
+
* Assumptions:
|
|
27
|
+
* positivity(x) - all values must be strictly positive (ensures Center > 0)
|
|
28
|
+
*
|
|
20
29
|
* @param x Array of sample values
|
|
21
30
|
* @returns The relative spread estimate
|
|
31
|
+
* @throws AssumptionError if sample is empty, contains NaN/Inf, or contains non-positive values
|
|
22
32
|
*/
|
|
23
33
|
export declare function relSpread(x: number[]): number;
|
|
24
34
|
/**
|
|
@@ -31,23 +41,41 @@ export declare function relSpread(x: number[]): number;
|
|
|
31
41
|
export declare function shift(x: number[], y: number[]): number;
|
|
32
42
|
/**
|
|
33
43
|
* Calculate the Ratio - median of all pairwise ratios (x[i] / y[j])
|
|
44
|
+
*
|
|
45
|
+
* Assumptions:
|
|
46
|
+
* positivity(x) - all values in x must be strictly positive
|
|
47
|
+
* positivity(y) - all values in y must be strictly positive
|
|
48
|
+
*
|
|
34
49
|
* @param x First sample
|
|
35
50
|
* @param y Second sample
|
|
36
51
|
* @returns The ratio estimate
|
|
52
|
+
* @throws AssumptionError if either sample is empty, contains NaN/Inf, or contains non-positive values
|
|
37
53
|
*/
|
|
38
54
|
export declare function ratio(x: number[], y: number[]): number;
|
|
39
55
|
/**
|
|
40
56
|
* Calculate the AvgSpread - weighted average of spreads: (n*Spread(x) + m*Spread(y))/(n+m)
|
|
57
|
+
*
|
|
58
|
+
* Assumptions:
|
|
59
|
+
* sparity(x) - first sample must be non tie-dominant (Spread > 0)
|
|
60
|
+
* sparity(y) - second sample must be non tie-dominant (Spread > 0)
|
|
61
|
+
*
|
|
41
62
|
* @param x First sample
|
|
42
63
|
* @param y Second sample
|
|
43
64
|
* @returns The combined spread estimate
|
|
65
|
+
* @throws AssumptionError if either sample is empty, contains NaN/Inf, or is tie-dominant
|
|
44
66
|
*/
|
|
45
67
|
export declare function avgSpread(x: number[], y: number[]): number;
|
|
46
68
|
/**
|
|
47
69
|
* Calculate the Disparity - Shift / AvgSpread
|
|
70
|
+
*
|
|
71
|
+
* Assumptions:
|
|
72
|
+
* sparity(x) - first sample must be non tie-dominant (Spread > 0)
|
|
73
|
+
* sparity(y) - second sample must be non tie-dominant (Spread > 0)
|
|
74
|
+
*
|
|
48
75
|
* @param x First sample
|
|
49
76
|
* @param y Second sample
|
|
50
77
|
* @returns The disparity estimate
|
|
78
|
+
* @throws AssumptionError if either sample is empty, contains NaN/Inf, or is tie-dominant
|
|
51
79
|
*/
|
|
52
80
|
export declare function disparity(x: number[], y: number[]): number;
|
|
53
81
|
/**
|
|
@@ -67,6 +95,7 @@ export interface Bounds {
|
|
|
67
95
|
* @param y Second sample
|
|
68
96
|
* @param misrate Misclassification rate (probability that true shift falls outside bounds)
|
|
69
97
|
* @returns An object containing the lower and upper bounds
|
|
98
|
+
* @throws AssumptionError if either sample is empty or contains NaN/Inf
|
|
70
99
|
*/
|
|
71
100
|
export declare function shiftBounds(x: number[], y: number[], misrate: number): Bounds;
|
|
72
101
|
//# sourceMappingURL=estimators.d.ts.map
|
package/dist/estimators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimators.d.ts","sourceRoot":"","sources":["../src/estimators.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"estimators.d.ts","sourceRoot":"","sources":["../src/estimators.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAI1C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAM1C;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAW7C;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAMtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAoBtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAkB1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAqB1D;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAqC7E"}
|
package/dist/estimators.js
CHANGED
|
@@ -16,6 +16,7 @@ const fastCenter_1 = require("./fastCenter");
|
|
|
16
16
|
const fastSpread_1 = require("./fastSpread");
|
|
17
17
|
const fastShift_1 = require("./fastShift");
|
|
18
18
|
const pairwiseMargin_1 = require("./pairwiseMargin");
|
|
19
|
+
const assumptions_1 = require("./assumptions");
|
|
19
20
|
/**
|
|
20
21
|
* Calculate the Center - median of all pairwise averages (x[i] + x[j])/2
|
|
21
22
|
* Uses fast O(n log n) algorithm.
|
|
@@ -23,37 +24,48 @@ const pairwiseMargin_1 = require("./pairwiseMargin");
|
|
|
23
24
|
* @returns The center estimate
|
|
24
25
|
*/
|
|
25
26
|
function center(x) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
// Check validity (priority 0)
|
|
28
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'Center');
|
|
29
29
|
return (0, fastCenter_1.fastCenter)(x);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Calculate the Spread - median of all pairwise absolute differences |x[i] - x[j]|
|
|
33
33
|
* Uses fast O(n log n) algorithm.
|
|
34
|
+
*
|
|
35
|
+
* Assumptions:
|
|
36
|
+
* sparity(x) - sample must be non tie-dominant (Spread > 0)
|
|
37
|
+
*
|
|
34
38
|
* @param x Array of sample values
|
|
35
39
|
* @returns The spread estimate
|
|
40
|
+
* @throws AssumptionError if sample is empty, contains NaN/Inf, or is tie-dominant
|
|
36
41
|
*/
|
|
37
42
|
function spread(x) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
// Check validity (priority 0)
|
|
44
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'Spread');
|
|
45
|
+
// Check sparity (priority 2)
|
|
46
|
+
(0, assumptions_1.checkSparity)(x, 'x', 'Spread');
|
|
41
47
|
return (0, fastSpread_1.fastSpread)(x);
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* Calculate the RelSpread - ratio of Spread to absolute Center
|
|
51
|
+
*
|
|
52
|
+
* Assumptions:
|
|
53
|
+
* positivity(x) - all values must be strictly positive (ensures Center > 0)
|
|
54
|
+
*
|
|
45
55
|
* @param x Array of sample values
|
|
46
56
|
* @returns The relative spread estimate
|
|
57
|
+
* @throws AssumptionError if sample is empty, contains NaN/Inf, or contains non-positive values
|
|
47
58
|
*/
|
|
48
59
|
function relSpread(x) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
// Check validity (priority 0)
|
|
61
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'RelSpread');
|
|
62
|
+
// Check positivity (priority 1)
|
|
63
|
+
(0, assumptions_1.checkPositivity)(x, 'x', 'RelSpread');
|
|
64
|
+
// Calculate center (we know x is valid, center should succeed)
|
|
65
|
+
const c = (0, fastCenter_1.fastCenter)(x);
|
|
66
|
+
// Calculate spread (using internal implementation since we already validated)
|
|
67
|
+
const s = (0, fastSpread_1.fastSpread)(x);
|
|
68
|
+
// center is guaranteed positive because all values are positive
|
|
57
69
|
return s / Math.abs(c);
|
|
58
70
|
}
|
|
59
71
|
/**
|
|
@@ -64,29 +76,34 @@ function relSpread(x) {
|
|
|
64
76
|
* @returns The shift estimate
|
|
65
77
|
*/
|
|
66
78
|
function shift(x, y) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
throw new Error('Input arrays cannot be empty');
|
|
71
|
-
}
|
|
79
|
+
// Check validity (priority 0)
|
|
80
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'Shift');
|
|
81
|
+
(0, assumptions_1.checkValidity)(y, 'y', 'Shift');
|
|
72
82
|
return (0, fastShift_1.fastShift)(x, y, [0.5], false)[0];
|
|
73
83
|
}
|
|
74
84
|
/**
|
|
75
85
|
* Calculate the Ratio - median of all pairwise ratios (x[i] / y[j])
|
|
86
|
+
*
|
|
87
|
+
* Assumptions:
|
|
88
|
+
* positivity(x) - all values in x must be strictly positive
|
|
89
|
+
* positivity(y) - all values in y must be strictly positive
|
|
90
|
+
*
|
|
76
91
|
* @param x First sample
|
|
77
92
|
* @param y Second sample
|
|
78
93
|
* @returns The ratio estimate
|
|
94
|
+
* @throws AssumptionError if either sample is empty, contains NaN/Inf, or contains non-positive values
|
|
79
95
|
*/
|
|
80
96
|
function ratio(x, y) {
|
|
97
|
+
// Check validity for x (priority 0, subject x)
|
|
98
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'Ratio');
|
|
99
|
+
// Check validity for y (priority 0, subject y)
|
|
100
|
+
(0, assumptions_1.checkValidity)(y, 'y', 'Ratio');
|
|
101
|
+
// Check positivity for x (priority 1, subject x)
|
|
102
|
+
(0, assumptions_1.checkPositivity)(x, 'x', 'Ratio');
|
|
103
|
+
// Check positivity for y (priority 1, subject y)
|
|
104
|
+
(0, assumptions_1.checkPositivity)(y, 'y', 'Ratio');
|
|
81
105
|
const nx = x.length;
|
|
82
106
|
const ny = y.length;
|
|
83
|
-
if (nx === 0 || ny === 0) {
|
|
84
|
-
throw new Error('Input arrays cannot be empty');
|
|
85
|
-
}
|
|
86
|
-
// Check that all y values are strictly positive
|
|
87
|
-
if (y.some((val) => val <= 0)) {
|
|
88
|
-
throw new Error('All values in y must be strictly positive');
|
|
89
|
-
}
|
|
90
107
|
const pairwiseRatios = [];
|
|
91
108
|
for (let i = 0; i < nx; i++) {
|
|
92
109
|
for (let j = 0; j < ny; j++) {
|
|
@@ -97,37 +114,62 @@ function ratio(x, y) {
|
|
|
97
114
|
}
|
|
98
115
|
/**
|
|
99
116
|
* Calculate the AvgSpread - weighted average of spreads: (n*Spread(x) + m*Spread(y))/(n+m)
|
|
117
|
+
*
|
|
118
|
+
* Assumptions:
|
|
119
|
+
* sparity(x) - first sample must be non tie-dominant (Spread > 0)
|
|
120
|
+
* sparity(y) - second sample must be non tie-dominant (Spread > 0)
|
|
121
|
+
*
|
|
100
122
|
* @param x First sample
|
|
101
123
|
* @param y Second sample
|
|
102
124
|
* @returns The combined spread estimate
|
|
125
|
+
* @throws AssumptionError if either sample is empty, contains NaN/Inf, or is tie-dominant
|
|
103
126
|
*/
|
|
104
127
|
function avgSpread(x, y) {
|
|
128
|
+
// Check validity for x (priority 0, subject x)
|
|
129
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'AvgSpread');
|
|
130
|
+
// Check validity for y (priority 0, subject y)
|
|
131
|
+
(0, assumptions_1.checkValidity)(y, 'y', 'AvgSpread');
|
|
132
|
+
// Check sparity for x (priority 2, subject x)
|
|
133
|
+
(0, assumptions_1.checkSparity)(x, 'x', 'AvgSpread');
|
|
134
|
+
// Check sparity for y (priority 2, subject y)
|
|
135
|
+
(0, assumptions_1.checkSparity)(y, 'y', 'AvgSpread');
|
|
105
136
|
const nx = x.length;
|
|
106
137
|
const ny = y.length;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Calculate weighted average of individual spreads
|
|
111
|
-
const spreadX = spread(x);
|
|
112
|
-
const spreadY = spread(y);
|
|
138
|
+
// Calculate spreads (using internal implementation since we already validated)
|
|
139
|
+
const spreadX = (0, fastSpread_1.fastSpread)(x);
|
|
140
|
+
const spreadY = (0, fastSpread_1.fastSpread)(y);
|
|
113
141
|
return (nx * spreadX + ny * spreadY) / (nx + ny);
|
|
114
142
|
}
|
|
115
143
|
/**
|
|
116
144
|
* Calculate the Disparity - Shift / AvgSpread
|
|
145
|
+
*
|
|
146
|
+
* Assumptions:
|
|
147
|
+
* sparity(x) - first sample must be non tie-dominant (Spread > 0)
|
|
148
|
+
* sparity(y) - second sample must be non tie-dominant (Spread > 0)
|
|
149
|
+
*
|
|
117
150
|
* @param x First sample
|
|
118
151
|
* @param y Second sample
|
|
119
152
|
* @returns The disparity estimate
|
|
153
|
+
* @throws AssumptionError if either sample is empty, contains NaN/Inf, or is tie-dominant
|
|
120
154
|
*/
|
|
121
155
|
function disparity(x, y) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
156
|
+
// Check validity for x (priority 0, subject x)
|
|
157
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'Disparity');
|
|
158
|
+
// Check validity for y (priority 0, subject y)
|
|
159
|
+
(0, assumptions_1.checkValidity)(y, 'y', 'Disparity');
|
|
160
|
+
// Check sparity for x (priority 2, subject x)
|
|
161
|
+
(0, assumptions_1.checkSparity)(x, 'x', 'Disparity');
|
|
162
|
+
// Check sparity for y (priority 2, subject y)
|
|
163
|
+
(0, assumptions_1.checkSparity)(y, 'y', 'Disparity');
|
|
164
|
+
const nx = x.length;
|
|
165
|
+
const ny = y.length;
|
|
166
|
+
// Calculate shift (we know inputs are valid)
|
|
167
|
+
const shiftVal = (0, fastShift_1.fastShift)(x, y, [0.5], false)[0];
|
|
168
|
+
// Calculate avg_spread (using internal implementation since we already validated)
|
|
169
|
+
const spreadX = (0, fastSpread_1.fastSpread)(x);
|
|
170
|
+
const spreadY = (0, fastSpread_1.fastSpread)(y);
|
|
171
|
+
const avgSpreadVal = (nx * spreadX + ny * spreadY) / (nx + ny);
|
|
172
|
+
return shiftVal / avgSpreadVal;
|
|
131
173
|
}
|
|
132
174
|
/**
|
|
133
175
|
* Provides bounds on the Shift estimator with specified misclassification rate (ShiftBounds)
|
|
@@ -139,11 +181,13 @@ function disparity(x, y) {
|
|
|
139
181
|
* @param y Second sample
|
|
140
182
|
* @param misrate Misclassification rate (probability that true shift falls outside bounds)
|
|
141
183
|
* @returns An object containing the lower and upper bounds
|
|
184
|
+
* @throws AssumptionError if either sample is empty or contains NaN/Inf
|
|
142
185
|
*/
|
|
143
186
|
function shiftBounds(x, y, misrate) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
187
|
+
// Check validity for x
|
|
188
|
+
(0, assumptions_1.checkValidity)(x, 'x', 'ShiftBounds');
|
|
189
|
+
// Check validity for y
|
|
190
|
+
(0, assumptions_1.checkValidity)(y, 'y', 'ShiftBounds');
|
|
147
191
|
const n = x.length;
|
|
148
192
|
const m = y.length;
|
|
149
193
|
// Sort both arrays
|
package/dist/estimators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimators.js","sourceRoot":"","sources":["../src/estimators.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"estimators.js","sourceRoot":"","sources":["../src/estimators.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAeH,wBAIC;AAaD,wBAMC;AAYD,8BAWC;AASD,sBAMC;AAcD,sBAoBC;AAcD,8BAkBC;AAcD,8BAqBC;AA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,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC;IACzB,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,GAAG,UAAU,CAAC;IAEtC,6BAA6B;IAC7B,MAAM,WAAW,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,KAAK,GAAG,WAAW,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC;IAEpC,6DAA6D;IAC7D,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,IAAA,qBAAS,EAAC,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAEpC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A collection of robust statistical estimators for real-world data analysis.
|
|
5
5
|
*/
|
|
6
|
+
export { AssumptionId, AssumptionError, type Subject, type Violation } from './assumptions';
|
|
6
7
|
export { center, spread, relSpread, shift, ratio, avgSpread, disparity, shiftBounds, type Bounds, } from './estimators';
|
|
7
8
|
export { median } from './utils';
|
|
8
9
|
export { pairwiseMargin } from './pairwiseMargin';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAG5F,OAAO,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,KAAK,EACL,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,KAAK,MAAM,GACZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,KAAK,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
* A collection of robust statistical estimators for real-world data analysis.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.Power = exports.Exp = exports.Multiplic = exports.Additive = exports.Uniform = exports.Rng = exports.pairwiseMargin = exports.median = exports.shiftBounds = exports.disparity = exports.avgSpread = exports.ratio = exports.shift = exports.relSpread = exports.spread = exports.center = void 0;
|
|
8
|
+
exports.Power = exports.Exp = exports.Multiplic = exports.Additive = exports.Uniform = exports.Rng = exports.pairwiseMargin = exports.median = exports.shiftBounds = exports.disparity = exports.avgSpread = exports.ratio = exports.shift = exports.relSpread = exports.spread = exports.center = exports.AssumptionError = exports.AssumptionId = void 0;
|
|
9
|
+
// Assumptions
|
|
10
|
+
var assumptions_1 = require("./assumptions");
|
|
11
|
+
Object.defineProperty(exports, "AssumptionId", { enumerable: true, get: function () { return assumptions_1.AssumptionId; } });
|
|
12
|
+
Object.defineProperty(exports, "AssumptionError", { enumerable: true, get: function () { return assumptions_1.AssumptionError; } });
|
|
13
|
+
// Estimators
|
|
9
14
|
var estimators_1 = require("./estimators");
|
|
10
15
|
Object.defineProperty(exports, "center", { enumerable: true, get: function () { return estimators_1.center; } });
|
|
11
16
|
Object.defineProperty(exports, "spread", { enumerable: true, get: function () { return estimators_1.spread; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,2CAUsB;AATpB,oGAAA,MAAM,OAAA;AACN,oGAAA,MAAM,OAAA;AACN,uGAAA,SAAS,OAAA;AACT,mGAAA,KAAK,OAAA;AACL,mGAAA,KAAK,OAAA;AACL,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AACT,yGAAA,WAAW,OAAA;AAIb,iCAAiC;AAAxB,+FAAA,MAAM,OAAA;AAEf,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AAEZ,+CAAoG;AAAxE,gGAAA,OAAO,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,kGAAA,SAAS,OAAA;AAAE,4FAAA,GAAG,OAAA;AAAE,8FAAA,KAAK,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,cAAc;AACd,6CAA4F;AAAnF,2GAAA,YAAY,OAAA;AAAE,8GAAA,eAAe,OAAA;AAEtC,aAAa;AACb,2CAUsB;AATpB,oGAAA,MAAM,OAAA;AACN,oGAAA,MAAM,OAAA;AACN,uGAAA,SAAS,OAAA;AACT,mGAAA,KAAK,OAAA;AACL,mGAAA,KAAK,OAAA;AACL,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AACT,yGAAA,WAAW,OAAA;AAIb,iCAAiC;AAAxB,+FAAA,MAAM,OAAA;AAEf,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AAEZ,+CAAoG;AAAxE,gGAAA,OAAO,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,kGAAA,SAAS,OAAA;AAAE,4FAAA,GAAG,OAAA;AAAE,8FAAA,KAAK,OAAA"}
|
package/dist/rng.d.ts
CHANGED
|
@@ -47,6 +47,14 @@ export declare class Rng {
|
|
|
47
47
|
* @returns Random value in [0, 1).
|
|
48
48
|
*/
|
|
49
49
|
uniform(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Generate a uniform random float in [min, max).
|
|
52
|
+
*
|
|
53
|
+
* @param min - Minimum value (inclusive).
|
|
54
|
+
* @param max - Maximum value (exclusive).
|
|
55
|
+
* @returns Random value in [min, max). Returns min if min >= max.
|
|
56
|
+
*/
|
|
57
|
+
uniformRange(min: number, max: number): number;
|
|
50
58
|
/**
|
|
51
59
|
* Generate a uniform random integer in [min, max).
|
|
52
60
|
*
|
|
@@ -59,6 +67,24 @@ export declare class Rng {
|
|
|
59
67
|
* @returns Random integer in [min, max). Returns min if min >= max.
|
|
60
68
|
*/
|
|
61
69
|
uniformInt(min: number, max: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Generate a uniform random BigInt in [min, max).
|
|
72
|
+
*
|
|
73
|
+
* Uses modulo reduction which introduces slight bias for ranges that don't
|
|
74
|
+
* evenly divide 2^64. This bias is negligible for statistical simulations
|
|
75
|
+
* but not suitable for cryptographic applications.
|
|
76
|
+
*
|
|
77
|
+
* @param min - Minimum value (inclusive).
|
|
78
|
+
* @param max - Maximum value (exclusive).
|
|
79
|
+
* @returns Random BigInt in [min, max). Returns min if min >= max.
|
|
80
|
+
*/
|
|
81
|
+
uniformBigInt(min: bigint, max: bigint): bigint;
|
|
82
|
+
/**
|
|
83
|
+
* Generate a uniform random boolean with P(true) = 0.5.
|
|
84
|
+
*
|
|
85
|
+
* @returns Random boolean value.
|
|
86
|
+
*/
|
|
87
|
+
uniformBool(): boolean;
|
|
62
88
|
/**
|
|
63
89
|
* Return a shuffled copy of the input array.
|
|
64
90
|
*
|
package/dist/rng.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rng.d.ts","sourceRoot":"","sources":["../src/rng.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,GAAG;IACd,OAAO,CAAC,KAAK,CAAqB;IAElC;;;;;;OAMG;gBACS,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"rng.d.ts","sourceRoot":"","sources":["../src/rng.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,GAAG;IACd,OAAO,CAAC,KAAK,CAAqB;IAElC;;;;;;OAMG;gBACS,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;IAmBlC;;;;;;OAMG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;OAMG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ9C;;;;;;;;;;OAUG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAK5C;;;;;;;;;;OAUG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ/C;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE;IAavB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE;CAuBlC"}
|
package/dist/rng.js
CHANGED
|
@@ -55,6 +55,9 @@ class Rng {
|
|
|
55
55
|
}
|
|
56
56
|
this.inner = new xoshiro256_1.Xoshiro256PlusPlus(seedBigInt);
|
|
57
57
|
}
|
|
58
|
+
// ========================================================================
|
|
59
|
+
// Floating Point Methods
|
|
60
|
+
// ========================================================================
|
|
58
61
|
/**
|
|
59
62
|
* Generate a uniform random float in [0, 1).
|
|
60
63
|
*
|
|
@@ -65,6 +68,19 @@ class Rng {
|
|
|
65
68
|
uniform() {
|
|
66
69
|
return this.inner.uniform();
|
|
67
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate a uniform random float in [min, max).
|
|
73
|
+
*
|
|
74
|
+
* @param min - Minimum value (inclusive).
|
|
75
|
+
* @param max - Maximum value (exclusive).
|
|
76
|
+
* @returns Random value in [min, max). Returns min if min >= max.
|
|
77
|
+
*/
|
|
78
|
+
uniformRange(min, max) {
|
|
79
|
+
return this.inner.uniformRange(min, max);
|
|
80
|
+
}
|
|
81
|
+
// ========================================================================
|
|
82
|
+
// Integer Methods
|
|
83
|
+
// ========================================================================
|
|
68
84
|
/**
|
|
69
85
|
* Generate a uniform random integer in [min, max).
|
|
70
86
|
*
|
|
@@ -80,6 +96,31 @@ class Rng {
|
|
|
80
96
|
const result = this.inner.uniformInt(BigInt(min), BigInt(max));
|
|
81
97
|
return Number(result);
|
|
82
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Generate a uniform random BigInt in [min, max).
|
|
101
|
+
*
|
|
102
|
+
* Uses modulo reduction which introduces slight bias for ranges that don't
|
|
103
|
+
* evenly divide 2^64. This bias is negligible for statistical simulations
|
|
104
|
+
* but not suitable for cryptographic applications.
|
|
105
|
+
*
|
|
106
|
+
* @param min - Minimum value (inclusive).
|
|
107
|
+
* @param max - Maximum value (exclusive).
|
|
108
|
+
* @returns Random BigInt in [min, max). Returns min if min >= max.
|
|
109
|
+
*/
|
|
110
|
+
uniformBigInt(min, max) {
|
|
111
|
+
return this.inner.uniformInt(min, max);
|
|
112
|
+
}
|
|
113
|
+
// ========================================================================
|
|
114
|
+
// Boolean Methods
|
|
115
|
+
// ========================================================================
|
|
116
|
+
/**
|
|
117
|
+
* Generate a uniform random boolean with P(true) = 0.5.
|
|
118
|
+
*
|
|
119
|
+
* @returns Random boolean value.
|
|
120
|
+
*/
|
|
121
|
+
uniformBool() {
|
|
122
|
+
return this.inner.uniformBool();
|
|
123
|
+
}
|
|
83
124
|
/**
|
|
84
125
|
* Return a shuffled copy of the input array.
|
|
85
126
|
*
|
package/dist/rng.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rng.js","sourceRoot":"","sources":["../src/rng.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6CAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,GAAG;IAGd;;;;;;OAMG;IACH,YAAY,IAAsB;QAChC,IAAI,UAAkB,CAAC;QAEvB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAClC,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,UAAU,GAAG,IAAA,sBAAS,EAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,2EAA2E;YAC3E,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,+BAAkB,CAAC,UAAU,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,C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,CAAM,EAAE,CAAS;QACzB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5C,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC;YACxB,4DAA4D;YAC5D,IAAI,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,GAAG,SAAS,EAAE,CAAC;gBAC3C,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClB,SAAS,EAAE,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA3JD,kBA2JC"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAY/C"}
|
package/dist/utils.js
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.median = median;
|
|
7
|
+
const assumptions_1 = require("./assumptions");
|
|
7
8
|
/**
|
|
8
9
|
* Calculate the median of an array of numbers
|
|
9
10
|
* @param values Array of numbers
|
|
10
11
|
* @returns The median value
|
|
11
12
|
*/
|
|
12
13
|
function median(values) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
// Check validity (priority 0)
|
|
15
|
+
(0, assumptions_1.checkValidity)(values, 'x', 'Median');
|
|
16
16
|
const sorted = [...values].sort((a, b) => a - b);
|
|
17
17
|
const mid = Math.floor(sorted.length / 2);
|
|
18
18
|
if (sorted.length % 2 === 0) {
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;AASH,wBAYC;AAnBD,+CAA8C;AAE9C;;;;GAIG;AACH,SAAgB,MAAM,CAAC,MAAgB;IACrC,8BAA8B;IAC9B,IAAA,2BAAa,EAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;IAErC,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/xoshiro256.d.ts
CHANGED
|
@@ -16,11 +16,13 @@ export declare class Xoshiro256PlusPlus {
|
|
|
16
16
|
constructor(seed: bigint);
|
|
17
17
|
nextU64(): bigint;
|
|
18
18
|
uniform(): number;
|
|
19
|
+
uniformRange(min: number, max: number): number;
|
|
19
20
|
/**
|
|
20
21
|
* Generate a uniform integer in [min, max).
|
|
21
22
|
* @throws RangeError if max - min exceeds i64 range.
|
|
22
23
|
*/
|
|
23
24
|
uniformInt(min: bigint, max: bigint): bigint;
|
|
25
|
+
uniformBool(): boolean;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Compute FNV-1a 64-bit hash of a string
|
package/dist/xoshiro256.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xoshiro256.d.ts","sourceRoot":"","sources":["../src/xoshiro256.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2BH;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAmC;gBAEpC,IAAI,EAAE,MAAM;IAKxB,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"xoshiro256.d.ts","sourceRoot":"","sources":["../src/xoshiro256.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2BH;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAmC;gBAEpC,IAAI,EAAE,MAAM;IAKxB,OAAO,IAAI,MAAM;IAqBjB,OAAO,IAAI,MAAM;IAMjB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAS9C;;;OAGG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAgB5C,WAAW,IAAI,OAAO;CAGvB;AAMD;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAW3C"}
|
package/dist/xoshiro256.js
CHANGED
|
@@ -51,11 +51,22 @@ class Xoshiro256PlusPlus {
|
|
|
51
51
|
s[3] = rotl(s[3], 45n);
|
|
52
52
|
return result;
|
|
53
53
|
}
|
|
54
|
+
// ========================================================================
|
|
55
|
+
// Floating Point Methods
|
|
56
|
+
// ========================================================================
|
|
54
57
|
uniform() {
|
|
55
58
|
// Use upper 53 bits for maximum precision in float64
|
|
56
59
|
const u64 = this.nextU64();
|
|
57
60
|
return Number(u64 >> 11n) * (1.0 / Number(1n << 53n));
|
|
58
61
|
}
|
|
62
|
+
uniformRange(min, max) {
|
|
63
|
+
if (min >= max)
|
|
64
|
+
return min;
|
|
65
|
+
return min + (max - min) * this.uniform();
|
|
66
|
+
}
|
|
67
|
+
// ========================================================================
|
|
68
|
+
// Integer Methods
|
|
69
|
+
// ========================================================================
|
|
59
70
|
/**
|
|
60
71
|
* Generate a uniform integer in [min, max).
|
|
61
72
|
* @throws RangeError if max - min exceeds i64 range.
|
|
@@ -71,6 +82,12 @@ class Xoshiro256PlusPlus {
|
|
|
71
82
|
}
|
|
72
83
|
return min + (this.nextU64() % range);
|
|
73
84
|
}
|
|
85
|
+
// ========================================================================
|
|
86
|
+
// Boolean Methods
|
|
87
|
+
// ========================================================================
|
|
88
|
+
uniformBool() {
|
|
89
|
+
return this.uniform() < 0.5;
|
|
90
|
+
}
|
|
74
91
|
}
|
|
75
92
|
exports.Xoshiro256PlusPlus = Xoshiro256PlusPlus;
|
|
76
93
|
// FNV-1a hash constants
|
package/dist/xoshiro256.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xoshiro256.js","sourceRoot":"","sources":["../src/xoshiro256.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;
|
|
1
|
+
{"version":3,"file":"xoshiro256.js","sourceRoot":"","sources":["../src/xoshiro256.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA6GH,8BAWC;AAtHD,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAEpC,SAAS,I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C;QACD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QACxB,8DAA8D;QAC9D,IAAI,KAAK,GAAG,mBAAmB,EAAE,CAAC;YAChC,MAAM,IAAI,UAAU,CAAC,qDAAqD,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,2EAA2E;IAC3E,kBAAkB;IAClB,2EAA2E;IAE3E,WAAW;QACT,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC;IAC9B,CAAC;CACF;AAnED,gDAmEC;AAED,wBAAwB;AACxB,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAC7C,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC;;GAEG;AACH,SAAgB,SAAS,CAAC,CAAS;IACjC,IAAI,IAAI,GAAG,gBAAgB,CAAC;IAC5B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEhC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC;IACtC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pragmastat",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Pragmastat: Pragmatic Statistical Toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"test": "jest",
|
|
10
|
-
"test:watch": "jest --watch",
|
|
11
|
-
"test:coverage": "jest --coverage",
|
|
12
|
-
"lint": "eslint src tests --ext .ts",
|
|
13
|
-
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
14
|
-
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
15
|
-
"clean": "rm -rf dist coverage",
|
|
16
|
-
"prepublishOnly": "npm run clean && npm run build && npm run test"
|
|
17
|
-
},
|
|
18
7
|
"keywords": [
|
|
19
8
|
"statistics"
|
|
20
9
|
],
|
|
@@ -41,5 +30,15 @@
|
|
|
41
30
|
"url": "https://github.com/AndreyAkinshin/pragmastat.git"
|
|
42
31
|
},
|
|
43
32
|
"homepage": "https://pragmastat.dev",
|
|
44
|
-
"doi": "10.5281/zenodo.17236778"
|
|
33
|
+
"doi": "10.5281/zenodo.17236778",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"test:watch": "jest --watch",
|
|
38
|
+
"test:coverage": "jest --coverage",
|
|
39
|
+
"lint": "eslint src tests --ext .ts",
|
|
40
|
+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
41
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
42
|
+
"clean": "rm -rf dist coverage"
|
|
43
|
+
}
|
|
45
44
|
}
|