tiny-essentials 1.25.3 → 1.25.5
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/changelog/1/25/3.md +6 -0
- package/changelog/1/25/4.md +3 -0
- package/dist/v1/TinyArrayComparator.min.js +1 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyMaInSys.min.js +1 -0
- package/dist/v1/build/TinyArrayComparator.cjs +7 -0
- package/dist/v1/build/TinyArrayComparator.d.mts +3 -0
- package/dist/v1/build/TinyArrayComparator.mjs +2 -0
- package/dist/v1/index.cjs +7 -0
- package/dist/v1/index.d.mts +6 -1
- package/dist/v1/index.mjs +4 -2
- package/dist/v1/libs/TinyArrayComparator.cjs +130 -0
- package/dist/v1/libs/TinyArrayComparator.d.mts +79 -0
- package/dist/v1/libs/TinyArrayComparator.mjs +112 -0
- package/dist/v1/libs/TinyMamdaniInferenceSystem.cjs +273 -0
- package/dist/v1/libs/TinyMamdaniInferenceSystem.d.mts +84 -0
- package/dist/v1/libs/TinyMamdaniInferenceSystem.mjs +233 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/libs/TinyArrayComparator.md +101 -0
- package/docs/v1/libs/TinyMamdaniInferenceSystem.md +103 -0
- package/package.json +9 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# 🧠 Fuzzy Logic Engine Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the official documentation for the **Fuzzy Logic Engine**! 🚀 This robust, type-safe JavaScript module provides a implementation of a Mamdani Inference System, allowing you to model logic using trapezoidal membership functions.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛠️ Core Utilities
|
|
8
|
+
|
|
9
|
+
### 📐 `trapezoid(value, a, b, c, d)`
|
|
10
|
+
A high-performance utility to safely calculate the fuzzy membership degree using a trapezoidal shape. It includes built-in protections against division by zero and short-circuit optimizations.
|
|
11
|
+
|
|
12
|
+
**Parameters:**
|
|
13
|
+
| Parameter | Type | Description |
|
|
14
|
+
| :--- | :--- | :--- |
|
|
15
|
+
| `value` | `number` | The crisp input value to check. |
|
|
16
|
+
| `a` | `number` | Start of the rise (membership = 0). |
|
|
17
|
+
| `b` | `number` | End of the rise / start of plateau (membership = 1). |
|
|
18
|
+
| `c` | `number` | Start of the fall / end of plateau (membership = 1). |
|
|
19
|
+
| `d` | `number` | End of the fall (membership = 0). |
|
|
20
|
+
|
|
21
|
+
**Returns:** * `number` - The degree of membership, safely clamped between `[0, 1]`.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
### 🎯 `defuzzifyCentroid(fuzzyOutput, outputSets, step = 0.5)`
|
|
26
|
+
Performs defuzzification using the highly accurate Centroid (Center of Gravity) numerical integration method.
|
|
27
|
+
|
|
28
|
+
* **Parameters:**
|
|
29
|
+
|
|
30
|
+
| Parameter | Type | Description |
|
|
31
|
+
| :--- | :--- | :--- |
|
|
32
|
+
| `fuzzyOutput` | `Object.<string, number>` | The evaluated rule strengths (e.g., `{"High": 0.8, "Medium": 0.2}`). |
|
|
33
|
+
| `outputSets` | `FuzzySet[]` | The array of sets defining the output spectrum. |
|
|
34
|
+
| `step` | `number`, optional | Resolution of the integral approximation. Default is `0.5`. |
|
|
35
|
+
|
|
36
|
+
* **Returns:** `number` - The final, precise crisp output value.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🏗️ Classes
|
|
41
|
+
|
|
42
|
+
### 🟦 `FuzzySet`
|
|
43
|
+
Represents a single linguistic term (e.g., "Cold", "High", "Severe") defined by a trapezoidal membership function. It includes strict type validations for all its properties.
|
|
44
|
+
|
|
45
|
+
#### ⚙️ Constructor
|
|
46
|
+
```javascript
|
|
47
|
+
new FuzzySet(name, a, b, c, d)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### 📦 Properties
|
|
51
|
+
* **`name`** (`string`): The name of the fuzzy set.
|
|
52
|
+
* **`a`, `b`, `c`, `d`** (`number`): The coordinates defining the trapezoidal shape.
|
|
53
|
+
|
|
54
|
+
#### 🧮 Methods
|
|
55
|
+
* **`calculate(x)`**
|
|
56
|
+
Calculates the membership degree for a specific input using the set's coordinates.
|
|
57
|
+
* **Parameters:** `x` (`number`) - The crisp input value.
|
|
58
|
+
* **Returns:** `number` - Degree of membership `[0, 1]`.
|
|
59
|
+
|
|
60
|
+
* **`static trapezoid(value, a, b, c, d)`**
|
|
61
|
+
Static wrapper for the global `trapezoid` utility.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### 🧠 `MamdaniInferenceSystem`
|
|
66
|
+
The core engine that handles the storage of linguistic variables, performs fuzzification, evaluates rules, and calculates the final crisp output via defuzzification.
|
|
67
|
+
|
|
68
|
+
#### ⚙️ Constructor
|
|
69
|
+
```javascript
|
|
70
|
+
const engine = new MamdaniInferenceSystem();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 🧮 Variable Management Methods
|
|
74
|
+
|
|
75
|
+
* **`addVariable(name, sets)`** ➕
|
|
76
|
+
Registers a new linguistic variable and its associated fuzzy sets.
|
|
77
|
+
* **Parameters:** * `name` (`string`) - The variable's name (e.g., "temperature").
|
|
78
|
+
* `sets` (`FuzzySet[]`) - An array of `FuzzySet` instances.
|
|
79
|
+
|
|
80
|
+
* **`removeVariable(name)`** 🗑️
|
|
81
|
+
Deletes a linguistic variable from the engine.
|
|
82
|
+
* **Parameters:** `name` (`string`) - The variable's name.
|
|
83
|
+
* **Returns:** `boolean` - `true` if successfully removed.
|
|
84
|
+
|
|
85
|
+
* **`getVariable(name)`** 🔍
|
|
86
|
+
Retrieves a cloned array of the fuzzy sets for a specific variable.
|
|
87
|
+
* **Parameters:** `name` (`string`) - The variable's name.
|
|
88
|
+
* **Returns:** `FuzzySet[]`
|
|
89
|
+
* **Throws:** `Error` if the variable is not found.
|
|
90
|
+
|
|
91
|
+
* **`hasVariable(name)`** ❓
|
|
92
|
+
Checks if a variable is registered in the engine.
|
|
93
|
+
* **Parameters:** `name` (`string`) - The variable's name.
|
|
94
|
+
* **Returns:** `boolean`
|
|
95
|
+
|
|
96
|
+
#### 🔬 Logic Processing Methods
|
|
97
|
+
|
|
98
|
+
* **`fuzzify(varName, value)`** 🌫️
|
|
99
|
+
Converts a crisp numeric input into a dictionary of fuzzy membership degrees based on the variable's sets.
|
|
100
|
+
* **Parameters:**
|
|
101
|
+
* `varName` (`string`) - The variable to evaluate.
|
|
102
|
+
* `value` (`number`) - The crisp input value.
|
|
103
|
+
* **Returns:** `Object.<string, number>` - A map of set names to their membership degrees.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.5",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|
|
@@ -220,6 +220,10 @@
|
|
|
220
220
|
"require": "./dist/v1/libs/TinyTextDiffer.cjs",
|
|
221
221
|
"import": "./dist/v1/libs/TinyTextDiffer.mjs"
|
|
222
222
|
},
|
|
223
|
+
"./libs/TinyArrayComparator": {
|
|
224
|
+
"require": "./dist/v1/libs/TinyArrayComparator.cjs",
|
|
225
|
+
"import": "./dist/v1/libs/TinyArrayComparator.mjs"
|
|
226
|
+
},
|
|
223
227
|
"./libs/TinyDragDropDetector": {
|
|
224
228
|
"require": "./dist/v1/libs/TinyDragDropDetector.cjs",
|
|
225
229
|
"import": "./dist/v1/libs/TinyDragDropDetector.mjs"
|
|
@@ -260,6 +264,10 @@
|
|
|
260
264
|
"require": "./dist/v1/libs/TinyAdvancedRaffle.cjs",
|
|
261
265
|
"import": "./dist/v1/libs/TinyAdvancedRaffle.mjs"
|
|
262
266
|
},
|
|
267
|
+
"./libs/TinyMamdaniInferenceSystem": {
|
|
268
|
+
"require": "./dist/v1/libs/TinyMamdaniInferenceSystem.cjs",
|
|
269
|
+
"import": "./dist/v1/libs/TinyMamdaniInferenceSystem.mjs"
|
|
270
|
+
},
|
|
263
271
|
"./libs/TinyHtmlElems": {
|
|
264
272
|
"require": "./dist/v1/libs/TinyHtml/index.cjs",
|
|
265
273
|
"import": "./dist/v1/libs/TinyHtml/index.mjs"
|