es6-fuzz 6.0.8 → 7.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/CONTRIBUTING.md +87 -0
- package/Readme.md +82 -71
- package/SECURITY.md +4 -5
- package/lib/curve/constant.d.ts +4 -3
- package/lib/curve/constant.d.ts.map +1 -1
- package/lib/curve/constant.js +5 -2
- package/lib/curve/constant.js.map +1 -1
- package/lib/curve/fuzzifier.d.ts +17 -0
- package/lib/curve/fuzzifier.d.ts.map +1 -0
- package/lib/curve/fuzzifier.js +3 -0
- package/lib/curve/fuzzifier.js.map +1 -0
- package/lib/curve/fuzzy-function.d.ts +2 -1
- package/lib/curve/fuzzy-function.d.ts.map +1 -1
- package/lib/curve/fuzzy-function.js +1 -1
- package/lib/curve/fuzzy-function.js.map +1 -1
- package/lib/curve/grade.d.ts +6 -0
- package/lib/curve/grade.d.ts.map +1 -1
- package/lib/curve/grade.js +14 -4
- package/lib/curve/grade.js.map +1 -1
- package/lib/curve/reverse-grade.d.ts +11 -1
- package/lib/curve/reverse-grade.d.ts.map +1 -1
- package/lib/curve/reverse-grade.js +25 -17
- package/lib/curve/reverse-grade.js.map +1 -1
- package/lib/curve/shape.d.ts +2 -1
- package/lib/curve/shape.d.ts.map +1 -1
- package/lib/curve/shape.js +4 -4
- package/lib/curve/shape.js.map +1 -1
- package/lib/curve/sigmoid.d.ts +5 -2
- package/lib/curve/sigmoid.d.ts.map +1 -1
- package/lib/curve/sigmoid.js +3 -1
- package/lib/curve/sigmoid.js.map +1 -1
- package/lib/curve/trapezoid.js +4 -4
- package/lib/curve/trapezoid.js.map +1 -1
- package/lib/curve/triangle.d.ts +7 -0
- package/lib/curve/triangle.d.ts.map +1 -1
- package/lib/curve/triangle.js +11 -2
- package/lib/curve/triangle.js.map +1 -1
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -0
- package/lib/logic.d.ts +62 -5
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +96 -40
- package/lib/logic.js.map +1 -1
- package/lib/render-examples.js +92 -36
- package/lib/render-examples.js.map +1 -1
- package/lib/svg-renderer.d.ts.map +1 -1
- package/lib/svg-renderer.js +18 -9
- package/lib/svg-renderer.js.map +1 -1
- package/package.json +25 -16
package/lib/curve/sigmoid.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fuzzifier } from './fuzzifier';
|
|
1
2
|
/**
|
|
2
3
|
* Class representing a Sigmoid.
|
|
3
4
|
* @example
|
|
@@ -5,13 +6,15 @@
|
|
|
5
6
|
* sigmoid = new Sigmoid(0, 100000);
|
|
6
7
|
* sigmoid2.fuzzify(10);
|
|
7
8
|
*/
|
|
8
|
-
export declare class Sigmoid {
|
|
9
|
+
export declare class Sigmoid implements Fuzzifier {
|
|
9
10
|
private readonly center;
|
|
10
11
|
private readonly slope;
|
|
11
12
|
/**
|
|
12
13
|
* Create a Sigmoid Function.
|
|
13
14
|
* @param {number} center - The center point of the sigmoid curve (where it outputs 0.5)
|
|
14
|
-
* @param {number} slope -
|
|
15
|
+
* @param {number} slope - Width of the transition: it appears in the denominator
|
|
16
|
+
* as 1 / (1 + exp(-(x - center) / slope)), so a smaller slope means a steeper
|
|
17
|
+
* transition and a larger slope a gentler one.
|
|
15
18
|
*/
|
|
16
19
|
constructor(center?: number, slope?: number);
|
|
17
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sigmoid.d.ts","sourceRoot":"","sources":["../../src/curve/sigmoid.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,qBAAa,
|
|
1
|
+
{"version":3,"file":"sigmoid.d.ts","sourceRoot":"","sources":["../../src/curve/sigmoid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC;;;;;;GAMG;AACH,qBAAa,OAAQ,YAAW,SAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B;;;;;;OAMG;gBACS,MAAM,GAAE,MAAU,EAAE,KAAK,GAAE,MAAU;IAIjD;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;CAS3B"}
|
package/lib/curve/sigmoid.js
CHANGED
|
@@ -14,7 +14,9 @@ class Sigmoid {
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a Sigmoid Function.
|
|
16
16
|
* @param {number} center - The center point of the sigmoid curve (where it outputs 0.5)
|
|
17
|
-
* @param {number} slope -
|
|
17
|
+
* @param {number} slope - Width of the transition: it appears in the denominator
|
|
18
|
+
* as 1 / (1 + exp(-(x - center) / slope)), so a smaller slope means a steeper
|
|
19
|
+
* transition and a larger slope a gentler one.
|
|
18
20
|
*/
|
|
19
21
|
constructor(center = 0, slope = 1) {
|
|
20
22
|
this.center = center;
|
package/lib/curve/sigmoid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sigmoid.js","sourceRoot":"","sources":["../../src/curve/sigmoid.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;
|
|
1
|
+
{"version":3,"file":"sigmoid.js","sourceRoot":"","sources":["../../src/curve/sigmoid.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb;;;;;;GAMG;AACH,MAAa,OAAO;IACD,MAAM,CAAS;IACf,KAAK,CAAS;IAE/B;;;;;;OAMG;IACH,YAAY,SAAiB,CAAC,EAAE,QAAgB,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAC,CAAS;QACf,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;YACrB,mDAAmD;YACnD,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAC;YAC9B,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAC;YAC9B,OAAO,GAAG,CAAC,CAAC,kBAAkB;QAChC,CAAC;QACD,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACjE,CAAC;CACF;AA7BD,0BA6BC"}
|
package/lib/curve/trapezoid.js
CHANGED
|
@@ -36,16 +36,16 @@ class Trapezoid extends shape_1.Shape {
|
|
|
36
36
|
else if (x >= this.x3) {
|
|
37
37
|
result = 0;
|
|
38
38
|
}
|
|
39
|
-
else if (
|
|
39
|
+
else if (x >= this.x1 && x <= this.x2) {
|
|
40
40
|
result = 1;
|
|
41
41
|
}
|
|
42
|
-
else if (
|
|
42
|
+
else if (x > this.x0 && x < this.x1) {
|
|
43
43
|
// Handle case where x0 = x1 (vertical left edge)
|
|
44
44
|
if (this.x1 === this.x0) {
|
|
45
45
|
result = 1;
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
result =
|
|
48
|
+
result = x / (this.x1 - this.x0) - this.x0 / (this.x1 - this.x0);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
@@ -54,7 +54,7 @@ class Trapezoid extends shape_1.Shape {
|
|
|
54
54
|
result = 1;
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
result =
|
|
57
|
+
result = -x / (this.x3 - this.x2) + this.x3 / (this.x3 - this.x2);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trapezoid.js","sourceRoot":"","sources":["../../src/curve/trapezoid.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,mCAAgC;AAChC;;;;GAIG;AACH,MAAa,SAA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EAAE,EAAE,CAAC;gBACxB,MAAM,GAAG,CAAC,CAAC;YACb,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;gBACxB,MAAM,GAAG,CAAC,CAAC;YACb,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA9CD,8BA8CC"}
|
package/lib/curve/triangle.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ import { Shape } from './shape';
|
|
|
5
5
|
* new Triangle(0, 10, 20)
|
|
6
6
|
*/
|
|
7
7
|
export declare class Triangle extends Shape {
|
|
8
|
+
/**
|
|
9
|
+
* Create a Triangle.
|
|
10
|
+
* @param {number} x0 - left base point
|
|
11
|
+
* @param {number} x1 - peak
|
|
12
|
+
* @param {number} x2 - right base point
|
|
13
|
+
*/
|
|
14
|
+
constructor(x0: number, x1: number, x2: number);
|
|
8
15
|
/**
|
|
9
16
|
* Fuzzify
|
|
10
17
|
* @param {number} x - Point on X axis
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triangle.d.ts","sourceRoot":"","sources":["../../src/curve/triangle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;CAwC3B"}
|
|
1
|
+
{"version":3,"file":"triangle.d.ts","sourceRoot":"","sources":["../../src/curve/triangle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC;;;;;OAKG;gBACS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAG9C;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;CAwC3B"}
|
package/lib/curve/triangle.js
CHANGED
|
@@ -8,6 +8,15 @@ const shape_1 = require("./shape");
|
|
|
8
8
|
* new Triangle(0, 10, 20)
|
|
9
9
|
*/
|
|
10
10
|
class Triangle extends shape_1.Shape {
|
|
11
|
+
/**
|
|
12
|
+
* Create a Triangle.
|
|
13
|
+
* @param {number} x0 - left base point
|
|
14
|
+
* @param {number} x1 - peak
|
|
15
|
+
* @param {number} x2 - right base point
|
|
16
|
+
*/
|
|
17
|
+
constructor(x0, x1, x2) {
|
|
18
|
+
super(x0, x1, x2, x2);
|
|
19
|
+
}
|
|
11
20
|
/**
|
|
12
21
|
* Fuzzify
|
|
13
22
|
* @param {number} x - Point on X axis
|
|
@@ -50,10 +59,10 @@ class Triangle extends shape_1.Shape {
|
|
|
50
59
|
else if (x >= this.x2) {
|
|
51
60
|
result = 0;
|
|
52
61
|
}
|
|
53
|
-
else if (
|
|
62
|
+
else if (x > this.x0 && x <= this.x1) {
|
|
54
63
|
result = (x - this.x0) / (this.x1 - this.x0);
|
|
55
64
|
}
|
|
56
|
-
else if (
|
|
65
|
+
else if (x > this.x1 && x < this.x2) {
|
|
57
66
|
result = (this.x2 - x) / (this.x2 - this.x1);
|
|
58
67
|
}
|
|
59
68
|
return result;
|
|
@@ -1 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AC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAvDD,4BAuDC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Logic } from './logic';
|
|
2
|
+
export { Shape } from './curve/shape';
|
|
3
|
+
export { Fuzzifier } from './curve/fuzzifier';
|
|
4
|
+
export { Grade } from './curve/grade';
|
|
5
|
+
export { ReverseGrade } from './curve/reverse-grade';
|
|
6
|
+
export { Triangle } from './curve/triangle';
|
|
7
|
+
export { Trapezoid } from './curve/trapezoid';
|
|
8
|
+
export { Constant } from './curve/constant';
|
|
9
|
+
export { FuzzyFunction } from './curve/fuzzy-function';
|
|
10
|
+
export { Sigmoid } from './curve/sigmoid';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sigmoid = exports.FuzzyFunction = exports.Constant = exports.Trapezoid = exports.Triangle = exports.ReverseGrade = exports.Grade = exports.Shape = exports.Logic = void 0;
|
|
4
|
+
var logic_1 = require("./logic");
|
|
5
|
+
Object.defineProperty(exports, "Logic", { enumerable: true, get: function () { return logic_1.Logic; } });
|
|
6
|
+
var shape_1 = require("./curve/shape");
|
|
7
|
+
Object.defineProperty(exports, "Shape", { enumerable: true, get: function () { return shape_1.Shape; } });
|
|
8
|
+
var grade_1 = require("./curve/grade");
|
|
9
|
+
Object.defineProperty(exports, "Grade", { enumerable: true, get: function () { return grade_1.Grade; } });
|
|
10
|
+
var reverse_grade_1 = require("./curve/reverse-grade");
|
|
11
|
+
Object.defineProperty(exports, "ReverseGrade", { enumerable: true, get: function () { return reverse_grade_1.ReverseGrade; } });
|
|
12
|
+
var triangle_1 = require("./curve/triangle");
|
|
13
|
+
Object.defineProperty(exports, "Triangle", { enumerable: true, get: function () { return triangle_1.Triangle; } });
|
|
14
|
+
var trapezoid_1 = require("./curve/trapezoid");
|
|
15
|
+
Object.defineProperty(exports, "Trapezoid", { enumerable: true, get: function () { return trapezoid_1.Trapezoid; } });
|
|
16
|
+
var constant_1 = require("./curve/constant");
|
|
17
|
+
Object.defineProperty(exports, "Constant", { enumerable: true, get: function () { return constant_1.Constant; } });
|
|
18
|
+
var fuzzy_function_1 = require("./curve/fuzzy-function");
|
|
19
|
+
Object.defineProperty(exports, "FuzzyFunction", { enumerable: true, get: function () { return fuzzy_function_1.FuzzyFunction; } });
|
|
20
|
+
var sigmoid_1 = require("./curve/sigmoid");
|
|
21
|
+
Object.defineProperty(exports, "Sigmoid", { enumerable: true, get: function () { return sigmoid_1.Sigmoid; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,uCAAsC;AAA7B,8FAAA,KAAK,OAAA;AAEd,uCAAsC;AAA7B,8FAAA,KAAK,OAAA;AACd,uDAAqD;AAA5C,6GAAA,YAAY,OAAA;AACrB,6CAA4C;AAAnC,oGAAA,QAAQ,OAAA;AACjB,+CAA8C;AAArC,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,oGAAA,QAAQ,OAAA;AACjB,yDAAuD;AAA9C,+GAAA,aAAa,OAAA;AACtB,2CAA0C;AAAjC,kGAAA,OAAO,OAAA"}
|
package/lib/logic.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Shape } from './curve/shape';
|
|
2
|
+
import { Fuzzifier } from './curve/fuzzifier';
|
|
2
3
|
import { Grade } from './curve/grade';
|
|
3
4
|
import { ReverseGrade } from './curve/reverse-grade';
|
|
4
5
|
import { Triangle } from './curve/triangle';
|
|
@@ -10,6 +11,11 @@ import { Sigmoid } from './curve/sigmoid';
|
|
|
10
11
|
export declare class Logic {
|
|
11
12
|
private initCalled;
|
|
12
13
|
private rules;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Redundant with the package's named exports. Import the shape
|
|
16
|
+
* classes directly instead, e.g. `import { Triangle } from 'es6-fuzz'`.
|
|
17
|
+
* Kept for backwards compatibility and slated for removal in the next major.
|
|
18
|
+
*/
|
|
13
19
|
c: {
|
|
14
20
|
Shape: typeof Shape;
|
|
15
21
|
Grade: typeof Grade;
|
|
@@ -23,17 +29,68 @@ export declare class Logic {
|
|
|
23
29
|
constructor();
|
|
24
30
|
private checkInitCalled;
|
|
25
31
|
private checkOutputName;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Registers the first rule. Must be called before {@link and}, {@link or},
|
|
34
|
+
* {@link not} or {@link defuzzify}.
|
|
35
|
+
*
|
|
36
|
+
* Rule composition is sequential and order-dependent: at {@link defuzzify}
|
|
37
|
+
* time each rule's membership is folded into a single value that is carried
|
|
38
|
+
* to the next rule (see {@link and}). `init` and `or` start a fresh value
|
|
39
|
+
* from the rule's own shape; `and` narrows it; `not` inverts it.
|
|
40
|
+
*
|
|
41
|
+
* @param output Output label, letters only (`/^[a-z]+$/i`), must be unique.
|
|
42
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
43
|
+
*/
|
|
44
|
+
init(output: string, shape: Fuzzifier): this;
|
|
45
|
+
/**
|
|
46
|
+
* Narrows the carried membership with `min(previous, shape(value))`
|
|
47
|
+
* (the standard fuzzy-AND / T-norm). Because `previous` is whatever the
|
|
48
|
+
* immediately preceding rule produced, `and` is order-dependent — it
|
|
49
|
+
* composes against the prior rule in the chain, not a grouped rule set.
|
|
50
|
+
*
|
|
51
|
+
* @param output Output label, letters only, must be unique.
|
|
52
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
53
|
+
*/
|
|
54
|
+
and(output: string, shape: Fuzzifier): this;
|
|
55
|
+
/**
|
|
56
|
+
* Starts a fresh membership from this rule's own shape value, ignoring the
|
|
57
|
+
* value carried from previous rules (fuzzy-OR / max is applied implicitly by
|
|
58
|
+
* {@link defuzzify} picking the single highest membership across all rules).
|
|
59
|
+
*
|
|
60
|
+
* @param output Output label, letters only, must be unique.
|
|
61
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
62
|
+
*/
|
|
63
|
+
or(output: string, shape: Fuzzifier): this;
|
|
64
|
+
/**
|
|
65
|
+
* Inverts this rule's shape value: `1 - shape(value)` (fuzzy-NOT /
|
|
66
|
+
* complement). Like {@link or}, it does not depend on the carried value.
|
|
67
|
+
*
|
|
68
|
+
* @param output Output label, letters only, must be unique.
|
|
69
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
70
|
+
*/
|
|
71
|
+
not(output: string, shape: Fuzzifier): this;
|
|
72
|
+
/**
|
|
73
|
+
* Evaluates every rule for `value` and returns the result.
|
|
74
|
+
*
|
|
75
|
+
* Note on terminology: this performs **max-membership classification**, not
|
|
76
|
+
* centroid / center-of-gravity defuzzification. It returns the *label* of the
|
|
77
|
+
* rule with the highest membership (`defuzzified`) together with that
|
|
78
|
+
* membership degree (`fuzzified`) — it does not compute a crisp output
|
|
79
|
+
* number. On ties the earliest rule wins (strict greater-than).
|
|
80
|
+
*
|
|
81
|
+
* @param value Crisp input fed to every rule's shape.
|
|
82
|
+
* @param as Optional namespace prefix for {@link DefuzzifyResult.boonJsInputs}
|
|
83
|
+
* keys, e.g. `'heat'` yields `heat.cold`. Useful when merging the inputs of
|
|
84
|
+
* several `Logic` instances for boon-js evaluation.
|
|
85
|
+
* @example logic.defuzzify(10)
|
|
86
|
+
*/
|
|
30
87
|
defuzzify(value: number, as?: string): Logic.DefuzzifyResult;
|
|
31
88
|
}
|
|
32
89
|
export declare namespace Logic {
|
|
33
90
|
type RuleType = 'init' | 'and' | 'or' | 'not';
|
|
34
91
|
interface Rule {
|
|
35
92
|
output: string;
|
|
36
|
-
shape:
|
|
93
|
+
shape: Fuzzifier;
|
|
37
94
|
type: RuleType;
|
|
38
95
|
fuzzy?: number;
|
|
39
96
|
}
|
package/lib/logic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAA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
15
15
|
const TYPE_NOT = 'not';
|
|
16
|
+
/**
|
|
17
|
+
* Maps a rule to the membership degree of its output, given the membership
|
|
18
|
+
* carried along the chain so far (`prev`) and this rule's own shape value
|
|
19
|
+
* (`raw`). The winning output is then the one with the highest membership.
|
|
20
|
+
*/
|
|
16
21
|
const ruleEngine = {
|
|
17
|
-
|
|
18
|
-
return
|
|
22
|
+
init(_prev, raw) {
|
|
23
|
+
return raw;
|
|
19
24
|
},
|
|
20
|
-
or(
|
|
21
|
-
return
|
|
25
|
+
or(_prev, raw) {
|
|
26
|
+
return raw;
|
|
27
|
+
},
|
|
28
|
+
and(prev, raw) {
|
|
29
|
+
return Math.min(prev, raw);
|
|
30
|
+
},
|
|
31
|
+
not(_prev, raw) {
|
|
32
|
+
return 1 - raw;
|
|
22
33
|
},
|
|
23
|
-
not(a, b = null, value) {
|
|
24
|
-
return 1 - a.fuzzify(value);
|
|
25
|
-
}
|
|
26
34
|
};
|
|
27
35
|
/** Class helping with FuzzyLogic. */
|
|
28
36
|
class Logic {
|
|
29
37
|
initCalled = false;
|
|
30
38
|
rules = [];
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Redundant with the package's named exports. Import the shape
|
|
41
|
+
* classes directly instead, e.g. `import { Triangle } from 'es6-fuzz'`.
|
|
42
|
+
* Kept for backwards compatibility and slated for removal in the next major.
|
|
43
|
+
*/
|
|
31
44
|
c;
|
|
32
45
|
constructor() {
|
|
33
46
|
this.c = {
|
|
@@ -38,7 +51,7 @@ class Logic {
|
|
|
38
51
|
Triangle: triangle_1.Triangle,
|
|
39
52
|
Constant: constant_1.Constant,
|
|
40
53
|
FuzzyFunction: fuzzy_function_1.FuzzyFunction,
|
|
41
|
-
Sigmoid: sigmoid_1.Sigmoid
|
|
54
|
+
Sigmoid: sigmoid_1.Sigmoid,
|
|
42
55
|
};
|
|
43
56
|
}
|
|
44
57
|
checkInitCalled() {
|
|
@@ -51,7 +64,22 @@ class Logic {
|
|
|
51
64
|
if (!reg.test(name)) {
|
|
52
65
|
throw Error('Output names can only be strings without space, without numbers and without special chars');
|
|
53
66
|
}
|
|
67
|
+
if (this.rules.some((rule) => rule.output === name)) {
|
|
68
|
+
throw Error('Output name "' + name + '" is already in use');
|
|
69
|
+
}
|
|
54
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Registers the first rule. Must be called before {@link and}, {@link or},
|
|
73
|
+
* {@link not} or {@link defuzzify}.
|
|
74
|
+
*
|
|
75
|
+
* Rule composition is sequential and order-dependent: at {@link defuzzify}
|
|
76
|
+
* time each rule's membership is folded into a single value that is carried
|
|
77
|
+
* to the next rule (see {@link and}). `init` and `or` start a fresh value
|
|
78
|
+
* from the rule's own shape; `and` narrows it; `not` inverts it.
|
|
79
|
+
*
|
|
80
|
+
* @param output Output label, letters only (`/^[a-z]+$/i`), must be unique.
|
|
81
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
82
|
+
*/
|
|
55
83
|
init(output, shape) {
|
|
56
84
|
this.checkOutputName(output);
|
|
57
85
|
this.initCalled = true;
|
|
@@ -59,79 +87,107 @@ class Logic {
|
|
|
59
87
|
this.rules.push({ output, shape, type });
|
|
60
88
|
return this;
|
|
61
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Narrows the carried membership with `min(previous, shape(value))`
|
|
92
|
+
* (the standard fuzzy-AND / T-norm). Because `previous` is whatever the
|
|
93
|
+
* immediately preceding rule produced, `and` is order-dependent — it
|
|
94
|
+
* composes against the prior rule in the chain, not a grouped rule set.
|
|
95
|
+
*
|
|
96
|
+
* @param output Output label, letters only, must be unique.
|
|
97
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
98
|
+
*/
|
|
62
99
|
and(output, shape) {
|
|
63
|
-
this.checkOutputName(output);
|
|
64
100
|
this.checkInitCalled();
|
|
101
|
+
this.checkOutputName(output);
|
|
65
102
|
const type = TYPE_AND;
|
|
66
103
|
this.rules.push({ output, shape, type });
|
|
67
104
|
return this;
|
|
68
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Starts a fresh membership from this rule's own shape value, ignoring the
|
|
108
|
+
* value carried from previous rules (fuzzy-OR / max is applied implicitly by
|
|
109
|
+
* {@link defuzzify} picking the single highest membership across all rules).
|
|
110
|
+
*
|
|
111
|
+
* @param output Output label, letters only, must be unique.
|
|
112
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
113
|
+
*/
|
|
69
114
|
or(output, shape) {
|
|
70
|
-
this.checkOutputName(output);
|
|
71
115
|
this.checkInitCalled();
|
|
116
|
+
this.checkOutputName(output);
|
|
72
117
|
const type = TYPE_OR;
|
|
73
118
|
this.rules.push({ output, shape, type });
|
|
74
119
|
return this;
|
|
75
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Inverts this rule's shape value: `1 - shape(value)` (fuzzy-NOT /
|
|
123
|
+
* complement). Like {@link or}, it does not depend on the carried value.
|
|
124
|
+
*
|
|
125
|
+
* @param output Output label, letters only, must be unique.
|
|
126
|
+
* @param shape Fuzzifier mapping a crisp input to a membership degree 0..1.
|
|
127
|
+
*/
|
|
76
128
|
not(output, shape) {
|
|
77
|
-
this.checkOutputName(output);
|
|
78
129
|
this.checkInitCalled();
|
|
130
|
+
this.checkOutputName(output);
|
|
79
131
|
const type = TYPE_NOT;
|
|
80
132
|
this.rules.push({ output, shape, type });
|
|
81
133
|
return this;
|
|
82
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Evaluates every rule for `value` and returns the result.
|
|
137
|
+
*
|
|
138
|
+
* Note on terminology: this performs **max-membership classification**, not
|
|
139
|
+
* centroid / center-of-gravity defuzzification. It returns the *label* of the
|
|
140
|
+
* rule with the highest membership (`defuzzified`) together with that
|
|
141
|
+
* membership degree (`fuzzified`) — it does not compute a crisp output
|
|
142
|
+
* number. On ties the earliest rule wins (strict greater-than).
|
|
143
|
+
*
|
|
144
|
+
* @param value Crisp input fed to every rule's shape.
|
|
145
|
+
* @param as Optional namespace prefix for {@link DefuzzifyResult.boonJsInputs}
|
|
146
|
+
* keys, e.g. `'heat'` yields `heat.cold`. Useful when merging the inputs of
|
|
147
|
+
* several `Logic` instances for boon-js evaluation.
|
|
148
|
+
* @example logic.defuzzify(10)
|
|
149
|
+
*/
|
|
83
150
|
defuzzify(value, as) {
|
|
84
151
|
this.checkInitCalled();
|
|
85
152
|
let defuzzified = 'none';
|
|
86
153
|
let fuzzified = 0;
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
154
|
+
let best = -Infinity;
|
|
155
|
+
// membership carried along the chain, used by AND to narrow the result
|
|
156
|
+
let running = 0;
|
|
157
|
+
// Evaluate into fresh rule copies so the engine's internal state is never
|
|
158
|
+
// mutated or handed out to the caller.
|
|
159
|
+
const rules = this.rules.map((rule) => {
|
|
160
|
+
const raw = rule.shape.fuzzify(value);
|
|
161
|
+
const membership = ruleEngine[rule.type](running, raw);
|
|
162
|
+
running = membership;
|
|
163
|
+
// max-membership defuzzification: highest membership wins, ties keep
|
|
164
|
+
// the earliest rule (strict greater-than)
|
|
165
|
+
if (membership > best) {
|
|
166
|
+
best = membership;
|
|
92
167
|
defuzzified = rule.output;
|
|
93
|
-
fuzzified =
|
|
94
|
-
lastShape = rule.shape;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
if (!lastShape)
|
|
99
|
-
return;
|
|
100
|
-
const fuzzyCompRes = ruleEngine[rule.type](lastShape, rule.shape, value);
|
|
101
|
-
lastShape.fuzzify(value);
|
|
102
|
-
// old value is kept, not is not yet implemented
|
|
103
|
-
if (fuzzyCompRes === lastShape.fuzzify(value)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
defuzzified = rule.output;
|
|
107
|
-
fuzzified = rule.fuzzy;
|
|
108
|
-
// if there is no shape, like for example for a NOT keep the last one
|
|
109
|
-
lastShape = rule.shape || lastShape;
|
|
168
|
+
fuzzified = membership;
|
|
110
169
|
}
|
|
170
|
+
return { ...rule, fuzzy: membership };
|
|
111
171
|
});
|
|
112
172
|
let namePrefix = '';
|
|
113
173
|
if (as && typeof as === 'string') {
|
|
114
174
|
namePrefix = as + '.';
|
|
115
175
|
}
|
|
116
176
|
const boonJsInputs = {};
|
|
117
|
-
|
|
177
|
+
rules.forEach((rule) => {
|
|
118
178
|
boonJsInputs[`${namePrefix}${rule.output}`] = rule.output === defuzzified;
|
|
119
179
|
});
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
* @example fuzzy.defuzzify(10)
|
|
123
|
-
*/
|
|
124
180
|
return {
|
|
125
181
|
boonJsInputs,
|
|
126
182
|
fuzzified: fuzzified,
|
|
127
183
|
defuzzified: defuzzified,
|
|
128
|
-
rules
|
|
184
|
+
rules,
|
|
129
185
|
valueOf() {
|
|
130
186
|
return fuzzified;
|
|
131
187
|
},
|
|
132
188
|
toString() {
|
|
133
189
|
return defuzzified;
|
|
134
|
-
}
|
|
190
|
+
},
|
|
135
191
|
};
|
|
136
192
|
}
|
|
137
193
|
}
|
package/lib/logic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic.js","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"logic.js","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,yCAAsC;AAEtC,yCAAsC;AACtC,yDAAqD;AACrD,+CAA4C;AAC5C,iDAA8C;AAC9C,+CAA4C;AAC5C,2DAAuD;AACvD,6CAA0C;AAE1C,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,QAAQ,GAAG,KAAK,CAAC;AACvB,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,QAAQ,GAAG,KAAK,CAAC;AAKvB;;;;GAIG;AACH,MAAM,UAAU,GAAkE;IAChF,IAAI,CAAC,KAAa,EAAE,GAAW;QAC7B,OAAO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