@rgsoft/stats 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/index.cjs +486 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +179 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.mjs +452 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
declare function erf(z: number): number;
|
|
2
|
+
|
|
3
|
+
interface Distribution {
|
|
4
|
+
/** Cumulative distribution function: P(X ≤ x) */
|
|
5
|
+
getAccumulated(x: number): number;
|
|
6
|
+
/** Expected value (mean) of the distribution */
|
|
7
|
+
getMean(): number;
|
|
8
|
+
/** Returns the variance if applicable */
|
|
9
|
+
getVariance?(): number;
|
|
10
|
+
/** Returns the standard deviation if applicable */
|
|
11
|
+
getStdDev?(): number;
|
|
12
|
+
/** Generate a random value following this distribution */
|
|
13
|
+
sample(): number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents a continuous probability distribution function (PDF).
|
|
18
|
+
*
|
|
19
|
+
* A PDF defines how the probability density of a continuous random variable
|
|
20
|
+
* is distributed over its domain. This interface provides methods for
|
|
21
|
+
* evaluating the density, cumulative distribution, and sampling values
|
|
22
|
+
* from the distribution.
|
|
23
|
+
*
|
|
24
|
+
* All implementations should ensure that the total integral of the density
|
|
25
|
+
* function over its domain equals 1.
|
|
26
|
+
*/
|
|
27
|
+
interface PDF extends Distribution {
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates the probability density function (PDF) at a given value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @param x - The point at which to evaluate the density.
|
|
32
|
+
* @returns The probability density at `x`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const gaussian = new Gaussian(0, 1);
|
|
37
|
+
* gaussian.density(0); // ≈ 0.3989
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
density(x: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Computes the quantile (inverse CDF) for a given probability `p`.
|
|
43
|
+
*
|
|
44
|
+
* The quantile function returns the value `x` such that `P(X ≤ x) = p`.
|
|
45
|
+
* Not all distributions have a closed-form quantile function; in such
|
|
46
|
+
* cases, implementations may use a numerical approximation or omit
|
|
47
|
+
* this method.
|
|
48
|
+
*
|
|
49
|
+
* @param p - The cumulative probability (0 ≤ p ≤ 1).
|
|
50
|
+
* @returns The value `x` such that the cumulative probability equals `p`.
|
|
51
|
+
*
|
|
52
|
+
* @throws If `p` is outside the range [0, 1].
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const gaussian = new Gaussian(0, 1);
|
|
57
|
+
* gaussian.quantile(0.975); // ≈ 1.96
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
quantile?(p: number): number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare class Exponential implements PDF {
|
|
64
|
+
private readonly mean;
|
|
65
|
+
private readonly lambda;
|
|
66
|
+
constructor(mean: number);
|
|
67
|
+
getAccumulated(x: number): number;
|
|
68
|
+
sample(): number;
|
|
69
|
+
getMean(): number;
|
|
70
|
+
density(x: number): number;
|
|
71
|
+
getVariance(): number;
|
|
72
|
+
getStdDev(): number;
|
|
73
|
+
quantile(p: number): number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare class Gaussian implements PDF {
|
|
77
|
+
readonly mean: number;
|
|
78
|
+
readonly variance: number;
|
|
79
|
+
readonly stdDev: number;
|
|
80
|
+
constructor(mean?: number, variance?: number);
|
|
81
|
+
getAccumulated(x: number): number;
|
|
82
|
+
quantile(p: number): number;
|
|
83
|
+
getMean(): number;
|
|
84
|
+
sample(): number;
|
|
85
|
+
density(x: number): number;
|
|
86
|
+
getVariance(): number;
|
|
87
|
+
getStdDev(): number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class Uniform implements PDF {
|
|
91
|
+
readonly min: number;
|
|
92
|
+
readonly max: number;
|
|
93
|
+
private readonly diff;
|
|
94
|
+
constructor(min: number, max: number);
|
|
95
|
+
getAccumulated(x: number): number;
|
|
96
|
+
getMean(): number;
|
|
97
|
+
sample(): number;
|
|
98
|
+
density(x: number): number;
|
|
99
|
+
getVariance(): number;
|
|
100
|
+
getStdDev(): number;
|
|
101
|
+
quantile(p: number): number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface PMF extends Distribution {
|
|
105
|
+
probability(x: number): number;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
declare class Binomial implements PMF {
|
|
109
|
+
private readonly n;
|
|
110
|
+
private readonly p;
|
|
111
|
+
private readonly probabilities;
|
|
112
|
+
private readonly accumulative;
|
|
113
|
+
private readonly variance;
|
|
114
|
+
private readonly stdDev;
|
|
115
|
+
constructor(n: number, p: number);
|
|
116
|
+
getAccumulated(x: number): number;
|
|
117
|
+
sample(): number;
|
|
118
|
+
getMean(): number;
|
|
119
|
+
getVariance(): number;
|
|
120
|
+
getStdDev(): number;
|
|
121
|
+
probability(x: number): number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare class NegativeBinomial implements PMF {
|
|
125
|
+
private readonly r;
|
|
126
|
+
private readonly p;
|
|
127
|
+
private readonly accumulative;
|
|
128
|
+
private readonly mean;
|
|
129
|
+
private readonly variance;
|
|
130
|
+
private readonly stdDev;
|
|
131
|
+
constructor(r: number, p: number);
|
|
132
|
+
getAccumulated(x: number): number;
|
|
133
|
+
getMean(): number;
|
|
134
|
+
getVariance(): number;
|
|
135
|
+
getStdDev(): number;
|
|
136
|
+
sample(): number;
|
|
137
|
+
probability(x: number): number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
declare class Poisson implements PMF {
|
|
141
|
+
private readonly l;
|
|
142
|
+
private readonly accumulative;
|
|
143
|
+
private readonly mean;
|
|
144
|
+
private readonly variance;
|
|
145
|
+
private readonly stdDev;
|
|
146
|
+
constructor(l: number);
|
|
147
|
+
getAccumulated(x: number): number;
|
|
148
|
+
sample(): number;
|
|
149
|
+
getMean(): number;
|
|
150
|
+
getVariance(): number;
|
|
151
|
+
getStdDev(): number;
|
|
152
|
+
probability(x: number): number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare class Stats {
|
|
156
|
+
private readonly orderedData;
|
|
157
|
+
private readonly data;
|
|
158
|
+
private _mean?;
|
|
159
|
+
private _variance?;
|
|
160
|
+
private _stdDev?;
|
|
161
|
+
private _q1?;
|
|
162
|
+
private _q2?;
|
|
163
|
+
private _q3?;
|
|
164
|
+
private _normalized?;
|
|
165
|
+
private _zScores?;
|
|
166
|
+
constructor(data: number[]);
|
|
167
|
+
get mean(): number;
|
|
168
|
+
get median(): number;
|
|
169
|
+
get variance(): number;
|
|
170
|
+
get stdDev(): number;
|
|
171
|
+
get q1(): number;
|
|
172
|
+
get q2(): number;
|
|
173
|
+
get q3(): number;
|
|
174
|
+
get zScores(): number[];
|
|
175
|
+
get normalized(): number[];
|
|
176
|
+
private percentile;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { Binomial, Exponential, Gaussian, NegativeBinomial, Poisson, Stats, Uniform, erf };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
declare function erf(z: number): number;
|
|
2
|
+
|
|
3
|
+
interface Distribution {
|
|
4
|
+
/** Cumulative distribution function: P(X ≤ x) */
|
|
5
|
+
getAccumulated(x: number): number;
|
|
6
|
+
/** Expected value (mean) of the distribution */
|
|
7
|
+
getMean(): number;
|
|
8
|
+
/** Returns the variance if applicable */
|
|
9
|
+
getVariance?(): number;
|
|
10
|
+
/** Returns the standard deviation if applicable */
|
|
11
|
+
getStdDev?(): number;
|
|
12
|
+
/** Generate a random value following this distribution */
|
|
13
|
+
sample(): number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents a continuous probability distribution function (PDF).
|
|
18
|
+
*
|
|
19
|
+
* A PDF defines how the probability density of a continuous random variable
|
|
20
|
+
* is distributed over its domain. This interface provides methods for
|
|
21
|
+
* evaluating the density, cumulative distribution, and sampling values
|
|
22
|
+
* from the distribution.
|
|
23
|
+
*
|
|
24
|
+
* All implementations should ensure that the total integral of the density
|
|
25
|
+
* function over its domain equals 1.
|
|
26
|
+
*/
|
|
27
|
+
interface PDF extends Distribution {
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates the probability density function (PDF) at a given value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @param x - The point at which to evaluate the density.
|
|
32
|
+
* @returns The probability density at `x`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const gaussian = new Gaussian(0, 1);
|
|
37
|
+
* gaussian.density(0); // ≈ 0.3989
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
density(x: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Computes the quantile (inverse CDF) for a given probability `p`.
|
|
43
|
+
*
|
|
44
|
+
* The quantile function returns the value `x` such that `P(X ≤ x) = p`.
|
|
45
|
+
* Not all distributions have a closed-form quantile function; in such
|
|
46
|
+
* cases, implementations may use a numerical approximation or omit
|
|
47
|
+
* this method.
|
|
48
|
+
*
|
|
49
|
+
* @param p - The cumulative probability (0 ≤ p ≤ 1).
|
|
50
|
+
* @returns The value `x` such that the cumulative probability equals `p`.
|
|
51
|
+
*
|
|
52
|
+
* @throws If `p` is outside the range [0, 1].
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const gaussian = new Gaussian(0, 1);
|
|
57
|
+
* gaussian.quantile(0.975); // ≈ 1.96
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
quantile?(p: number): number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare class Exponential implements PDF {
|
|
64
|
+
private readonly mean;
|
|
65
|
+
private readonly lambda;
|
|
66
|
+
constructor(mean: number);
|
|
67
|
+
getAccumulated(x: number): number;
|
|
68
|
+
sample(): number;
|
|
69
|
+
getMean(): number;
|
|
70
|
+
density(x: number): number;
|
|
71
|
+
getVariance(): number;
|
|
72
|
+
getStdDev(): number;
|
|
73
|
+
quantile(p: number): number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare class Gaussian implements PDF {
|
|
77
|
+
readonly mean: number;
|
|
78
|
+
readonly variance: number;
|
|
79
|
+
readonly stdDev: number;
|
|
80
|
+
constructor(mean?: number, variance?: number);
|
|
81
|
+
getAccumulated(x: number): number;
|
|
82
|
+
quantile(p: number): number;
|
|
83
|
+
getMean(): number;
|
|
84
|
+
sample(): number;
|
|
85
|
+
density(x: number): number;
|
|
86
|
+
getVariance(): number;
|
|
87
|
+
getStdDev(): number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class Uniform implements PDF {
|
|
91
|
+
readonly min: number;
|
|
92
|
+
readonly max: number;
|
|
93
|
+
private readonly diff;
|
|
94
|
+
constructor(min: number, max: number);
|
|
95
|
+
getAccumulated(x: number): number;
|
|
96
|
+
getMean(): number;
|
|
97
|
+
sample(): number;
|
|
98
|
+
density(x: number): number;
|
|
99
|
+
getVariance(): number;
|
|
100
|
+
getStdDev(): number;
|
|
101
|
+
quantile(p: number): number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface PMF extends Distribution {
|
|
105
|
+
probability(x: number): number;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
declare class Binomial implements PMF {
|
|
109
|
+
private readonly n;
|
|
110
|
+
private readonly p;
|
|
111
|
+
private readonly probabilities;
|
|
112
|
+
private readonly accumulative;
|
|
113
|
+
private readonly variance;
|
|
114
|
+
private readonly stdDev;
|
|
115
|
+
constructor(n: number, p: number);
|
|
116
|
+
getAccumulated(x: number): number;
|
|
117
|
+
sample(): number;
|
|
118
|
+
getMean(): number;
|
|
119
|
+
getVariance(): number;
|
|
120
|
+
getStdDev(): number;
|
|
121
|
+
probability(x: number): number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare class NegativeBinomial implements PMF {
|
|
125
|
+
private readonly r;
|
|
126
|
+
private readonly p;
|
|
127
|
+
private readonly accumulative;
|
|
128
|
+
private readonly mean;
|
|
129
|
+
private readonly variance;
|
|
130
|
+
private readonly stdDev;
|
|
131
|
+
constructor(r: number, p: number);
|
|
132
|
+
getAccumulated(x: number): number;
|
|
133
|
+
getMean(): number;
|
|
134
|
+
getVariance(): number;
|
|
135
|
+
getStdDev(): number;
|
|
136
|
+
sample(): number;
|
|
137
|
+
probability(x: number): number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
declare class Poisson implements PMF {
|
|
141
|
+
private readonly l;
|
|
142
|
+
private readonly accumulative;
|
|
143
|
+
private readonly mean;
|
|
144
|
+
private readonly variance;
|
|
145
|
+
private readonly stdDev;
|
|
146
|
+
constructor(l: number);
|
|
147
|
+
getAccumulated(x: number): number;
|
|
148
|
+
sample(): number;
|
|
149
|
+
getMean(): number;
|
|
150
|
+
getVariance(): number;
|
|
151
|
+
getStdDev(): number;
|
|
152
|
+
probability(x: number): number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare class Stats {
|
|
156
|
+
private readonly orderedData;
|
|
157
|
+
private readonly data;
|
|
158
|
+
private _mean?;
|
|
159
|
+
private _variance?;
|
|
160
|
+
private _stdDev?;
|
|
161
|
+
private _q1?;
|
|
162
|
+
private _q2?;
|
|
163
|
+
private _q3?;
|
|
164
|
+
private _normalized?;
|
|
165
|
+
private _zScores?;
|
|
166
|
+
constructor(data: number[]);
|
|
167
|
+
get mean(): number;
|
|
168
|
+
get median(): number;
|
|
169
|
+
get variance(): number;
|
|
170
|
+
get stdDev(): number;
|
|
171
|
+
get q1(): number;
|
|
172
|
+
get q2(): number;
|
|
173
|
+
get q3(): number;
|
|
174
|
+
get zScores(): number[];
|
|
175
|
+
get normalized(): number[];
|
|
176
|
+
private percentile;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { Binomial, Exponential, Gaussian, NegativeBinomial, Poisson, Stats, Uniform, erf };
|