@ac-kit/math-stats 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/CHANGELOG.md +22 -0
- package/LICENSE +28 -0
- package/README.md +91 -0
- package/dist/_assert-probability.d.ts +14 -0
- package/dist/_assert-probability.d.ts.map +1 -0
- package/dist/_assert-probability.js +18 -0
- package/dist/_assert-probability.js.map +1 -0
- package/dist/_discrete-quantile.d.ts +16 -0
- package/dist/_discrete-quantile.d.ts.map +1 -0
- package/dist/_discrete-quantile.js +43 -0
- package/dist/_discrete-quantile.js.map +1 -0
- package/dist/_inverse-transform-sample.d.ts +17 -0
- package/dist/_inverse-transform-sample.d.ts.map +1 -0
- package/dist/_inverse-transform-sample.js +18 -0
- package/dist/_inverse-transform-sample.js.map +1 -0
- package/dist/_log-binomial.d.ts +16 -0
- package/dist/_log-binomial.d.ts.map +1 -0
- package/dist/_log-binomial.js +19 -0
- package/dist/_log-binomial.js.map +1 -0
- package/dist/average.d.ts +95 -0
- package/dist/average.d.ts.map +1 -0
- package/dist/average.js +113 -0
- package/dist/average.js.map +1 -0
- package/dist/beta-distribution.d.ts +15 -0
- package/dist/beta-distribution.d.ts.map +1 -0
- package/dist/beta-distribution.js +61 -0
- package/dist/beta-distribution.js.map +1 -0
- package/dist/binomial-distribution.d.ts +18 -0
- package/dist/binomial-distribution.d.ts.map +1 -0
- package/dist/binomial-distribution.js +74 -0
- package/dist/binomial-distribution.js.map +1 -0
- package/dist/chi-squared-distribution.d.ts +15 -0
- package/dist/chi-squared-distribution.d.ts.map +1 -0
- package/dist/chi-squared-distribution.js +25 -0
- package/dist/chi-squared-distribution.js.map +1 -0
- package/dist/chi-squared-test.d.ts +39 -0
- package/dist/chi-squared-test.d.ts.map +1 -0
- package/dist/chi-squared-test.js +56 -0
- package/dist/chi-squared-test.js.map +1 -0
- package/dist/confidence-interval.d.ts +62 -0
- package/dist/confidence-interval.d.ts.map +1 -0
- package/dist/confidence-interval.js +93 -0
- package/dist/confidence-interval.js.map +1 -0
- package/dist/dispersion.d.ts +45 -0
- package/dist/dispersion.d.ts.map +1 -0
- package/dist/dispersion.js +80 -0
- package/dist/dispersion.js.map +1 -0
- package/dist/distribution.d.ts +61 -0
- package/dist/distribution.d.ts.map +1 -0
- package/dist/distribution.js +2 -0
- package/dist/distribution.js.map +1 -0
- package/dist/exponential-distribution.d.ts +15 -0
- package/dist/exponential-distribution.d.ts.map +1 -0
- package/dist/exponential-distribution.js +33 -0
- package/dist/exponential-distribution.js.map +1 -0
- package/dist/f-distribution.d.ts +17 -0
- package/dist/f-distribution.d.ts.map +1 -0
- package/dist/f-distribution.js +88 -0
- package/dist/f-distribution.js.map +1 -0
- package/dist/gamma-distribution.d.ts +15 -0
- package/dist/gamma-distribution.d.ts.map +1 -0
- package/dist/gamma-distribution.js +45 -0
- package/dist/gamma-distribution.js.map +1 -0
- package/dist/geometric-distribution.d.ts +19 -0
- package/dist/geometric-distribution.d.ts.map +1 -0
- package/dist/geometric-distribution.js +54 -0
- package/dist/geometric-distribution.js.map +1 -0
- package/dist/hierarchical-cluster.d.ts +35 -0
- package/dist/hierarchical-cluster.d.ts.map +1 -0
- package/dist/hierarchical-cluster.js +97 -0
- package/dist/hierarchical-cluster.js.map +1 -0
- package/dist/hypergeometric-distribution.d.ts +18 -0
- package/dist/hypergeometric-distribution.d.ts.map +1 -0
- package/dist/hypergeometric-distribution.js +92 -0
- package/dist/hypergeometric-distribution.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/kmeans.d.ts +87 -0
- package/dist/kmeans.d.ts.map +1 -0
- package/dist/kmeans.js +126 -0
- package/dist/kmeans.js.map +1 -0
- package/dist/kmedoids.d.ts +27 -0
- package/dist/kmedoids.d.ts.map +1 -0
- package/dist/kmedoids.js +47 -0
- package/dist/kmedoids.js.map +1 -0
- package/dist/log-normal-distribution.d.ts +15 -0
- package/dist/log-normal-distribution.d.ts.map +1 -0
- package/dist/log-normal-distribution.js +44 -0
- package/dist/log-normal-distribution.js.map +1 -0
- package/dist/negative-binomial-distribution.d.ts +18 -0
- package/dist/negative-binomial-distribution.d.ts.map +1 -0
- package/dist/negative-binomial-distribution.js +64 -0
- package/dist/negative-binomial-distribution.js.map +1 -0
- package/dist/normal-distribution.d.ts +16 -0
- package/dist/normal-distribution.d.ts.map +1 -0
- package/dist/normal-distribution.js +41 -0
- package/dist/normal-distribution.js.map +1 -0
- package/dist/normal-quantile.d.ts +19 -0
- package/dist/normal-quantile.d.ts.map +1 -0
- package/dist/normal-quantile.js +115 -0
- package/dist/normal-quantile.js.map +1 -0
- package/dist/one-way-anova.d.ts +31 -0
- package/dist/one-way-anova.d.ts.map +1 -0
- package/dist/one-way-anova.js +69 -0
- package/dist/one-way-anova.js.map +1 -0
- package/dist/outliers.d.ts +20 -0
- package/dist/outliers.d.ts.map +1 -0
- package/dist/outliers.js +49 -0
- package/dist/outliers.js.map +1 -0
- package/dist/poisson-distribution.d.ts +15 -0
- package/dist/poisson-distribution.d.ts.map +1 -0
- package/dist/poisson-distribution.js +44 -0
- package/dist/poisson-distribution.js.map +1 -0
- package/dist/quantile.d.ts +9 -0
- package/dist/quantile.d.ts.map +1 -0
- package/dist/quantile.js +23 -0
- package/dist/quantile.js.map +1 -0
- package/dist/random-effects.d.ts +45 -0
- package/dist/random-effects.d.ts.map +1 -0
- package/dist/random-effects.js +97 -0
- package/dist/random-effects.js.map +1 -0
- package/dist/regression.d.ts +12 -0
- package/dist/regression.d.ts.map +1 -0
- package/dist/regression.js +35 -0
- package/dist/regression.js.map +1 -0
- package/dist/student-t-distribution.d.ts +16 -0
- package/dist/student-t-distribution.d.ts.map +1 -0
- package/dist/student-t-distribution.js +54 -0
- package/dist/student-t-distribution.js.map +1 -0
- package/dist/sum.d.ts +31 -0
- package/dist/sum.d.ts.map +1 -0
- package/dist/sum.js +30 -0
- package/dist/sum.js.map +1 -0
- package/dist/t-test.d.ts +52 -0
- package/dist/t-test.d.ts.map +1 -0
- package/dist/t-test.js +81 -0
- package/dist/t-test.js.map +1 -0
- package/dist/trend.d.ts +55 -0
- package/dist/trend.d.ts.map +1 -0
- package/dist/trend.js +98 -0
- package/dist/trend.js.map +1 -0
- package/dist/uncertainty.d.ts +25 -0
- package/dist/uncertainty.d.ts.map +1 -0
- package/dist/uncertainty.js +26 -0
- package/dist/uncertainty.js.map +1 -0
- package/dist/uniform-distribution.d.ts +11 -0
- package/dist/uniform-distribution.d.ts.map +1 -0
- package/dist/uniform-distribution.js +33 -0
- package/dist/uniform-distribution.js.map +1 -0
- package/dist/welch-t-statistic.d.ts +24 -0
- package/dist/welch-t-statistic.d.ts.map +1 -0
- package/dist/welch-t-statistic.js +33 -0
- package/dist/welch-t-statistic.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* The exponential distribution — the waiting time between events arriving at a
|
|
4
|
+
* constant average `rate`.
|
|
5
|
+
*
|
|
6
|
+
* Every member has a closed form, and each is written in the shape that keeps
|
|
7
|
+
* it accurate: `expm1` and `log1p` rather than `exp` and `log` of a quantity
|
|
8
|
+
* near 1, which is where the whole answer sits for a short wait.
|
|
9
|
+
*
|
|
10
|
+
* @param rate Events per unit time; must be positive.
|
|
11
|
+
* @returns The distribution.
|
|
12
|
+
* @throws {RangeError} When `rate` is not positive.
|
|
13
|
+
*/
|
|
14
|
+
export declare function exponentialDistribution(rate?: number): Distribution;
|
|
15
|
+
//# sourceMappingURL=exponential-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exponential-distribution.d.ts","sourceRoot":"","sources":["../src/exponential-distribution.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,SAAI,GAAG,YAAY,CAsB9D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
2
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
3
|
+
/**
|
|
4
|
+
* The exponential distribution — the waiting time between events arriving at a
|
|
5
|
+
* constant average `rate`.
|
|
6
|
+
*
|
|
7
|
+
* Every member has a closed form, and each is written in the shape that keeps
|
|
8
|
+
* it accurate: `expm1` and `log1p` rather than `exp` and `log` of a quantity
|
|
9
|
+
* near 1, which is where the whole answer sits for a short wait.
|
|
10
|
+
*
|
|
11
|
+
* @param rate Events per unit time; must be positive.
|
|
12
|
+
* @returns The distribution.
|
|
13
|
+
* @throws {RangeError} When `rate` is not positive.
|
|
14
|
+
*/
|
|
15
|
+
export function exponentialDistribution(rate = 1) {
|
|
16
|
+
if (!(rate > 0)) {
|
|
17
|
+
throw new RangeError(`exponentialDistribution: rate must be positive, got ${rate}`);
|
|
18
|
+
}
|
|
19
|
+
const quantile = (probability) => {
|
|
20
|
+
assertProbability_("exponentialDistribution", probability);
|
|
21
|
+
return -Math.log1p(-probability) / rate;
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
density: (x) => (x < 0 ? 0 : rate * Math.exp(-rate * x)),
|
|
25
|
+
cdf: (x) => (x < 0 ? 0 : -Math.expm1(-rate * x)),
|
|
26
|
+
survival: (x) => (x < 0 ? 1 : Math.exp(-rate * x)),
|
|
27
|
+
quantile,
|
|
28
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
29
|
+
mean: 1 / rate,
|
|
30
|
+
variance: 1 / (rate * rate),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=exponential-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exponential-distribution.js","sourceRoot":"","sources":["../src/exponential-distribution.ts"],"names":[],"mappings":"AAAA,OA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AC,IAAI,GAAG,IAAI,CAAC;KAC3B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* The F distribution — the ratio of two chi-squared variates divided by their
|
|
4
|
+
* degrees of freedom, and the reference distribution of an analysis of
|
|
5
|
+
* variance.
|
|
6
|
+
*
|
|
7
|
+
* Each tail is reached through the incomplete beta on the side where it is
|
|
8
|
+
* small, and the quantile is solved from whichever tail `probability` names, so
|
|
9
|
+
* neither ever hands the beta inverse an argument adjacent to 1.
|
|
10
|
+
*
|
|
11
|
+
* @param numeratorDegreesOfFreedom Positive; need not be an integer.
|
|
12
|
+
* @param denominatorDegreesOfFreedom Positive; need not be an integer.
|
|
13
|
+
* @returns The distribution.
|
|
14
|
+
* @throws {RangeError} When either parameter is not positive.
|
|
15
|
+
*/
|
|
16
|
+
export declare function fDistribution(numeratorDegreesOfFreedom: number, denominatorDegreesOfFreedom: number): Distribution;
|
|
17
|
+
//# sourceMappingURL=f-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f-distribution.d.ts","sourceRoot":"","sources":["../src/f-distribution.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC5B,yBAAyB,EAAE,MAAM,EACjC,2BAA2B,EAAE,MAAM,GACjC,YAAY,CA4Gd"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { inverseRegularizedIncompleteBeta, logBeta, regularizedIncompleteBeta, } from "@ac-kit/math-analysis";
|
|
2
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
3
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
4
|
+
/**
|
|
5
|
+
* The F distribution — the ratio of two chi-squared variates divided by their
|
|
6
|
+
* degrees of freedom, and the reference distribution of an analysis of
|
|
7
|
+
* variance.
|
|
8
|
+
*
|
|
9
|
+
* Each tail is reached through the incomplete beta on the side where it is
|
|
10
|
+
* small, and the quantile is solved from whichever tail `probability` names, so
|
|
11
|
+
* neither ever hands the beta inverse an argument adjacent to 1.
|
|
12
|
+
*
|
|
13
|
+
* @param numeratorDegreesOfFreedom Positive; need not be an integer.
|
|
14
|
+
* @param denominatorDegreesOfFreedom Positive; need not be an integer.
|
|
15
|
+
* @returns The distribution.
|
|
16
|
+
* @throws {RangeError} When either parameter is not positive.
|
|
17
|
+
*/
|
|
18
|
+
export function fDistribution(numeratorDegreesOfFreedom, denominatorDegreesOfFreedom) {
|
|
19
|
+
if (!(numeratorDegreesOfFreedom > 0)) {
|
|
20
|
+
throw new RangeError(`fDistribution: numeratorDegreesOfFreedom must be positive, got ${numeratorDegreesOfFreedom}`);
|
|
21
|
+
}
|
|
22
|
+
if (!(denominatorDegreesOfFreedom > 0)) {
|
|
23
|
+
throw new RangeError(`fDistribution: denominatorDegreesOfFreedom must be positive, got ${denominatorDegreesOfFreedom}`);
|
|
24
|
+
}
|
|
25
|
+
const halfNumerator = numeratorDegreesOfFreedom / 2;
|
|
26
|
+
const halfDenominator = denominatorDegreesOfFreedom / 2;
|
|
27
|
+
const logNormaliser = logBeta(halfNumerator, halfDenominator);
|
|
28
|
+
const quantile = (probability) => {
|
|
29
|
+
assertProbability_("fDistribution", probability);
|
|
30
|
+
if (probability === 1) {
|
|
31
|
+
return Number.POSITIVE_INFINITY;
|
|
32
|
+
}
|
|
33
|
+
// Solved from the near end: for the upper half the beta inverse is given
|
|
34
|
+
// `1 − probability` against the swapped shapes, so its argument stays small
|
|
35
|
+
// and the ratio below divides by a well-resolved number.
|
|
36
|
+
if (probability > 0.5) {
|
|
37
|
+
const upper = inverseRegularizedIncompleteBeta(halfDenominator, halfNumerator, 1 - probability);
|
|
38
|
+
return ((denominatorDegreesOfFreedom * (1 - upper)) /
|
|
39
|
+
(numeratorDegreesOfFreedom * upper));
|
|
40
|
+
}
|
|
41
|
+
const lower = inverseRegularizedIncompleteBeta(halfNumerator, halfDenominator, probability);
|
|
42
|
+
return ((denominatorDegreesOfFreedom * lower) /
|
|
43
|
+
(numeratorDegreesOfFreedom * (1 - lower)));
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
density: (x) => {
|
|
47
|
+
if (x <= 0) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
const scaled = numeratorDegreesOfFreedom * x;
|
|
51
|
+
const total = scaled + denominatorDegreesOfFreedom;
|
|
52
|
+
return Math.exp(halfNumerator * Math.log(scaled) +
|
|
53
|
+
halfDenominator * Math.log(denominatorDegreesOfFreedom) -
|
|
54
|
+
(halfNumerator + halfDenominator) * Math.log(total) -
|
|
55
|
+
Math.log(x) -
|
|
56
|
+
logNormaliser);
|
|
57
|
+
},
|
|
58
|
+
cdf: (x) => {
|
|
59
|
+
if (x <= 0) {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
const scaled = numeratorDegreesOfFreedom * x;
|
|
63
|
+
return regularizedIncompleteBeta(halfNumerator, halfDenominator, scaled / (scaled + denominatorDegreesOfFreedom));
|
|
64
|
+
},
|
|
65
|
+
survival: (x) => {
|
|
66
|
+
if (x <= 0) {
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
const scaled = numeratorDegreesOfFreedom * x;
|
|
70
|
+
return regularizedIncompleteBeta(halfDenominator, halfNumerator, denominatorDegreesOfFreedom / (scaled + denominatorDegreesOfFreedom));
|
|
71
|
+
},
|
|
72
|
+
quantile,
|
|
73
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
74
|
+
mean: denominatorDegreesOfFreedom > 2
|
|
75
|
+
? denominatorDegreesOfFreedom / (denominatorDegreesOfFreedom - 2)
|
|
76
|
+
: Number.NaN,
|
|
77
|
+
variance: denominatorDegreesOfFreedom > 4
|
|
78
|
+
? (2 *
|
|
79
|
+
denominatorDegreesOfFreedom *
|
|
80
|
+
denominatorDegreesOfFreedom *
|
|
81
|
+
(numeratorDegreesOfFreedom + denominatorDegreesOfFreedom - 2)) /
|
|
82
|
+
(numeratorDegreesOfFreedom *
|
|
83
|
+
(denominatorDegreesOfFreedom - 2) ** 2 *
|
|
84
|
+
(denominatorDegreesOfFreedom - 4))
|
|
85
|
+
: Number.NaN,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=f-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f-distribution.js","sourceRoot":"","sources":["../src/f-distribution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gCAAgC,EAChC,OAAO,EACP,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC5B,yBAAiC,EACjC,2BAAmC;IAEnC,IAAI,CAAC,CAAC,yBAAyB,GAAG,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CACnB,kEAAkE,yBAAyB,EAAE,CAC7F,CAAC;IACH,CAAC;IACD,IAAI,CAAC,CAAC,2BAA2B,GAAG,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,UAAU,CACnB,oEAAoE,2BAA2B,EAAE,CACjG,CAAC;IACH,CAAC;IAED,MAAM,aAAa,GAAG,yBAAyB,GAAG,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,2BAA2B,GAAG,CAAC,CAAC;IACxD,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;IAE9D,MAAM,QAAQ,GAAG,CAAC,WAAmB,EAAE,EAAE;QACxC,kBAAkB,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAEjD,IAAI,WAAW,KAAK,CAA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;YACV,CAAC;YACD,MAAM,MAAM,GAAG,yBAAyB,GAAG,CAAC,CAAC;YAE7C,OAAO,yBAAyB,CAC/B,aAAa,EACb,eAAe,EACf,MAAM,GAAG,CAAC,MAAM,GAAG,2BAA2B,CAAC,CAC/C,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;YACf,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACZ,OAAO,CAAC,CAAC;YACV,CAAC;YACD,MAAM,MAAM,GAAG,yBAAyB,GAAG,CAAC,CAAC;YAE7C,OAAO,yBAAyB,CAC/B,eAAe,EACf,aAAa,EACb,2BAA2B,GAAG,CAAC,MAAM,GAAG,2BAA2B,CAAC,CACpE,CAAC;QACH,CAAC;QACD,QAAQ;QACR,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC7D,IAAI,EACH,2BAA2B,GAAG,CAAC;YAC9B,CAAC,CAAC,2BAA2B,GAAG,CAAC,2BAA2B,GAAG,CAAC,CAAC;YACjE,CAAC,CAAC,MAAM,CAAC,GAAG;QACd,QAAQ,EACP,2BAA2B,GAAG,CAAC;YAC9B,CAAC,CAAC,CAAC,CAAC;gBACF,2BAA2B;gBAC3B,2BAA2B;gBAC3B,CAAC,yBAAyB,GAAG,2BAA2B,GAAG,CAAC,CAAC,CAAC;gBAC/D,CAAC,yBAAyB;oBACzB,CAAC,2BAA2B,GAAG,CAAC,CAAC,IAAI,CAAC;oBACtC,CAAC,2BAA2B,GAAG,CAAC,CAAC,CAAC;YACpC,CAAC,CAAC,MAAM,CAAC,GAAG;KACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* The gamma distribution, parameterised by shape and **rate**.
|
|
4
|
+
*
|
|
5
|
+
* Rate rather than scale, so that `gammaDistribution(1, r)` is the same
|
|
6
|
+
* distribution as `exponentialDistribution(r)` and the two agree on what their
|
|
7
|
+
* second argument means. Scale is its reciprocal.
|
|
8
|
+
*
|
|
9
|
+
* @param shape Shape parameter `k`; must be positive.
|
|
10
|
+
* @param rate Rate parameter `λ`; must be positive.
|
|
11
|
+
* @returns The distribution.
|
|
12
|
+
* @throws {RangeError} When either parameter is not positive.
|
|
13
|
+
*/
|
|
14
|
+
export declare function gammaDistribution(shape: number, rate?: number): Distribution;
|
|
15
|
+
//# sourceMappingURL=gamma-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamma-distribution.d.ts","sourceRoot":"","sources":["../src/gamma-distribution.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,YAAY,CAuCvE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { inverseRegularizedIncompleteGamma, logGamma, regularizedIncompleteGamma, regularizedIncompleteGammaUpper, } from "@ac-kit/math-analysis";
|
|
2
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
3
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
4
|
+
/**
|
|
5
|
+
* The gamma distribution, parameterised by shape and **rate**.
|
|
6
|
+
*
|
|
7
|
+
* Rate rather than scale, so that `gammaDistribution(1, r)` is the same
|
|
8
|
+
* distribution as `exponentialDistribution(r)` and the two agree on what their
|
|
9
|
+
* second argument means. Scale is its reciprocal.
|
|
10
|
+
*
|
|
11
|
+
* @param shape Shape parameter `k`; must be positive.
|
|
12
|
+
* @param rate Rate parameter `λ`; must be positive.
|
|
13
|
+
* @returns The distribution.
|
|
14
|
+
* @throws {RangeError} When either parameter is not positive.
|
|
15
|
+
*/
|
|
16
|
+
export function gammaDistribution(shape, rate = 1) {
|
|
17
|
+
if (!(shape > 0)) {
|
|
18
|
+
throw new RangeError(`gammaDistribution: shape must be positive, got ${shape}`);
|
|
19
|
+
}
|
|
20
|
+
if (!(rate > 0)) {
|
|
21
|
+
throw new RangeError(`gammaDistribution: rate must be positive, got ${rate}`);
|
|
22
|
+
}
|
|
23
|
+
const quantile = (probability) => {
|
|
24
|
+
assertProbability_("gammaDistribution", probability);
|
|
25
|
+
return inverseRegularizedIncompleteGamma(shape, probability) / rate;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
density: (x) => {
|
|
29
|
+
if (x < 0) {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
if (x === 0) {
|
|
33
|
+
return shape < 1 ? Number.POSITIVE_INFINITY : shape === 1 ? rate : 0;
|
|
34
|
+
}
|
|
35
|
+
return (Math.exp(shape * Math.log(rate * x) - rate * x - logGamma(shape)) / x);
|
|
36
|
+
},
|
|
37
|
+
cdf: (x) => (x <= 0 ? 0 : regularizedIncompleteGamma(shape, rate * x)),
|
|
38
|
+
survival: (x) => x <= 0 ? 1 : regularizedIncompleteGammaUpper(shape, rate * x),
|
|
39
|
+
quantile,
|
|
40
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
41
|
+
mean: shape / rate,
|
|
42
|
+
variance: shape / (rate * rate),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=gamma-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamma-distribution.js","sourceRoot":"","sources":["../src/gamma-distribution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iCAAiC,EACjC,QAAQ,EACR,0BAA0B,EAC1B,+BAA+B,GAC/B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAA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EAAE,EAAE,CACf,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,+BAA+B,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC;QAC9D,QAAQ;QACR,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC7D,IAAI,EAAE,KAAK,GAAG,IAAI;QAClB,QAAQ,EAAE,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;KAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* The geometric distribution — the number of **failures** before the first
|
|
4
|
+
* success.
|
|
5
|
+
*
|
|
6
|
+
* The support therefore starts at 0, not 1. That is the convention under which
|
|
7
|
+
* `geometricDistribution(p)` and `negativeBinomialDistribution(1, p)` are the
|
|
8
|
+
* same distribution; libraries counting trials instead give an answer one
|
|
9
|
+
* larger throughout.
|
|
10
|
+
*
|
|
11
|
+
* Every member has a closed form, `quantile` included, so none of them
|
|
12
|
+
* iterates.
|
|
13
|
+
*
|
|
14
|
+
* @param probability Success probability of one attempt, in `(0, 1]`.
|
|
15
|
+
* @returns The distribution.
|
|
16
|
+
* @throws {RangeError} When `probability` is outside `(0, 1]`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function geometricDistribution(probability: number): Distribution;
|
|
19
|
+
//# sourceMappingURL=geometric-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometric-distribution.d.ts","sourceRoot":"","sources":["../src/geometric-distribution.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CA4CvE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
2
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
3
|
+
/**
|
|
4
|
+
* The geometric distribution — the number of **failures** before the first
|
|
5
|
+
* success.
|
|
6
|
+
*
|
|
7
|
+
* The support therefore starts at 0, not 1. That is the convention under which
|
|
8
|
+
* `geometricDistribution(p)` and `negativeBinomialDistribution(1, p)` are the
|
|
9
|
+
* same distribution; libraries counting trials instead give an answer one
|
|
10
|
+
* larger throughout.
|
|
11
|
+
*
|
|
12
|
+
* Every member has a closed form, `quantile` included, so none of them
|
|
13
|
+
* iterates.
|
|
14
|
+
*
|
|
15
|
+
* @param probability Success probability of one attempt, in `(0, 1]`.
|
|
16
|
+
* @returns The distribution.
|
|
17
|
+
* @throws {RangeError} When `probability` is outside `(0, 1]`.
|
|
18
|
+
*/
|
|
19
|
+
export function geometricDistribution(probability) {
|
|
20
|
+
if (!(probability > 0 && probability <= 1)) {
|
|
21
|
+
throw new RangeError(`geometricDistribution: probability must be in (0, 1], got ${probability}`);
|
|
22
|
+
}
|
|
23
|
+
/** `ln(1 − p)`, the log of one failure, taken accurately for small `p`. */
|
|
24
|
+
const logFailure = Math.log1p(-probability);
|
|
25
|
+
const quantile = (target) => {
|
|
26
|
+
assertProbability_("geometricDistribution", target);
|
|
27
|
+
if (probability === 1) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
if (target >= 1) {
|
|
31
|
+
return Number.POSITIVE_INFINITY;
|
|
32
|
+
}
|
|
33
|
+
// Smallest k with 1 − (1 − p)^(k+1) ≥ target, solved rather than searched.
|
|
34
|
+
return Math.max(0, Math.ceil(Math.log1p(-target) / logFailure) - 1);
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
density: (x) => Number.isInteger(x) && x >= 0
|
|
38
|
+
? Math.exp(x * logFailure) * probability
|
|
39
|
+
: 0,
|
|
40
|
+
cdf: (x) => {
|
|
41
|
+
const failures = Math.floor(x);
|
|
42
|
+
return failures < 0 ? 0 : -Math.expm1((failures + 1) * logFailure);
|
|
43
|
+
},
|
|
44
|
+
survival: (x) => {
|
|
45
|
+
const failures = Math.floor(x);
|
|
46
|
+
return failures < 0 ? 1 : Math.exp((failures + 1) * logFailure);
|
|
47
|
+
},
|
|
48
|
+
quantile,
|
|
49
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
50
|
+
mean: (1 - probability) / probability,
|
|
51
|
+
variance: (1 - probability) / (probability * probability),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=geometric-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometric-distribution.js","sourceRoot":"","sources":["../src/geometric-distribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAmB;IACxD,IAAI,CAAC,CAAC,WAAW,GAAG,CAAC,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,UAAU,CACnB,6DAA6D,WAAW,EAAE,CAC1E,CAAC;IACH,CAAC;IAED,2EAA2E;IAC3E,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC;IAE5C,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE;QACnC,kBAAkB,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;QAEpD,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,CAAC;QACV,CAAC;QACD,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YACjB,OAAO,MAAM,CAAC,iBAAiB,CAAC;QACjC,CAAC;QAED,2EAA2E;QAC3E,OAAO,IAAI,CAAC,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+
/**
|
|
2
|
+
* Linkage criterion for computing inter-cluster distances.
|
|
3
|
+
*
|
|
4
|
+
* - `"single"` — minimum pairwise distance. Prone to chaining.
|
|
5
|
+
* - `"average"` — mean pairwise distance (UPGMA). Balanced; default.
|
|
6
|
+
* - `"complete"` — maximum pairwise distance. Compact clusters; eliminates
|
|
7
|
+
* chaining.
|
|
8
|
+
* - `"ward"` — minimises the increase in total within-cluster variance (Ward's
|
|
9
|
+
* minimum-variance criterion). The threshold is in Ward-distance units
|
|
10
|
+
* (√ΔTWCSS), which differ from the raw distance units of `getDistance`.
|
|
11
|
+
*/
|
|
12
|
+
export type HierarchicalLinkage = "single" | "average" | "complete" | "ward";
|
|
13
|
+
export type HierarchicalClusterOptions = {
|
|
14
|
+
linkage?: HierarchicalLinkage;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Agglomerative hierarchical clustering with selectable linkage.
|
|
18
|
+
*
|
|
19
|
+
* Pre-computes a full n×n pairwise distance matrix and uses the Lance–Williams
|
|
20
|
+
* recurrence to update inter-cluster distances after each merge — O(n) per
|
|
21
|
+
* merge instead of recomputing from raw point pairs.
|
|
22
|
+
*
|
|
23
|
+
* Complexity: O(n²) space; O(n³) time in the worst case (n−1 merges × O(n²)
|
|
24
|
+
* scan). Acceptable for n up to a few hundred (e.g. palette entries across a
|
|
25
|
+
* gallery).
|
|
26
|
+
*
|
|
27
|
+
* @param n Number of items (indexed 0 … n-1).
|
|
28
|
+
* @param getDistance Pairwise distance between original items by index.
|
|
29
|
+
* @param threshold Merge threshold: cluster pairs whose inter-cluster distance
|
|
30
|
+
* is ≥ this value are not merged.
|
|
31
|
+
* @param options Optional linkage selection. Default: `"average"`.
|
|
32
|
+
* @returns Array of clusters; each cluster is an array of original indices.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hierarchicalCluster(n: number, getDistance: (i: number, j: number) => number, threshold: number, options?: HierarchicalClusterOptions): number[][];
|
|
35
|
+
//# sourceMappingURL=hierarchical-cluster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical-cluster.d.ts","sourceRoot":"","sources":["../src/hierarchical-cluster.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC;AAE7E,MAAM,MAAM,0BAA0B,GAAG;IACxC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAClC,CAAC,EAAE,MAAM,EACT,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,EAC7C,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,0BAA0B,GAClC,MAAM,EAAE,EAAE,CAuFZ"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { dotPrecise } from "@ac-kit/math-scalar";
|
|
2
|
+
/**
|
|
3
|
+
* Agglomerative hierarchical clustering with selectable linkage.
|
|
4
|
+
*
|
|
5
|
+
* Pre-computes a full n×n pairwise distance matrix and uses the Lance–Williams
|
|
6
|
+
* recurrence to update inter-cluster distances after each merge — O(n) per
|
|
7
|
+
* merge instead of recomputing from raw point pairs.
|
|
8
|
+
*
|
|
9
|
+
* Complexity: O(n²) space; O(n³) time in the worst case (n−1 merges × O(n²)
|
|
10
|
+
* scan). Acceptable for n up to a few hundred (e.g. palette entries across a
|
|
11
|
+
* gallery).
|
|
12
|
+
*
|
|
13
|
+
* @param n Number of items (indexed 0 … n-1).
|
|
14
|
+
* @param getDistance Pairwise distance between original items by index.
|
|
15
|
+
* @param threshold Merge threshold: cluster pairs whose inter-cluster distance
|
|
16
|
+
* is ≥ this value are not merged.
|
|
17
|
+
* @param options Optional linkage selection. Default: `"average"`.
|
|
18
|
+
* @returns Array of clusters; each cluster is an array of original indices.
|
|
19
|
+
*/
|
|
20
|
+
export function hierarchicalCluster(n, getDistance, threshold, options) {
|
|
21
|
+
if (n === 0)
|
|
22
|
+
return [];
|
|
23
|
+
const linkage = options?.linkage ?? "average";
|
|
24
|
+
// Build a symmetric n×n distance matrix.
|
|
25
|
+
// clusterDist[i][j] holds the current inter-cluster distance (same value at [j][i]).
|
|
26
|
+
const clusterDist = Array.from({ length: n }, () => Array.from({ length: n }).fill(0));
|
|
27
|
+
for (let i = 0; i < n; i++) {
|
|
28
|
+
for (let j = i + 1; j < n; j++) {
|
|
29
|
+
const rawDist = getDistance(i, j);
|
|
30
|
+
// Ward's singleton distance is rawDist / √2 (= √(½ · d²), the TWCSS increase for two singletons).
|
|
31
|
+
const d = linkage === "ward" ? rawDist / Math.SQRT2 : rawDist;
|
|
32
|
+
clusterDist[i][j] = d;
|
|
33
|
+
clusterDist[j][i] = d;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const sizes = Array.from({ length: n }).fill(1);
|
|
37
|
+
const members = Array.from({ length: n }, (_, i) => [i]);
|
|
38
|
+
const active = Array.from({ length: n }).fill(true);
|
|
39
|
+
for (let step = 0; step < n - 1; step++) {
|
|
40
|
+
// Find the active pair with the smallest inter-cluster distance.
|
|
41
|
+
let minDist = Infinity;
|
|
42
|
+
let mergeA = -1;
|
|
43
|
+
let mergeB = -1;
|
|
44
|
+
for (let i = 0; i < n; i++) {
|
|
45
|
+
if (!active[i])
|
|
46
|
+
continue;
|
|
47
|
+
for (let j = i + 1; j < n; j++) {
|
|
48
|
+
if (!active[j])
|
|
49
|
+
continue;
|
|
50
|
+
const d = clusterDist[i][j];
|
|
51
|
+
if (d < minDist) {
|
|
52
|
+
minDist = d;
|
|
53
|
+
mergeA = i;
|
|
54
|
+
mergeB = j;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (mergeA === -1 || minDist >= threshold)
|
|
59
|
+
break;
|
|
60
|
+
const nA = sizes[mergeA];
|
|
61
|
+
const nB = sizes[mergeB];
|
|
62
|
+
const dAB = clusterDist[mergeA][mergeB];
|
|
63
|
+
// Update distances from the merged cluster (mergeA absorbs mergeB) to all remaining
|
|
64
|
+
// active clusters using the Lance–Williams recurrence for the chosen linkage.
|
|
65
|
+
for (let c = 0; c < n; c++) {
|
|
66
|
+
if (!active[c] || c === mergeA || c === mergeB)
|
|
67
|
+
continue;
|
|
68
|
+
const nC = sizes[c];
|
|
69
|
+
const dAC = clusterDist[mergeA][c];
|
|
70
|
+
const dBC = clusterDist[mergeB][c];
|
|
71
|
+
let newDist;
|
|
72
|
+
if (linkage === "single") {
|
|
73
|
+
newDist = Math.min(dAC, dBC);
|
|
74
|
+
}
|
|
75
|
+
else if (linkage === "complete") {
|
|
76
|
+
newDist = Math.max(dAC, dBC);
|
|
77
|
+
}
|
|
78
|
+
else if (linkage === "average") {
|
|
79
|
+
newDist = (nA * dAC + nB * dBC) / (nA + nB);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Ward's recurrence: apply weights to squared Ward distances, then take sqrt.
|
|
83
|
+
// The result is mathematically non-negative; max(0,…) guards against FP underflow.
|
|
84
|
+
const nABC = nA + nB + nC;
|
|
85
|
+
const wardSq = dotPrecise([(nA + nC) * dAC, (nB + nC) * dBC, -(nC * dAB)], [dAC, dBC, dAB]) / nABC;
|
|
86
|
+
newDist = Math.sqrt(Math.max(0, wardSq));
|
|
87
|
+
}
|
|
88
|
+
clusterDist[mergeA][c] = newDist;
|
|
89
|
+
clusterDist[c][mergeA] = newDist;
|
|
90
|
+
}
|
|
91
|
+
sizes[mergeA] = nA + nB;
|
|
92
|
+
members[mergeA] = [...members[mergeA], ...members[mergeB]];
|
|
93
|
+
active[mergeB] = false;
|
|
94
|
+
}
|
|
95
|
+
return members.filter((_, i) => active[i]);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=hierarchical-cluster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical-cluster.js","source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E,GAAG,GAAG,CAAC,CAAC,EAC/C,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CACf,GAAG,IAAI,CAAC;gBACV,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAC1C,CAAC;YAED,WAAW,CAAC,MAAM,CAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;YAClC,WAAW,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;QACnC,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;QACxB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAE,CAAC,CAAC;QAC7D,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* The hypergeometric distribution — successes drawn without replacement.
|
|
4
|
+
*
|
|
5
|
+
* The only family here with no closed form for its tails: unlike the binomial,
|
|
6
|
+
* whose sampling-with-replacement counterpart collapses into an incomplete
|
|
7
|
+
* beta, this one has to be summed. Each tail is summed from its **own** end
|
|
8
|
+
* inward, so every term is positive and nothing is reached by subtracting a
|
|
9
|
+
* near-one value from one.
|
|
10
|
+
*
|
|
11
|
+
* @param population Total size `N`; a non-negative integer.
|
|
12
|
+
* @param successes Successes in the population `K`; in `[0, N]`.
|
|
13
|
+
* @param draws Number drawn `n`; in `[0, N]`.
|
|
14
|
+
* @returns The distribution.
|
|
15
|
+
* @throws {RangeError} When any argument is not an integer in range.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hypergeometricDistribution(population: number, successes: number, draws: number): Distribution;
|
|
18
|
+
//# sourceMappingURL=hypergeometric-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypergeometric-distribution.d.ts","sourceRoot":"","sources":["../src/hypergeometric-distribution.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACzC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACX,YAAY,CAyFd"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PreciseSum } from "@ac-kit/core";
|
|
2
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
3
|
+
import { discreteQuantile_ } from "./_discrete-quantile.js";
|
|
4
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
5
|
+
import { logBinomial_ } from "./_log-binomial.js";
|
|
6
|
+
/**
|
|
7
|
+
* The hypergeometric distribution — successes drawn without replacement.
|
|
8
|
+
*
|
|
9
|
+
* The only family here with no closed form for its tails: unlike the binomial,
|
|
10
|
+
* whose sampling-with-replacement counterpart collapses into an incomplete
|
|
11
|
+
* beta, this one has to be summed. Each tail is summed from its **own** end
|
|
12
|
+
* inward, so every term is positive and nothing is reached by subtracting a
|
|
13
|
+
* near-one value from one.
|
|
14
|
+
*
|
|
15
|
+
* @param population Total size `N`; a non-negative integer.
|
|
16
|
+
* @param successes Successes in the population `K`; in `[0, N]`.
|
|
17
|
+
* @param draws Number drawn `n`; in `[0, N]`.
|
|
18
|
+
* @returns The distribution.
|
|
19
|
+
* @throws {RangeError} When any argument is not an integer in range.
|
|
20
|
+
*/
|
|
21
|
+
export function hypergeometricDistribution(population, successes, draws) {
|
|
22
|
+
for (const [name, value] of [
|
|
23
|
+
["population", population],
|
|
24
|
+
["successes", successes],
|
|
25
|
+
["draws", draws],
|
|
26
|
+
]) {
|
|
27
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
28
|
+
throw new RangeError(`hypergeometricDistribution: ${name} must be a non-negative integer, got ${value}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (successes > population || draws > population) {
|
|
32
|
+
throw new RangeError(`hypergeometricDistribution: successes and draws must not exceed population ${population}`);
|
|
33
|
+
}
|
|
34
|
+
const lowest = Math.max(0, draws + successes - population);
|
|
35
|
+
const highest = Math.min(draws, successes);
|
|
36
|
+
const logTotal = logBinomial_(population, draws);
|
|
37
|
+
const density = (x) => {
|
|
38
|
+
if (!Number.isInteger(x) || x < lowest || x > highest) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
return Math.exp(logBinomial_(successes, x) +
|
|
42
|
+
logBinomial_(population - successes, draws - x) -
|
|
43
|
+
logTotal);
|
|
44
|
+
};
|
|
45
|
+
/** Sums the mass over an inclusive run of outcomes. */
|
|
46
|
+
const massBetween = (from, to) => {
|
|
47
|
+
const total = new PreciseSum();
|
|
48
|
+
for (let outcome = from; outcome <= to; outcome++) {
|
|
49
|
+
total.add(density(outcome));
|
|
50
|
+
}
|
|
51
|
+
return total.value;
|
|
52
|
+
};
|
|
53
|
+
const cdf = (x) => {
|
|
54
|
+
const drawn = Math.floor(x);
|
|
55
|
+
if (drawn < lowest) {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
if (drawn >= highest) {
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
return massBetween(lowest, drawn);
|
|
62
|
+
};
|
|
63
|
+
const quantile = (probability) => {
|
|
64
|
+
assertProbability_("hypergeometricDistribution", probability);
|
|
65
|
+
return discreteQuantile_(cdf, probability, lowest, highest);
|
|
66
|
+
};
|
|
67
|
+
const successRate = successes / population;
|
|
68
|
+
return {
|
|
69
|
+
density,
|
|
70
|
+
cdf,
|
|
71
|
+
survival: (x) => {
|
|
72
|
+
const drawn = Math.floor(x);
|
|
73
|
+
if (drawn < lowest) {
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
if (drawn >= highest) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
return massBetween(drawn + 1, highest);
|
|
80
|
+
},
|
|
81
|
+
quantile,
|
|
82
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
83
|
+
mean: draws * successRate,
|
|
84
|
+
variance: population > 1
|
|
85
|
+
? draws *
|
|
86
|
+
successRate *
|
|
87
|
+
(1 - successRate) *
|
|
88
|
+
((population - draws) / (population - 1))
|
|
89
|
+
: 0,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=hypergeometric-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypergeometric-distribution.js","sourceRoot":"","sources":["../src/hypergeometric-distribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0BAA0B,CACzC,UAAkB,EAClB,SAAiB,EACjB,KAAa;IAEb,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI;QAC3B,CAAC,YAAY,EAAE,UAAU,CAAC;QAC1B,CAAC,WAAW,EAAE,SAAS,CAAC;QACxB,CAAC,OAAO,EAAE,KAAK,CAAC;KACP,EAAE,CAAC;QACZ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE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AK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;KACL,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from "./average.js";
|
|
2
|
+
export * from "./beta-distribution.js";
|
|
3
|
+
export * from "./binomial-distribution.js";
|
|
4
|
+
export * from "./chi-squared-distribution.js";
|
|
5
|
+
export * from "./chi-squared-test.js";
|
|
6
|
+
export * from "./confidence-interval.js";
|
|
7
|
+
export * from "./dispersion.js";
|
|
8
|
+
export * from "./distribution.js";
|
|
9
|
+
export * from "./exponential-distribution.js";
|
|
10
|
+
export * from "./f-distribution.js";
|
|
11
|
+
export * from "./gamma-distribution.js";
|
|
12
|
+
export * from "./geometric-distribution.js";
|
|
13
|
+
export * from "./hierarchical-cluster.js";
|
|
14
|
+
export * from "./hypergeometric-distribution.js";
|
|
15
|
+
export * from "./kmeans.js";
|
|
16
|
+
export * from "./kmedoids.js";
|
|
17
|
+
export * from "./log-normal-distribution.js";
|
|
18
|
+
export * from "./negative-binomial-distribution.js";
|
|
19
|
+
export * from "./normal-distribution.js";
|
|
20
|
+
export * from "./normal-quantile.js";
|
|
21
|
+
export * from "./one-way-anova.js";
|
|
22
|
+
export * from "./outliers.js";
|
|
23
|
+
export * from "./poisson-distribution.js";
|
|
24
|
+
export * from "./quantile.js";
|
|
25
|
+
export * from "./random-effects.js";
|
|
26
|
+
export * from "./regression.js";
|
|
27
|
+
export * from "./student-t-distribution.js";
|
|
28
|
+
export * from "./sum.js";
|
|
29
|
+
export * from "./t-test.js";
|
|
30
|
+
export * from "./trend.js";
|
|
31
|
+
export * from "./uncertainty.js";
|
|
32
|
+
export * from "./uniform-distribution.js";
|
|
33
|
+
export * from "./welch-t-statistic.js";
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC"}
|