es6-fuzz 6.0.8 → 6.0.9

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.
Files changed (2) hide show
  1. package/Readme.md +65 -70
  2. package/package.json +1 -1
package/Readme.md CHANGED
@@ -1,107 +1,96 @@
1
- # es6-fuzz
1
+ # es6-fuzz
2
2
 
3
- > Fuzzy Logic in Javascript
3
+ > Fuzzy Logic in JavaScript
4
4
 
5
5
  [![npm](https://img.shields.io/npm/dt/es6-fuzz.svg)](https://www.npmjs.com/package/es6-fuzz)
6
6
  [![license](https://img.shields.io/github/license/sebs/es6-fuzz.svg)](https://github.com/sebs/es6-fuzz/blob/master/LICENSE.md)
7
7
  [![GitHub tag](https://img.shields.io/github/tag/sebs/es6-fuzz.svg)](https://github.com/sebs/es6-fuzz)
8
8
  [![GitHub issues](https://img.shields.io/github/issues/sebs/es6-fuzz.svg)](https://github.com/sebs/es6-fuzz/issues)
9
9
 
10
- ## Supported fuzzyfiers
10
+ ## Supported Fuzzifiers
11
11
 
12
- * Constant
13
- * Grade
14
- * Reverse Grade
15
- * Sigmoid
16
- * Trapezoid
17
- * Triangle
12
+ * **Constant** - Fixed membership value
13
+ * **Grade** - Linear membership function
14
+ * **Reverse Grade** - Inverted linear membership
15
+ * **Sigmoid** - S-shaped membership curve
16
+ * **Trapezoid** - Trapezoidal membership function
17
+ * **Triangle** - Triangular membership function
18
18
 
19
- * [api docs](http://sebs.github.io/es6-fuzz)
20
- * [changelog](https://github.com/sebs/es6-fuzz/blob/master/docs/CHANGELOG.md)
19
+ ## Documentation
21
20
 
22
- ## Install and Usage
21
+ * [API Documentation](http://sebs.github.io/es6-fuzz)
22
+ * [Changelog](https://github.com/sebs/es6-fuzz/blob/master/docs/CHANGELOG.md)
23
23
 
24
- es6-fuzz is available as a NPM package.
24
+ ## Installation
25
25
 
26
- ```
26
+ ```bash
27
27
  npm install es6-fuzz
28
28
  ```
29
- ## Example
29
+
30
+ ## Quick Start
30
31
 
31
32
  ```javascript
32
- var logic = new Logic();
33
- var res = logic
33
+ const { Logic, Triangle, Trapezoid, Grade } = require('es6-fuzz');
34
+
35
+ const logic = new Logic();
36
+ const result = logic
34
37
  .init('noAttack', new Triangle(0, 20, 40))
35
38
  .or('normalAttack', new Trapezoid(20, 30, 90, 100))
36
39
  .or('enragedAttack', new Grade(90, 100))
37
- .defuzzify(40);
40
+ .defuzzify(40);
41
+
42
+ console.log(result); // 'enragedAttack'
38
43
  ```
39
- * enraged attack
40
44
 
41
- ## Example 2
45
+ ## Temperature Example
42
46
 
43
47
  <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/Fuzzy_logic_temperature_en.svg/300px-Fuzzy_logic_temperature_en.svg.png" />
44
48
 
45
49
  ```javascript
46
- var Trapezoid = require('./lib/curve/trapezoid');
50
+ const { Logic, Trapezoid } = require('es6-fuzz');
47
51
 
48
- var logic = new Logic();
49
- var res = logic
52
+ const logic = new Logic();
53
+ const result = logic
50
54
  .init('cold', new Trapezoid(0, 12, 18, 20))
51
55
  .or('hot', new Trapezoid(12, 14, 16, 100))
52
56
  .defuzzify(20);
53
57
 
58
+ console.log(result); // 'hot'
54
59
  ```
55
60
 
56
- * hot
57
-
58
-
59
- ## Usage with boon-js
60
-
61
- In order to combine 2 fuzzy functions with boolean logic, there is a compat layer for boon-js which allows the sauge of 'boolean expression language'.
62
-
63
- Example of a monster biting when its cold and you are close to it:
64
-
65
61
 
66
- Heat part:
62
+ ## Advanced Usage with boon-js
67
63
 
68
- ```js
69
- var logicHeat = new Logic();
70
- const optimalTemperature = new Triangle(10, 20, 30);
71
- const toColdTemperature = new Triangle(0, 10, 15);
72
- const toHotTemperature = new Triangle(25, 40, 60);
64
+ Combine multiple fuzzy functions with boolean logic using the boon-js compatibility layer.
73
65
 
74
- logicHeat.init('cold', toColdTemperature)
75
- logicHeat.or('optimal', optimalTemperature)
76
- logicHeat.or('hot', toHotTemperature);
77
- ```
78
-
79
- Distance Part
66
+ ### Example: Monster AI
80
67
 
81
- ```js
68
+ A monster that bites when it's cold AND you're close to it:
82
69
 
83
- var logicDistance = new Logic();
84
- const close = new Triangle(0, 10, 20);
85
- const far = new Triangle(5, 50, 100);
70
+ ```javascript
71
+ const { Logic, Triangle } = require('es6-fuzz');
72
+ const { getEvaluator } = require('boon-js');
86
73
 
87
- logicDistance.init('close', close)
88
- logicDistance.or('far', far)
74
+ // Temperature logic
75
+ const logicHeat = new Logic();
76
+ logicHeat.init('cold', new Triangle(0, 10, 15))
77
+ .or('optimal', new Triangle(10, 20, 30))
78
+ .or('hot', new Triangle(25, 40, 60));
89
79
 
90
- ```
80
+ // Distance logic
81
+ const logicDistance = new Logic();
82
+ logicDistance.init('close', new Triangle(0, 10, 20))
83
+ .or('far', new Triangle(5, 50, 100));
91
84
 
92
- Now we marry the 2 and use boon js
85
+ // Combine with boolean logic
86
+ const monsterBiteTest = getEvaluator('heat.cold AND distance.close');
93
87
 
94
- ```js
95
- const monsterBiteTest = getEvaluator(
96
- 'heat.cold AND distance.close',
97
- );
98
88
  const resHeat = logicHeat.defuzzify(2, 'heat');
99
89
  const resClose = logicDistance.defuzzify(2, 'distance');
100
90
 
101
- const jsBoonInput = { ...resHeat.boonJsInputs, ...resClose.boonJsInputs }
91
+ const jsBoonInput = { ...resHeat.boonJsInputs, ...resClose.boonJsInputs };
102
92
 
103
- monsterBiteTest(jsBoonInput)
104
- // returns true
93
+ console.log(monsterBiteTest(jsBoonInput)); // true
105
94
  ```
106
95
 
107
96
 
@@ -110,24 +99,30 @@ monsterBiteTest(jsBoonInput)
110
99
 
111
100
 
112
101
 
113
- ## development
102
+ ## Development
114
103
 
115
- **Tests** use node internal testing framework
104
+ ### Running Tests
116
105
 
117
- ```
106
+ ```bash
118
107
  npm test
119
108
  ```
120
109
 
121
- * docs: npm run docs, npm run docs:site
110
+ ### Building Documentation
111
+
112
+ ```bash
113
+ npm run docs # Generate API docs
114
+ npm run docs:site # Build documentation site
115
+ ```
116
+
117
+ ## Requirements
122
118
 
123
- # Stuff
124
- * http://de.slideshare.net/BCSLeicester/fuzzy-logic-in-the-real-world-2326817
125
- * http://computing.dcu.ie/~humphrys/Notes/Neural/sigmoid.html
119
+ * Node.js 20+
126
120
 
127
- ## Supported Node.js Versions
121
+ ## Resources
128
122
 
129
- Versions: 20+
123
+ * [Fuzzy Logic in the Real World](http://de.slideshare.net/BCSLeicester/fuzzy-logic-in-the-real-world-2326817)
124
+ * [Understanding Sigmoid Functions](http://computing.dcu.ie/~humphrys/Notes/Neural/sigmoid.html)
130
125
 
131
- ## Related
126
+ ## Related Projects
132
127
 
133
- * https://www.npmjs.com/package/gaussian
128
+ * [gaussian](https://www.npmjs.com/package/gaussian) - Gaussian distribution functions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es6-fuzz",
3
3
  "description": "fuzzy logic with and for es6",
4
- "version": "6.0.8",
4
+ "version": "6.0.9",
5
5
  "main": "lib/logic.js",
6
6
  "repository": "git@github.com:sebs/es6-fuzz.git",
7
7
  "homepage": "https://github.com/sebs/es6-fuzz",