ziko 0.53.0 → 0.54.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.
@@ -0,0 +1,75 @@
1
+ // Mean
2
+ export const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
3
+ export const geo_mean = (...x) => (x.reduce((a, b) => a * b)) ** (1/x.length);
4
+ // Quadratic Mean
5
+ export const rms = (...x) => {
6
+ const n = x.length;
7
+ return (Math.hypot(...x)/n)**(1/n)
8
+ }
9
+
10
+ export const weighted_mean=(values, weights)=>{
11
+ let sum = 0, sw = 0;
12
+ for (let i = 0; i < values.length; i++) {
13
+ sum += values[i] * weights[i];
14
+ sw += weights[i];
15
+ }
16
+ return sum / sw;
17
+ }
18
+
19
+ export const harmonic_mean = (...x) => {
20
+ let s = 0, i = 0;
21
+ for(i=0; i<x.length; i++)
22
+ s += 1/x[i]
23
+ return x.length / s;
24
+ }
25
+
26
+ export const power_mean = (X, p) =>{
27
+ let s = 0, i = 0, l = X.length;
28
+ for(i=0; i < l; i++)
29
+ s+= X[i]**p
30
+ return (s / l) ** (1 / p);
31
+ }
32
+
33
+ export const trimmed_mean = (X, k) =>{
34
+ let a = [...X].sort((a,b)=>a-b).slice(k, X.length - k);
35
+ return mean(...a);
36
+ }
37
+
38
+ export const winsorized_mean = (X, k) =>{
39
+ let a = [...X].sort((a,b)=>a-b);
40
+ let low = a[k], high = a[a.length - k - 1];
41
+ a = a.map(x => Math.max(low, Math.min(high, x)));
42
+ return mean(a);
43
+ }
44
+
45
+ export const midrange = (x) =>{
46
+ let min = Math.min(...x);
47
+ let max = Math.max(...x);
48
+ return (min + max) / 2;
49
+ }
50
+
51
+ export const midhinge = (...x) =>{
52
+ let a = x.sort((a,b)=>a-b);
53
+ let q1 = a[Math.floor((a.length - 1) * 0.25)];
54
+ let q3 = a[Math.floor((a.length - 1) * 0.75)];
55
+ return (q1 + q3) / 2;
56
+ }
57
+
58
+
59
+ export const interquartile_mean = (...x) =>{
60
+ let a = x.sort((a,b)=>a-b);
61
+ let q1 = a[Math.floor((a.length - 1) * 0.25)];
62
+ let q3 = a[Math.floor((a.length - 1) * 0.75)];
63
+ let m = a.filter(x => x >= q1 && x <= q3);
64
+ return mean(m);
65
+ }
66
+
67
+
68
+ export const contraharmonic_mean = (...x) =>{
69
+ let num = 0, den = 0, i, l = x.length;
70
+ for(i = 0; i < l; i++){
71
+ num += x[i]**2;
72
+ den += x[i]
73
+ }
74
+ return num / den;
75
+ }
@@ -0,0 +1,14 @@
1
+ export * from './percentile/index.js';
2
+ export * from './average/index.js';
3
+ export * from './variability/index.js'
4
+ export * from './rolling/index.js'
5
+ export * from './accum/index.js'
6
+
7
+
8
+ // mean
9
+ // variance
10
+ // std
11
+ // percentil
12
+ // accum
13
+
14
+ //
@@ -0,0 +1,18 @@
1
+ export const percentile = (X, p) => {
2
+ if (X.length === 0)
3
+ return NaN;
4
+ let a = X.sort((x, y) => x - y);
5
+ let index = (p / 100) * (a.length - 1);
6
+ let i = Math.floor(index);
7
+ let f = index - i;
8
+ if (i === a.length - 1)
9
+ return a[i];
10
+ return a[i] * (1 - f) + a[i + 1] * f;
11
+ }
12
+
13
+ export const q1 = X => percentile(X, 25);
14
+ export const median = X => percentile(X, 50);
15
+ export const q3 = X => percentile(X, 75);
16
+
17
+ // Interquartile Range
18
+ export const iqr = X => q3(X) - q1(X)
@@ -0,0 +1,34 @@
1
+ // Simple Moving Average
2
+ export const sma = (X, w) =>{
3
+ let r = [];
4
+ for (let i = 0; i <= X.length - w; i++) {
5
+ let s = 0;
6
+ for (let j = 0; j < w; j++) s += X[i + j];
7
+ r.push(s / w);
8
+ }
9
+ return r;
10
+ }
11
+
12
+ // exponential Moving Average
13
+ export const ema = (X, alpha) =>{
14
+ let r = [], prev = X[0];
15
+ r.push(prev);
16
+ for (let i = 1; i < X.length; i++) {
17
+ prev = alpha * X[i] + (1 - alpha) * prev;
18
+ r.push(prev);
19
+ }
20
+ return r;
21
+ }
22
+
23
+ // weightedMovingAverage
24
+ export const wma = (X, weights) =>{
25
+ let k = weights.length;
26
+ let sw = weights.reduce((a,b)=>a+b, 0);
27
+ let r = [];
28
+ for (let i = 0; i <= X.length - k; i++) {
29
+ let s = 0;
30
+ for (let j = 0; j < k; j++) s += X[i+j] * weights[j];
31
+ r.push(s / sw);
32
+ }
33
+ return r;
34
+ }
@@ -0,0 +1,37 @@
1
+ // Population Variance
2
+ import { mean } from "../average/index.js";
3
+ export const variance = (...x) => {
4
+ const n = x.length;
5
+ if (n === 0) return NaN;
6
+ const x_mean = mean(...x);
7
+ return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
8
+ };
9
+ export const std = (...x) => Math.sqrt(variance(...x));
10
+
11
+ export const sample_variance = (...x) => {
12
+ const n = x.length;
13
+ if (n < 2) return NaN;
14
+ const x_mean = mean(...x);
15
+ return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / (n - 1);
16
+ };
17
+ export const sample_std = (...x) => Math.sqrt(sample_variance(...x));
18
+
19
+ export const weighted_variance = (X, weights) => {
20
+ const n = X.length;
21
+ if (n === 0 || weights.length !== n) return NaN;
22
+ const sw = weights.reduce((sum, w) => sum + w, 0);
23
+ const mean = X.reduce((sum, x, i) => sum + x * weights[i], 0) / sw;
24
+ return X.reduce((sum, x, i) => sum + weights[i] * (x - mean) ** 2, 0) / sw;
25
+ };
26
+ export const weighted_std = (X, weights) => Math.sqrt(weighted_variance(X, weights));
27
+
28
+ export const rolling_variance = (X, windowSize) => {
29
+ if (windowSize < 1 || X.length < windowSize) return [];
30
+ let result = [];
31
+ for (let i = 0; i <= X.length - windowSize; i++) {
32
+ const w = X.slice(i, i + windowSize);
33
+ result.push(sample_variance(w)); // usually sample variance for rolling
34
+ }
35
+ return result;
36
+ };
37
+ export const rolling_std = (X, windowSize) => Math.sqrt(rolling_variance(X, windowSize));
@@ -43,7 +43,7 @@ const _sub=(a,b)=>{
43
43
  const _mul=(a,b)=>{
44
44
  if(typeof(a)==="number"){
45
45
  if (typeof b == "number") return a * b;
46
- else if (b.isComplex?.())return new b.constructor(a * b.a,a * b.b);
46
+ else if (b.isComplex?.())return new b.constructor(a * b.a, a * b.b);
47
47
  else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).mul(b);
48
48
  else if (b instanceof Array)return b.map(n=>mul(a,n));
49
49
  }
@@ -1,28 +1,28 @@
1
- import { mapfun } from "../mapfun/index.js";
2
- import {
3
- add,
4
- sub,
5
- mul,
6
- div,
7
- modulo
8
- } from "./arithmetic.js";
1
+ // import { mapfun } from "../mapfun/index.js";
2
+ // import {
3
+ // add,
4
+ // sub,
5
+ // mul,
6
+ // div,
7
+ // modulo
8
+ // } from "./arithmetic.js";
9
9
  import {
10
10
  zeros,
11
11
  ones,
12
12
  nums,
13
- norm,
14
- lerp,
15
- map,
16
- clamp,
13
+ // norm,
14
+ // lerp,
15
+ // map,
16
+ // clamp,
17
17
  arange,
18
18
  linspace,
19
19
  logspace,
20
20
  geomspace
21
21
  } from "../signal/functions.js"
22
- import {
23
- deg2rad,
24
- rad2deg
25
- } from "./conversions.js"
22
+ // import {
23
+ // deg2rad,
24
+ // rad2deg
25
+ // } from "./conversions.js"
26
26
  import{
27
27
  sum,
28
28
  prod,
@@ -38,19 +38,19 @@ import{
38
38
  pgcd
39
39
  } from "./discret.js"
40
40
  const Utils={
41
- add,
42
- sub,
43
- mul,
44
- div,
45
- modulo,
41
+ // add,
42
+ // sub,
43
+ // mul,
44
+ // div,
45
+ // modulo,
46
46
 
47
47
  zeros,
48
48
  ones,
49
49
  nums,
50
- norm,
51
- lerp,
52
- map,
53
- clamp,
50
+ // norm,
51
+ // lerp,
52
+ // map,
53
+ // clamp,
54
54
  arange,
55
55
  linspace,
56
56
  logspace,
@@ -64,35 +64,35 @@ const Utils={
64
64
  ppcm,
65
65
  pgcd,
66
66
 
67
- deg2rad,
68
- rad2deg,
67
+ // deg2rad,
68
+ // rad2deg,
69
69
 
70
70
  inRange,
71
71
  isApproximatlyEqual
72
72
  }
73
73
  export {
74
- mapfun,
74
+ // mapfun,
75
75
  Utils,
76
76
  zeros,
77
77
  ones,
78
78
  nums,
79
79
  sum,
80
80
  prod,
81
- add,
82
- mul,
83
- sub,
84
- div,
85
- modulo,
86
- rad2deg,
87
- deg2rad,
81
+ // add,
82
+ // mul,
83
+ // sub,
84
+ // div,
85
+ // modulo,
86
+ // rad2deg,
87
+ // deg2rad,
88
88
  arange,
89
89
  linspace,
90
90
  logspace,
91
91
  geomspace,
92
- norm,
93
- lerp,
94
- map,
95
- clamp,
92
+ // norm,
93
+ // lerp,
94
+ // map,
95
+ // clamp,
96
96
  pgcd,
97
97
  ppcm,
98
98
  isApproximatlyEqual,
@@ -1,5 +1,5 @@
1
1
  import { linear } from "../ease/index.js";
2
- import { map } from "../../math/utils/index.js";
2
+ import { map } from "../../math/functions/utils/index.js";
3
3
 
4
4
  class TimeAnimation {
5
5
  constructor(callback, { ease = linear, step = 50, t0 = 0, start = true, duration = 3000 } = {}) {
@@ -23,6 +23,7 @@ export declare class Complex {
23
23
  readonly conj: Complex;
24
24
  readonly inv: Complex;
25
25
  readonly sqrt: Complex;
26
+ readonly cbrt: Complex;
26
27
  readonly log: Complex;
27
28
  readonly cos: Complex;
28
29
  readonly sin: Complex;
@@ -34,7 +35,7 @@ export declare class Complex {
34
35
  mul(...z: (number | Complex)[]): this;
35
36
  div(...z: (number | Complex)[]): this;
36
37
  pow(n: number): this;
37
- sqrtn(n?: number): Complex;
38
+ nrth(n?: number): Complex;
38
39
 
39
40
  static Zero(): Complex;
40
41
  static fromExpo(z: number, phi: number): Complex;