@sc-voice/tools 3.27.0 → 3.29.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/package.json +1 -1
- package/src/math/activation.mjs +37 -24
- package/src/math/interval.mjs +30 -20
package/package.json
CHANGED
package/src/math/activation.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class Activation {
|
|
2
2
|
constructor(opts = {}) {
|
|
3
3
|
const msg = 'A8n.ctor';
|
|
4
|
-
let { a, b, c, d, fEval, dEval} = opts;
|
|
4
|
+
let { a, b, c, d, fEval, dEval } = opts;
|
|
5
5
|
if (fEval == null) {
|
|
6
6
|
throw new Error(`${msg} fEval?`);
|
|
7
7
|
}
|
|
@@ -10,11 +10,19 @@ export class Activation {
|
|
|
10
10
|
throw new Error(`${msg} dEval?`);
|
|
11
11
|
}
|
|
12
12
|
this.dEval = dEval;
|
|
13
|
-
|
|
14
|
-
if (a != null) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
13
|
+
|
|
14
|
+
if (a != null) {
|
|
15
|
+
this.a = a;
|
|
16
|
+
}
|
|
17
|
+
if (b != null) {
|
|
18
|
+
this.b = b;
|
|
19
|
+
}
|
|
20
|
+
if (c != null) {
|
|
21
|
+
this.c = c;
|
|
22
|
+
}
|
|
23
|
+
if (d != null) {
|
|
24
|
+
this.d = d;
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
f(x) {
|
|
@@ -31,31 +39,36 @@ export class Activation {
|
|
|
31
39
|
static createSoboleva(a = 1, b = 1, c = 1, d = 1) {
|
|
32
40
|
const msg = 'a8n.createSoboleva';
|
|
33
41
|
let fEval = (x, a, b, c, d) => {
|
|
34
|
-
return (
|
|
42
|
+
return (
|
|
43
|
+
(Math.exp(a * x) - Math.exp(-b * x)) /
|
|
35
44
|
(Math.exp(c * x) + Math.exp(-d * x))
|
|
36
|
-
|
|
45
|
+
);
|
|
46
|
+
};
|
|
37
47
|
let dEval = (x, a, b, c, d) => {
|
|
38
|
-
console.log(msg,
|
|
39
|
-
return (
|
|
40
|
-
(Math.exp(
|
|
41
|
-
|
|
42
|
-
(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
console.log(msg, 'UNTESTED');
|
|
49
|
+
return (
|
|
50
|
+
(a * Math.exp(a * x) + b * Math.exp(-b * x)) /
|
|
51
|
+
(Math.exp(c * x) + Math.exp(-d * x)) -
|
|
52
|
+
(fEval(x, a, b, c, d) *
|
|
53
|
+
(c * Math.exp(c * x) - d * Math.exp(-d * x))) /
|
|
54
|
+
(Math.exp(c * x) + Math.exp(-d * x))
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
46
58
|
return new Activation({ a, b, c, d, fEval, dEval });
|
|
47
59
|
}
|
|
48
60
|
|
|
49
|
-
static createRareN(a=100,b=1) {
|
|
50
|
-
let fEval = (x,a) =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
static createRareN(a = 100, b = 1) {
|
|
62
|
+
let fEval = (x, a) =>
|
|
63
|
+
x < 1 ? 1 : 1 - Math.exp(((x - a) / x) * b);
|
|
64
|
+
let dEval = (x, a) =>
|
|
65
|
+
x < 1 ? 0 : -(a * b * fEval(x, a, b)) / (x * x);
|
|
66
|
+
return new Activation({ a, b, fEval, dEval });
|
|
54
67
|
}
|
|
55
68
|
|
|
56
|
-
static createElu(a=0) {
|
|
57
|
-
let fEval = (x) => (x >= 0 ? x :
|
|
58
|
-
let dEval = (x) =>
|
|
69
|
+
static createElu(a = 0) {
|
|
70
|
+
let fEval = (x) => (x >= 0 ? x : a * (Math.exp(x) - 1));
|
|
71
|
+
let dEval = (x) => 'TBD';
|
|
59
72
|
//let dEval = (x) => (x >= 0 ? 1 : fEval(x,a)+a);
|
|
60
73
|
return new Activation({ a, fEval, dEval });
|
|
61
74
|
}
|
package/src/math/interval.mjs
CHANGED
|
@@ -3,11 +3,14 @@ const { EMPTY_SET, INFINITY } = Unicode;
|
|
|
3
3
|
import { ColorConsole } from '../text/color-console.mjs';
|
|
4
4
|
const { cc } = ColorConsole;
|
|
5
5
|
import { DBG } from '../defines.mjs';
|
|
6
|
+
import util from 'node:util';
|
|
6
7
|
|
|
7
8
|
const MINUS_INFINITY = `-${INFINITY}`;
|
|
8
9
|
const PLUS_INFINITY = `+${INFINITY}`;
|
|
9
10
|
|
|
10
11
|
export class Interval {
|
|
12
|
+
styleText = (text)=>text;
|
|
13
|
+
|
|
11
14
|
constructor(a, b, opts = {}) {
|
|
12
15
|
const msg = 'i6l.ctor';
|
|
13
16
|
let hi = null;
|
|
@@ -65,6 +68,10 @@ export class Interval {
|
|
|
65
68
|
return INFINITY;
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
get size(){
|
|
72
|
+
return this.hi - this.lo;
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
get isOpen() {
|
|
69
76
|
return this.leftOpen || this.rightOpen || this.isEmpty;
|
|
70
77
|
}
|
|
@@ -127,25 +134,28 @@ export class Interval {
|
|
|
127
134
|
|
|
128
135
|
toString() {
|
|
129
136
|
let { lo, hi, leftOpen, rightOpen, isEmpty } = this;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
let result = EMPTY_SET;
|
|
138
|
+
if (!isEmpty) {
|
|
139
|
+
if (lo === hi) {
|
|
140
|
+
result = [
|
|
141
|
+
leftOpen ? '(' : '[',
|
|
142
|
+
lo === INFINITY ? MINUS_INFINITY : lo,
|
|
143
|
+
lo == null ? '' : ',',
|
|
144
|
+
hi === INFINITY ? PLUS_INFINITY : hi,
|
|
145
|
+
rightOpen ? ')' : ']',
|
|
146
|
+
].join('');
|
|
147
|
+
} else {
|
|
148
|
+
result = [
|
|
149
|
+
leftOpen ? '(' : '[',
|
|
150
|
+
lo === INFINITY ? MINUS_INFINITY : lo,
|
|
151
|
+
lo === hi ? '' : ',',
|
|
152
|
+
hi === INFINITY ? PLUS_INFINITY : hi,
|
|
153
|
+
rightOpen ? ')' : ']',
|
|
154
|
+
].join('');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return Interval.styleText ? Interval.styleText(result) : result;
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
overlaps(iv2) {
|
|
@@ -185,4 +195,4 @@ export class Interval {
|
|
|
185
195
|
dbg && cc.fyi1(msg + 0.1, false);
|
|
186
196
|
return false;
|
|
187
197
|
}
|
|
188
|
-
}
|
|
198
|
+
} // Interval
|