ziko 1.3.0 → 1.5.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/dist/ziko.cjs +362 -90
- package/dist/ziko.js +362 -90
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +333 -91
- package/package.json +1 -1
- package/src/dom/components/for/index.js +17 -0
- package/src/dom/components/fragment/index.d.ts +36 -0
- package/src/dom/components/fragment/index.js +13 -0
- package/src/dom/components/index.js +3 -1
- package/src/dom/constructors/UIElement.js +8 -1
- package/src/math/complex/index.d.ts +207 -30
- package/src/math/functions/arithmetic/index.d.ts +95 -0
- package/src/math/functions/conversions/index.d.ts +101 -0
- package/src/math/functions/index.d.ts +97 -90
- package/src/math/functions/logic/index.d.ts +50 -8
- package/src/math/functions/logic/index.js +1 -1
- package/src/math/functions/mapfun/index.d.ts +46 -80
- package/src/math/functions/mapfun/index.d.ts.txt +162 -0
- package/src/math/functions/signal/index.d.ts +146 -0
- package/src/math/functions/stats/index.js +33 -33
- package/src/math/functions/ufunc/index.d.ts +96 -0
- package/src/math/functions/utils/index.d.ts +118 -1
- package/src/math/index.d.ts +4 -0
- package/src/math/index.js +1 -16
- package/src/math/random/index.d.ts +162 -0
- package/src/math/random/index.js +4 -4
- package/src/math/stats/accum/index.d.ts +43 -0
- package/src/math/stats/average/index.d.ts +123 -0
- package/src/math/stats/index.d.ts +5 -0
- package/src/math/stats/percentile/index.d.ts +66 -0
- package/src/math/stats/rolling/index.d.ts +47 -0
- package/src/math/stats/variability/index.d.ts +93 -0
- package/src/math/index.d.ts.txt +0 -5
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Complex }from '../../complex/index.d.ts'
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array filled with zeros.
|
|
4
|
+
*
|
|
5
|
+
* @param n Array length.
|
|
6
|
+
*/
|
|
7
|
+
export declare function zeros(
|
|
8
|
+
n: number
|
|
9
|
+
): number[];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates an array filled with ones.
|
|
13
|
+
*
|
|
14
|
+
* @param n Array length.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ones(
|
|
17
|
+
n: number
|
|
18
|
+
): number[];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an array filled with a given value.
|
|
22
|
+
*
|
|
23
|
+
* @param n Array length.
|
|
24
|
+
* @param num Fill value.
|
|
25
|
+
*/
|
|
26
|
+
export declare function nums<T>(
|
|
27
|
+
n: number,
|
|
28
|
+
num: T
|
|
29
|
+
): T[];
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a range of numbers.
|
|
34
|
+
*
|
|
35
|
+
* Supports ascending and descending ranges.
|
|
36
|
+
*
|
|
37
|
+
* @param a Start value.
|
|
38
|
+
* @param b End value.
|
|
39
|
+
* @param step Step size.
|
|
40
|
+
* @param include Include end value.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* arange(0, 5, 1)
|
|
44
|
+
* // [0,1,2,3,4]
|
|
45
|
+
*/
|
|
46
|
+
export declare function arange(
|
|
47
|
+
a: number,
|
|
48
|
+
b: number,
|
|
49
|
+
step: number,
|
|
50
|
+
include?: boolean
|
|
51
|
+
): number[];
|
|
52
|
+
|
|
53
|
+
export declare function arange(
|
|
54
|
+
a: number[],
|
|
55
|
+
b: number,
|
|
56
|
+
step: number,
|
|
57
|
+
include?: boolean
|
|
58
|
+
): number[][];
|
|
59
|
+
|
|
60
|
+
export declare function arange(
|
|
61
|
+
a: number,
|
|
62
|
+
b: number[],
|
|
63
|
+
step: number,
|
|
64
|
+
include?: boolean
|
|
65
|
+
): number[][];
|
|
66
|
+
|
|
67
|
+
export declare function arange(
|
|
68
|
+
a: number[],
|
|
69
|
+
b: number[],
|
|
70
|
+
step: number,
|
|
71
|
+
include?: boolean
|
|
72
|
+
): number[][];
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Generates evenly spaced numbers over an interval.
|
|
77
|
+
*
|
|
78
|
+
* @param a Start value.
|
|
79
|
+
* @param b End value.
|
|
80
|
+
* @param n Number of samples.
|
|
81
|
+
* @param endpoint Include endpoint.
|
|
82
|
+
*/
|
|
83
|
+
export declare function linspace(
|
|
84
|
+
a: number,
|
|
85
|
+
b: number,
|
|
86
|
+
n?: number,
|
|
87
|
+
endpoint?: boolean
|
|
88
|
+
): number[];
|
|
89
|
+
|
|
90
|
+
export declare function linspace<T extends Complex>(
|
|
91
|
+
a: number | T,
|
|
92
|
+
b: number | T,
|
|
93
|
+
n?: number,
|
|
94
|
+
endpoint?: boolean
|
|
95
|
+
): T[];
|
|
96
|
+
|
|
97
|
+
export declare function linspace(
|
|
98
|
+
a: number[],
|
|
99
|
+
b: number | number[],
|
|
100
|
+
n?: number,
|
|
101
|
+
endpoint?: boolean
|
|
102
|
+
): number[][];
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Generates numbers spaced evenly on a logarithmic scale.
|
|
107
|
+
*
|
|
108
|
+
* @param a Start exponent.
|
|
109
|
+
* @param b End exponent.
|
|
110
|
+
* @param n Number of samples.
|
|
111
|
+
* @param base Logarithm base.
|
|
112
|
+
* @param endpoint Include endpoint.
|
|
113
|
+
*/
|
|
114
|
+
export declare function logspace(
|
|
115
|
+
a: number,
|
|
116
|
+
b: number,
|
|
117
|
+
n?: number,
|
|
118
|
+
base?: number,
|
|
119
|
+
endpoint?: boolean
|
|
120
|
+
): number[];
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Generates numbers spaced evenly on a geometric progression.
|
|
125
|
+
*
|
|
126
|
+
* @param a Start value.
|
|
127
|
+
* @param b End value.
|
|
128
|
+
* @param n Number of samples.
|
|
129
|
+
* @param endpoint Include endpoint.
|
|
130
|
+
* @param precision Decimal precision.
|
|
131
|
+
*/
|
|
132
|
+
export declare function geomspace(
|
|
133
|
+
a: number,
|
|
134
|
+
b: number,
|
|
135
|
+
n?: number,
|
|
136
|
+
endpoint?: boolean,
|
|
137
|
+
precision?: number
|
|
138
|
+
): number[];
|
|
139
|
+
|
|
140
|
+
export declare function geomspace<T extends Complex>(
|
|
141
|
+
a: T | number,
|
|
142
|
+
b: T | number,
|
|
143
|
+
n?: number,
|
|
144
|
+
endpoint?: boolean,
|
|
145
|
+
precision?: number
|
|
146
|
+
): T[];
|
|
@@ -15,26 +15,26 @@ export const binomial = (n, k) =>{
|
|
|
15
15
|
return c;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
|
|
19
|
-
|
|
20
|
-
export const variance = (...x) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const std = (...x) => Math.sqrt(variance(...x));
|
|
28
|
-
|
|
29
|
-
export const accum_sum = (...x) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
18
|
+
// export const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
|
|
19
|
+
|
|
20
|
+
// export const variance = (...x) => {
|
|
21
|
+
// const n = x.length;
|
|
22
|
+
// if (n === 0) return NaN;
|
|
23
|
+
// const x_mean = mean(...x);
|
|
24
|
+
// return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
|
|
25
|
+
// };
|
|
26
|
+
|
|
27
|
+
// export const std = (...x) => Math.sqrt(variance(...x));
|
|
28
|
+
|
|
29
|
+
// export const accum_sum = (...x) => {
|
|
30
|
+
// let result = [];
|
|
31
|
+
// let total = 0, i, n = x.length;
|
|
32
|
+
// for(i = 0; i < n ; i++){
|
|
33
|
+
// total = add(total, x[i])
|
|
34
|
+
// result.push(total);
|
|
35
|
+
// }
|
|
36
|
+
// return result;
|
|
37
|
+
// };
|
|
38
38
|
|
|
39
39
|
export const accum_prod = (...x) => {
|
|
40
40
|
let result = [];
|
|
@@ -46,16 +46,16 @@ export const accum_prod = (...x) => {
|
|
|
46
46
|
return result;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export const percentile = (X, p) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const median = X => percentile(X, 50);
|
|
49
|
+
// export const percentile = (X, p) => {
|
|
50
|
+
// if (X.length === 0)
|
|
51
|
+
// return NaN;
|
|
52
|
+
// let a = [...X].sort((x, y) => x - y);
|
|
53
|
+
// let index = (p / 100) * (a.length - 1);
|
|
54
|
+
// let i = Math.floor(index);
|
|
55
|
+
// let f = index - i;
|
|
56
|
+
// if (i === a.length - 1)
|
|
57
|
+
// return a[i];
|
|
58
|
+
// return a[i] * (1 - f) + a[i + 1] * f;
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// export const median = X => percentile(X, 50);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { mapfun, MapFunResult } from '../mapfun/index.d.ts';
|
|
2
|
+
import { complex } from '../../complex/index.d.ts';
|
|
3
|
+
|
|
4
|
+
// --- Standard Unary / Multi-Argument Math Functions ---
|
|
5
|
+
|
|
6
|
+
export function abs<T>(x: T): MapFunResult<T, any>;
|
|
7
|
+
export function abs<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
8
|
+
|
|
9
|
+
export function sqrt<T>(x: T): MapFunResult<T, any>;
|
|
10
|
+
export function sqrt<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
11
|
+
|
|
12
|
+
export function cbrt<T>(x: T): MapFunResult<T, any>;
|
|
13
|
+
export function cbrt<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
14
|
+
|
|
15
|
+
export function exp<T>(x: T): MapFunResult<T, any>;
|
|
16
|
+
export function exp<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
17
|
+
|
|
18
|
+
export function ln<T>(x: T): MapFunResult<T, any>;
|
|
19
|
+
export function ln<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
20
|
+
|
|
21
|
+
export function sign<T>(x: T): MapFunResult<T, any>;
|
|
22
|
+
export function sign<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
23
|
+
|
|
24
|
+
export function floor<T>(x: T): MapFunResult<T, any>;
|
|
25
|
+
export function floor<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
26
|
+
|
|
27
|
+
export function ceil<T>(x: T): MapFunResult<T, any>;
|
|
28
|
+
export function ceil<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
29
|
+
|
|
30
|
+
export function round<T>(x: T): MapFunResult<T, any>;
|
|
31
|
+
export function round<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
32
|
+
|
|
33
|
+
export function trunc<T>(x: T): MapFunResult<T, any>;
|
|
34
|
+
export function trunc<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
35
|
+
|
|
36
|
+
export function fract<T>(x: T): MapFunResult<T, any>;
|
|
37
|
+
export function fract<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
38
|
+
|
|
39
|
+
export function cos<T>(x: T): MapFunResult<T, any>;
|
|
40
|
+
export function cos<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
41
|
+
|
|
42
|
+
export function sin<T>(x: T): MapFunResult<T, any>;
|
|
43
|
+
export function sin<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
44
|
+
|
|
45
|
+
export function tan<T>(x: T): MapFunResult<T, any>;
|
|
46
|
+
export function tan<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
47
|
+
|
|
48
|
+
export function sec<T>(x: T): MapFunResult<T, any>;
|
|
49
|
+
export function sec<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
50
|
+
|
|
51
|
+
export function acos<T>(x: T): MapFunResult<T, any>;
|
|
52
|
+
export function acos<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
53
|
+
|
|
54
|
+
export function asin<T>(x: T): MapFunResult<T, any>;
|
|
55
|
+
export function asin<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
56
|
+
|
|
57
|
+
export function atan<T>(x: T): MapFunResult<T, any>;
|
|
58
|
+
export function atan<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
59
|
+
|
|
60
|
+
export function acot<T>(x: T): MapFunResult<T, any>;
|
|
61
|
+
export function acot<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
62
|
+
|
|
63
|
+
export function cosh<T>(x: T): MapFunResult<T, any>;
|
|
64
|
+
export function cosh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
65
|
+
|
|
66
|
+
export function sinh<T>(x: T): MapFunResult<T, any>;
|
|
67
|
+
export function sinh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
68
|
+
|
|
69
|
+
export function tanh<T>(x: T): MapFunResult<T, any>;
|
|
70
|
+
export function tanh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
71
|
+
|
|
72
|
+
export function coth<T>(x: T): MapFunResult<T, any>;
|
|
73
|
+
export function coth<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
74
|
+
|
|
75
|
+
export function acosh<T>(x: T): MapFunResult<T, any>;
|
|
76
|
+
export function acosh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
77
|
+
|
|
78
|
+
export function asinh<T>(x: T): MapFunResult<T, any>;
|
|
79
|
+
export function asinh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
80
|
+
|
|
81
|
+
export function atanh<T>(x: T): MapFunResult<T, any>;
|
|
82
|
+
export function atanh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
83
|
+
|
|
84
|
+
export function sig<T>(x: T): MapFunResult<T, any>;
|
|
85
|
+
export function sig<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
86
|
+
|
|
87
|
+
// --- Functions that pop parameters from the end (pow, nthr, croot) ---
|
|
88
|
+
|
|
89
|
+
export function pow<T, N>(base: T, n: N): MapFunResult<T, any>;
|
|
90
|
+
export function pow<T extends any[], N>(...args: [...T, N]): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
91
|
+
|
|
92
|
+
export function nthr<T, N extends number>(base: T, n: N): MapFunResult<T, any>;
|
|
93
|
+
export function nthr<T extends any[], N extends number>(...args: [...T, N]): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
94
|
+
|
|
95
|
+
export function croot<T, C>(base: T, root: C): MapFunResult<T, any>;
|
|
96
|
+
export function croot<T extends any[], C>(...args: [...T, C]): { [K in keyof T]: MapFunResult<T[K], any> };
|
|
@@ -1 +1,118 @@
|
|
|
1
|
-
|
|
1
|
+
import { Mappable } from "../mapfun/index.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Converts degrees to radians.
|
|
4
|
+
*
|
|
5
|
+
* Accepts multiple values and recursively maps through
|
|
6
|
+
* supported structures.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* deg2rad(180) // 3.14159...
|
|
10
|
+
*/
|
|
11
|
+
export declare function deg2rad(
|
|
12
|
+
...deg: Mappable<number>[]
|
|
13
|
+
): Mappable<number>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts radians to degrees.
|
|
17
|
+
*
|
|
18
|
+
* Accepts multiple values and recursively maps through
|
|
19
|
+
* supported structures.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* rad2deg(Math.PI) // 180
|
|
23
|
+
*/
|
|
24
|
+
export declare function rad2deg(
|
|
25
|
+
...rad: Mappable<number>[]
|
|
26
|
+
): Mappable<number>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Normalizes a value from a range to the interval [0, 1].
|
|
30
|
+
*
|
|
31
|
+
* Supports numbers, arrays, typed arrays, objects,
|
|
32
|
+
* complex values and matrices.
|
|
33
|
+
*
|
|
34
|
+
* @param x Input value.
|
|
35
|
+
* @param min Minimum range value.
|
|
36
|
+
* @param max Maximum range value.
|
|
37
|
+
*/
|
|
38
|
+
export declare function norm(
|
|
39
|
+
x: Mappable<number>,
|
|
40
|
+
min: number,
|
|
41
|
+
max: number
|
|
42
|
+
): Mappable<number>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Performs linear interpolation.
|
|
46
|
+
*
|
|
47
|
+
* Maps a normalized value to a given range.
|
|
48
|
+
*
|
|
49
|
+
* @param x Input normalized value.
|
|
50
|
+
* @param min Start value.
|
|
51
|
+
* @param max End value.
|
|
52
|
+
*/
|
|
53
|
+
export declare function lerp(
|
|
54
|
+
x: Mappable<number>,
|
|
55
|
+
min: number,
|
|
56
|
+
max: number
|
|
57
|
+
): Mappable<number>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Restricts values to a given interval.
|
|
61
|
+
*
|
|
62
|
+
* @param x Input value.
|
|
63
|
+
* @param min Lower bound.
|
|
64
|
+
* @param max Upper bound.
|
|
65
|
+
*/
|
|
66
|
+
export declare function clamp(
|
|
67
|
+
x: Mappable<number>,
|
|
68
|
+
min: number,
|
|
69
|
+
max: number
|
|
70
|
+
): Mappable<number>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Maps a value from one range to another.
|
|
74
|
+
*
|
|
75
|
+
* @param x Input value.
|
|
76
|
+
* @param a Source minimum.
|
|
77
|
+
* @param b Source maximum.
|
|
78
|
+
* @param c Target minimum.
|
|
79
|
+
* @param d Target maximum.
|
|
80
|
+
*/
|
|
81
|
+
export declare function map(
|
|
82
|
+
x: Mappable<number>,
|
|
83
|
+
a: number,
|
|
84
|
+
b: number,
|
|
85
|
+
c: number,
|
|
86
|
+
d: number
|
|
87
|
+
): Mappable<number>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Calculates the Euclidean norm (hypotenuse).
|
|
91
|
+
*
|
|
92
|
+
* Supports numbers and complex-like values.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* hypot(3, 4) // 5
|
|
96
|
+
*/
|
|
97
|
+
export declare function hypot(
|
|
98
|
+
...x: (number | ComplexLike)[]
|
|
99
|
+
): number;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Calculates the angle between the positive x-axis and a point.
|
|
103
|
+
*
|
|
104
|
+
* Supports scalar values and array inputs.
|
|
105
|
+
*
|
|
106
|
+
* @param y Y coordinate(s).
|
|
107
|
+
* @param x X coordinate(s).
|
|
108
|
+
* @param rad Return radians when true, degrees otherwise.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* atan2(1, 1) // 0.785...
|
|
112
|
+
* atan2(1, 1, false) // 45
|
|
113
|
+
*/
|
|
114
|
+
export declare function atan2(
|
|
115
|
+
y: Mappable<number>,
|
|
116
|
+
x: Mappable<number>,
|
|
117
|
+
rad?: boolean
|
|
118
|
+
): Mappable<number>;
|
package/src/math/index.js
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
// import * as __Const__ from "./const.js"
|
|
2
|
-
// import * as __Functions__ from "./functions/index.js"
|
|
3
|
-
// import * as __Random__ from "./random"
|
|
4
|
-
// import * as __Complex__ from "./complex"
|
|
5
|
-
// import * as __Matrix__ from "./matrix"
|
|
6
|
-
// import * as __Discrect__ from "./discret"
|
|
7
|
-
// import * as __Utils__ from "./utils"
|
|
8
|
-
// const Math = {
|
|
9
|
-
// ...__Const__,
|
|
10
|
-
// ...__Functions__,
|
|
11
|
-
// ...__Complex__,
|
|
12
|
-
// ...__Matrix__,
|
|
13
|
-
// ...__Random__,
|
|
14
|
-
// ...__Utils__,
|
|
15
|
-
// ...__Discrect__,
|
|
16
|
-
// }
|
|
17
1
|
export * from "./const.js"
|
|
18
2
|
export * from "./functions/index.js"
|
|
19
3
|
export * from "./complex/index.js"
|
|
20
4
|
export * from "./matrix/index.js"
|
|
5
|
+
export * from './stats/index.js'
|
|
21
6
|
// export * from "./discret"
|
|
22
7
|
export * from "./random/index.js"
|
|
23
8
|
// export * from "./utils/index.js" // To Check
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for generating random values.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Random {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generates a random integer.
|
|
8
|
+
* @param a Minimum value (inclusive).
|
|
9
|
+
* @param b Maximum value (exclusive).
|
|
10
|
+
*/
|
|
11
|
+
static int(a: number, b?: number): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generates a random floating-point number.
|
|
15
|
+
* @param a Minimum value.
|
|
16
|
+
* @param b Maximum value.
|
|
17
|
+
*/
|
|
18
|
+
static float(a: number, b?: number): number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generates a random binary value.
|
|
22
|
+
*/
|
|
23
|
+
static bin(): 0 | 1;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generates a random octal digit.
|
|
27
|
+
*/
|
|
28
|
+
static oct(): number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generates a random decimal digit.
|
|
32
|
+
*/
|
|
33
|
+
static dec(): number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Generates a random hexadecimal digit.
|
|
37
|
+
*/
|
|
38
|
+
static hex(): string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generates a random alphabetic character.
|
|
42
|
+
* @param upperCase Generate uppercase character when true.
|
|
43
|
+
*/
|
|
44
|
+
static char(upperCase?: boolean): string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generates a random boolean value.
|
|
48
|
+
*/
|
|
49
|
+
static bool(): boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Random color generators.
|
|
53
|
+
*/
|
|
54
|
+
static readonly color: {
|
|
55
|
+
/** Generates a random HEX color. */
|
|
56
|
+
hex(): string;
|
|
57
|
+
|
|
58
|
+
/** Generates a random HEXA color with alpha channel. */
|
|
59
|
+
hexa(): string;
|
|
60
|
+
|
|
61
|
+
/** Generates a random RGB color. */
|
|
62
|
+
rgb(): string;
|
|
63
|
+
|
|
64
|
+
/** Generates a random RGBA color. */
|
|
65
|
+
rgba(): string;
|
|
66
|
+
|
|
67
|
+
/** Generates a random HSL color. */
|
|
68
|
+
hsl(): string;
|
|
69
|
+
|
|
70
|
+
/** Generates a random HSLA color with alpha channel. */
|
|
71
|
+
hsla(): string;
|
|
72
|
+
|
|
73
|
+
/** Generates a random grayscale RGB color. */
|
|
74
|
+
gray(): string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Generates arrays of random values.
|
|
79
|
+
*/
|
|
80
|
+
static readonly sample: {
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Generates an array of random integers.
|
|
84
|
+
*/
|
|
85
|
+
int(n: number, a: number, b?: number): number[];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Generates an array of random floats.
|
|
89
|
+
*/
|
|
90
|
+
float(n: number, a: number, b?: number): number[];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Generates an array of random characters.
|
|
94
|
+
*/
|
|
95
|
+
char(n: number, upper?: boolean): string[];
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Generates an array of random booleans.
|
|
99
|
+
*/
|
|
100
|
+
bool(n: number): boolean[];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Generates an array of random binary values.
|
|
104
|
+
*/
|
|
105
|
+
bin(n: number): (0 | 1)[];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Generates an array of random octal digits.
|
|
109
|
+
*/
|
|
110
|
+
oct(n: number): number[];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Generates an array of random decimal digits.
|
|
114
|
+
*/
|
|
115
|
+
dec(n: number): number[];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Generates an array of random hexadecimal digits.
|
|
119
|
+
*/
|
|
120
|
+
hex(n: number): string[];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Generates arrays of random colors.
|
|
124
|
+
*/
|
|
125
|
+
readonly color: {
|
|
126
|
+
hex(n: number): string[];
|
|
127
|
+
hexa(n: number): string[];
|
|
128
|
+
rgb(n: number): string[];
|
|
129
|
+
rgba(n: number): string[];
|
|
130
|
+
hsl(n: number): string[];
|
|
131
|
+
hsla(n: number): string[];
|
|
132
|
+
gray(n: number): string[];
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Generates an array of random choices from a list.
|
|
137
|
+
* @param n Number of generated values.
|
|
138
|
+
* @param choices Available values.
|
|
139
|
+
* @param p Probability distribution for each value.
|
|
140
|
+
*/
|
|
141
|
+
choice<T>(
|
|
142
|
+
n: number,
|
|
143
|
+
choices: T[],
|
|
144
|
+
p?: number[]
|
|
145
|
+
): T[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns a shuffled copy of an array.
|
|
150
|
+
*/
|
|
151
|
+
static shuffle<T>(arr: T[]): T[];
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Randomly selects a value from a list.
|
|
155
|
+
* @param choices Available values.
|
|
156
|
+
* @param p Probability distribution for each value.
|
|
157
|
+
*/
|
|
158
|
+
static choice<T>(
|
|
159
|
+
choices?: T[],
|
|
160
|
+
p?: number[]
|
|
161
|
+
): T;
|
|
162
|
+
}
|
package/src/math/random/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base2base } from "../functions/conversions/index.js";
|
|
2
|
-
import { accum_sum } from "../
|
|
2
|
+
import { accum_sum } from "../stats/index.js";
|
|
3
3
|
|
|
4
4
|
export class Random {
|
|
5
5
|
static int(a, b){
|
|
@@ -74,9 +74,9 @@ export class Random {
|
|
|
74
74
|
static get sample(){
|
|
75
75
|
const R = this;
|
|
76
76
|
return {
|
|
77
|
-
int : (n,a,b) => Array.from({length:n}, () => R.int(a,b)),
|
|
78
|
-
float : (n,a,b) => Array.from({length:n}, () => R.float(a,b)),
|
|
79
|
-
char : (n,upper=false) => Array.from({length:n}, () => R.char(upper)),
|
|
77
|
+
int : (n, a, b) => Array.from({length:n}, () => R.int(a, b)),
|
|
78
|
+
float : (n, a, b) => Array.from({length:n}, () => R.float(a, b)),
|
|
79
|
+
char : (n, upper=false) => Array.from({length:n}, () => R.char(upper)),
|
|
80
80
|
bool : n => Array.from({length:n}, () => R.bool()),
|
|
81
81
|
bin : n => Array.from({length:n}, () => R.bin()),
|
|
82
82
|
oct : n => Array.from({length:n}, () => R.oct()),
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the cumulative sum of an array.
|
|
3
|
+
*
|
|
4
|
+
* Each element in the returned array represents the sum of all
|
|
5
|
+
* previous elements up to the current index.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* accum_sum([1, 2, 3]) // [1, 3, 6]
|
|
9
|
+
*/
|
|
10
|
+
export declare function accum_sum(arr: number[]): number[];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the cumulative product of an array.
|
|
14
|
+
*
|
|
15
|
+
* Each element in the returned array represents the product of all
|
|
16
|
+
* previous elements up to the current index.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* accum_product([2, 3, 4]) // [2, 6, 24]
|
|
20
|
+
*/
|
|
21
|
+
export declare function accum_product(arr: number[]): number[];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the cumulative maximum values of an array.
|
|
25
|
+
*
|
|
26
|
+
* Each element in the returned array represents the maximum value
|
|
27
|
+
* encountered from the beginning of the array.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* accum_max([3, 1, 5, 2]) // [3, 3, 5, 5]
|
|
31
|
+
*/
|
|
32
|
+
export declare function accum_max(arr: number[]): number[];
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Calculates the cumulative minimum values of an array.
|
|
36
|
+
*
|
|
37
|
+
* Each element in the returned array represents the minimum value
|
|
38
|
+
* encountered from the beginning of the array.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* accum_min([3, 1, 5, 2]) // [3, 1, 1, 1]
|
|
42
|
+
*/
|
|
43
|
+
export declare function accum_min(arr: number[]): number[];
|