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/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Contributing to es6-fuzz
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in improving es6-fuzz! This guide covers the local
|
|
4
|
+
workflow and the conventions used in this repository.
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
- Node.js 22+ (see `engines` in [package.json](package.json))
|
|
9
|
+
- npm
|
|
10
|
+
|
|
11
|
+
`package-lock.json` is intentionally not committed, so use `npm install`
|
|
12
|
+
(not `npm ci`).
|
|
13
|
+
|
|
14
|
+
## Getting started
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/sebs/es6-fuzz.git
|
|
18
|
+
cd es6-fuzz
|
|
19
|
+
npm install
|
|
20
|
+
npm test
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Common scripts
|
|
24
|
+
|
|
25
|
+
| Script | What it does |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `npm run build` | Clean `lib/` and compile TypeScript |
|
|
28
|
+
| `npm test` | Build, then run the test suite |
|
|
29
|
+
| `npm run test:coverage` | Run the suite with a coverage report |
|
|
30
|
+
| `npm run check` | Strict type-check (`tsc --noEmit`) without emitting |
|
|
31
|
+
| `npm run docs` | Generate the TypeDoc API site into `out/` |
|
|
32
|
+
| `npm run render-examples` | Render fuzzifier SVGs + viewer into `examples/` |
|
|
33
|
+
|
|
34
|
+
Generated output (`lib/`, `out/`, `docs/CHANGELOG.md`, `examples/`) is not
|
|
35
|
+
committed — it is produced by the build and CI pipeline.
|
|
36
|
+
|
|
37
|
+
## Tests
|
|
38
|
+
|
|
39
|
+
Tests use the built-in Node.js test runner (`node:test`) executed via `tsx`,
|
|
40
|
+
and live under [test/](test/). Test files import from the compiled `lib/`
|
|
41
|
+
output, which is why `npm test` builds first. Please add or update tests for any
|
|
42
|
+
behavior change, and keep the suite green:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm test
|
|
46
|
+
npm run check
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Coding conventions
|
|
50
|
+
|
|
51
|
+
- TypeScript in `strict` mode — no new type errors (`npm run check`).
|
|
52
|
+
- Each fuzzifier implements the `Fuzzify` contract in
|
|
53
|
+
[src/curve/fuzzifier.ts](src/curve/fuzzifier.ts) and maps a crisp input to a
|
|
54
|
+
membership degree in `0..1`.
|
|
55
|
+
- Match the style of the surrounding code.
|
|
56
|
+
|
|
57
|
+
## Commit messages
|
|
58
|
+
|
|
59
|
+
This project uses [Conventional Commits](https://www.conventionalcommits.org/)
|
|
60
|
+
prefixes — e.g. `feat:`, `fix:`, `chore:`, `ci:`, `build:`, `refactor:`,
|
|
61
|
+
`docs:`. Keep commits focused and the subject line imperative.
|
|
62
|
+
|
|
63
|
+
## Submitting changes
|
|
64
|
+
|
|
65
|
+
1. Fork and branch from `master`.
|
|
66
|
+
2. Make your change with tests and passing `npm test` / `npm run check`.
|
|
67
|
+
3. Open a pull request describing the change and the motivation.
|
|
68
|
+
|
|
69
|
+
CI runs the test suite and the strict type-check on Node 22 and 24
|
|
70
|
+
(see [.github/workflows/ci.yml](.github/workflows/ci.yml)).
|
|
71
|
+
|
|
72
|
+
## Releases
|
|
73
|
+
|
|
74
|
+
Maintainers release by bumping the version, which creates a matching tag:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm version <patch|minor|major> # postversion pushes the commit + tag
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Pushing the `v*` tag triggers the release workflow (builds, packs, and
|
|
81
|
+
generates release notes); publishing to npm is a separate, manually dispatched
|
|
82
|
+
workflow.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
By contributing you agree that your contributions are licensed under the
|
|
87
|
+
project's [MIT License](LICENSE.md).
|
package/Readme.md
CHANGED
|
@@ -1,107 +1,96 @@
|
|
|
1
|
-
# es6-fuzz
|
|
1
|
+
# es6-fuzz
|
|
2
2
|
|
|
3
|
-
> Fuzzy Logic in
|
|
3
|
+
> Fuzzy Logic in JavaScript
|
|
4
4
|
|
|
5
|
+
[](https://github.com/sebs/es6-fuzz/actions/workflows/ci.yml)
|
|
5
6
|
[](https://www.npmjs.com/package/es6-fuzz)
|
|
6
7
|
[](https://github.com/sebs/es6-fuzz/blob/master/LICENSE.md)
|
|
7
8
|
[](https://github.com/sebs/es6-fuzz)
|
|
8
9
|
[](https://github.com/sebs/es6-fuzz/issues)
|
|
9
10
|
|
|
10
|
-
## Supported
|
|
11
|
+
## Supported Fuzzifiers
|
|
11
12
|
|
|
12
|
-
* Constant
|
|
13
|
-
* Grade
|
|
14
|
-
* Reverse Grade
|
|
15
|
-
* Sigmoid
|
|
16
|
-
* Trapezoid
|
|
17
|
-
* Triangle
|
|
13
|
+
* **Constant** - Fixed membership value
|
|
14
|
+
* **Grade** - Linear membership function
|
|
15
|
+
* **Reverse Grade** - Inverted linear membership
|
|
16
|
+
* **Sigmoid** - S-shaped membership curve
|
|
17
|
+
* **Trapezoid** - Trapezoidal membership function
|
|
18
|
+
* **Triangle** - Triangular membership functionve
|
|
19
|
+
## Documentation
|
|
18
20
|
|
|
19
|
-
* [
|
|
20
|
-
* [
|
|
21
|
+
* [API Documentation](http://sebs.github.io/es6-fuzz)
|
|
22
|
+
* [Changelog](https://github.com/sebs/es6-fuzz/releases)
|
|
21
23
|
|
|
22
|
-
##
|
|
24
|
+
## Installation
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
26
|
+
```bash
|
|
27
27
|
npm install es6-fuzz
|
|
28
28
|
```
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
30
31
|
|
|
31
32
|
```javascript
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
40
|
+
.defuzzify(99);
|
|
41
|
+
|
|
42
|
+
console.log(result.toString()); // 'enragedAttack'
|
|
38
43
|
```
|
|
39
|
-
* enraged attack
|
|
40
44
|
|
|
41
|
-
## Example
|
|
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
|
-
|
|
50
|
+
const { Logic, Trapezoid } = require('es6-fuzz');
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
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.toString()); // 'hot'
|
|
54
59
|
```
|
|
55
60
|
|
|
56
|
-
* hot
|
|
57
|
-
|
|
58
61
|
|
|
59
|
-
## Usage with boon-js
|
|
62
|
+
## Advanced Usage with boon-js
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Example of a monster biting when its cold and you are close to it:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Heat part:
|
|
67
|
-
|
|
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);
|
|
73
|
-
|
|
74
|
-
logicHeat.init('cold', toColdTemperature)
|
|
75
|
-
logicHeat.or('optimal', optimalTemperature)
|
|
76
|
-
logicHeat.or('hot', toHotTemperature);
|
|
77
|
-
```
|
|
64
|
+
Combine multiple fuzzy functions with boolean logic using the boon-js compatibility layer.
|
|
78
65
|
|
|
79
|
-
|
|
66
|
+
### Example: Monster AI
|
|
80
67
|
|
|
81
|
-
|
|
68
|
+
A monster that bites when it's cold AND you're close to it:
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const
|
|
70
|
+
```javascript
|
|
71
|
+
const { Logic, Triangle } = require('es6-fuzz');
|
|
72
|
+
const { getEvaluator } = require('boon-js');
|
|
86
73
|
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
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,46 @@ monsterBiteTest(jsBoonInput)
|
|
|
110
99
|
|
|
111
100
|
|
|
112
101
|
|
|
113
|
-
##
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
### Running Tests
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm test # build + run the test suite
|
|
108
|
+
npm run test:coverage # same, with a coverage report
|
|
109
|
+
```
|
|
114
110
|
|
|
115
|
-
|
|
111
|
+
### Building Documentation
|
|
116
112
|
|
|
113
|
+
```bash
|
|
114
|
+
npm run docs # Generate the TypeDoc API site into ./out
|
|
117
115
|
```
|
|
118
|
-
|
|
116
|
+
|
|
117
|
+
The site is deployed to GitHub Pages automatically on every push to `master`
|
|
118
|
+
by the [Docs workflow](.github/workflows/docs.yml); `npm run docs` is for local
|
|
119
|
+
preview.
|
|
120
|
+
|
|
121
|
+
### Visual Examples
|
|
122
|
+
|
|
123
|
+
The `render-examples` script renders every fuzzifier and a few composite
|
|
124
|
+
systems (temperature/speed controllers) to SVG, plus an `index.html` viewer:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm run build # render-examples runs from the compiled output
|
|
128
|
+
npm run render-examples # writes SVGs + index.html into ./examples
|
|
119
129
|
```
|
|
120
130
|
|
|
121
|
-
|
|
131
|
+
Open `examples/index.html` in a browser to see the membership curves.
|
|
132
|
+
|
|
133
|
+
## Requirements
|
|
122
134
|
|
|
123
|
-
|
|
124
|
-
* http://de.slideshare.net/BCSLeicester/fuzzy-logic-in-the-real-world-2326817
|
|
125
|
-
* http://computing.dcu.ie/~humphrys/Notes/Neural/sigmoid.html
|
|
135
|
+
* Node.js 22+
|
|
126
136
|
|
|
127
|
-
##
|
|
137
|
+
## Resources
|
|
128
138
|
|
|
129
|
-
|
|
139
|
+
* [Fuzzy Logic in the Real World](http://de.slideshare.net/BCSLeicester/fuzzy-logic-in-the-real-world-2326817)
|
|
140
|
+
* [Understanding Sigmoid Functions](http://computing.dcu.ie/~humphrys/Notes/Neural/sigmoid.html)
|
|
130
141
|
|
|
131
|
-
## Related
|
|
142
|
+
## Related Projects
|
|
132
143
|
|
|
133
|
-
* https://www.npmjs.com/package/gaussian
|
|
144
|
+
* [gaussian](https://www.npmjs.com/package/gaussian) - Gaussian distribution functions
|
package/SECURITY.md
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Supported Versions
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
currently being supported with security updates.
|
|
5
|
+
The following versions of es6-fuzz are currently supported with security updates:
|
|
7
6
|
|
|
8
7
|
| Version | Supported |
|
|
9
8
|
| ------- | ------------------ |
|
|
10
|
-
|
|
|
11
|
-
| 5.
|
|
12
|
-
| 4.
|
|
9
|
+
| 6.0.x | :white_check_mark: |
|
|
10
|
+
| 5.x.x | :x: |
|
|
11
|
+
| 4.x.x | :x: |
|
|
13
12
|
| < 4.0 | :x: |
|
|
14
13
|
|
|
15
14
|
## Reporting a Vulnerability
|
package/lib/curve/constant.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { Fuzzifier } from './fuzzifier';
|
|
1
2
|
/** Class representing a Constant. */
|
|
2
|
-
export declare class Constant {
|
|
3
|
+
export declare class Constant implements Fuzzifier {
|
|
3
4
|
private readonly cValue;
|
|
4
5
|
/**
|
|
5
6
|
* Create a Constant Value.
|
|
6
|
-
* @param {number} constantValue - The value.
|
|
7
|
+
* @param {number} constantValue - The membership value, must be within 0..1.
|
|
7
8
|
* @example
|
|
8
|
-
* new Constant(
|
|
9
|
+
* new Constant(0.5)
|
|
9
10
|
*/
|
|
10
11
|
constructor(constantValue: number);
|
|
11
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../src/curve/constant.ts"],"names":[],"mappings":"AACA,qCAAqC;AACrC,qBAAa,
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../src/curve/constant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,qCAAqC;AACrC,qBAAa,QAAS,YAAW,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBACS,aAAa,EAAE,MAAM;IAMjC;;;OAGG;IACH,OAAO,IAAI,MAAM;CAGlB"}
|
package/lib/curve/constant.js
CHANGED
|
@@ -6,11 +6,14 @@ class Constant {
|
|
|
6
6
|
cValue;
|
|
7
7
|
/**
|
|
8
8
|
* Create a Constant Value.
|
|
9
|
-
* @param {number} constantValue - The value.
|
|
9
|
+
* @param {number} constantValue - The membership value, must be within 0..1.
|
|
10
10
|
* @example
|
|
11
|
-
* new Constant(
|
|
11
|
+
* new Constant(0.5)
|
|
12
12
|
*/
|
|
13
13
|
constructor(constantValue) {
|
|
14
|
+
if (!(constantValue >= 0 && constantValue <= 1)) {
|
|
15
|
+
throw Error('Constant value must be between 0 and 1 but is ' + constantValue);
|
|
16
|
+
}
|
|
14
17
|
this.cValue = constantValue;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/curve/constant.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/curve/constant.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,qCAAqC;AACrC,MAAa,QAAQ;IACF,MAAM,CAAS;IAEhC;;;;;OAKG;IACH,YAAY,aAAqB;QAC/B,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,IAAI,aAAa,IAAI,CAAC,CAAC,EAAE,CAAC;YAChD,MAAM,KAAK,CAAC,gDAAgD,GAAG,aAAa,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;IAC9B,CAAC;IACD;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAtBD,4BAsBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common interface implemented by every fuzzifier.
|
|
3
|
+
*
|
|
4
|
+
* Anything that maps a crisp input value to a membership degree can be used
|
|
5
|
+
* with {@link Logic}. This includes the geometric {@link Shape} curves as well
|
|
6
|
+
* as {@link Constant}, {@link Sigmoid} and {@link FuzzyFunction}, none of which
|
|
7
|
+
* are point-based shapes.
|
|
8
|
+
*/
|
|
9
|
+
export interface Fuzzifier {
|
|
10
|
+
/**
|
|
11
|
+
* Fuzzify
|
|
12
|
+
* @param {number} val - Point on X axis
|
|
13
|
+
* @return {number} fuzzy output 0..1
|
|
14
|
+
*/
|
|
15
|
+
fuzzify(val: number): number;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=fuzzifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuzzifier.d.ts","sourceRoot":"","sources":["../../src/curve/fuzzifier.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuzzifier.js","sourceRoot":"","sources":["../../src/curve/fuzzifier.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fuzzy-function.d.ts","sourceRoot":"","sources":["../../src/curve/fuzzy-function.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,qBAAa,
|
|
1
|
+
{"version":3,"file":"fuzzy-function.d.ts","sourceRoot":"","sources":["../../src/curve/fuzzy-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,0CAA0C;AAC1C,qBAAa,aAAc,YAAW,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAA0B;IAE7C;;;OAGG;gBACS,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM;IAGvC;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAO7B"}
|
|
@@ -20,7 +20,7 @@ class FuzzyFunction {
|
|
|
20
20
|
if (res >= 0 && res <= 1) {
|
|
21
21
|
return res;
|
|
22
22
|
}
|
|
23
|
-
throw Error('fuzzified result must be
|
|
23
|
+
throw Error('fuzzified result must be between 0 and 1 but is ' + res);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
exports.FuzzyFunction = FuzzyFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fuzzy-function.js","sourceRoot":"","sources":["../../src/curve/fuzzy-function.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fuzzy-function.js","sourceRoot":"","sources":["../../src/curve/fuzzy-function.ts"],"names":[],"mappings":";;;AACA,0CAA0C;AAC1C,MAAa,aAAa;IACP,EAAE,CAA0B;IAE7C;;;OAGG;IACH,YAAY,EAA2B;QACrC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD;;;OAGG;IACH,OAAO,CAAC,GAAW;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;YACzB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,MAAM,KAAK,CAAC,kDAAkD,GAAG,GAAG,CAAC,CAAC;IACxE,CAAC;CACF;AArBD,sCAqBC"}
|
package/lib/curve/grade.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ import { Shape } from './shape';
|
|
|
5
5
|
* new Grade(0, 10)
|
|
6
6
|
*/
|
|
7
7
|
export declare class Grade extends Shape {
|
|
8
|
+
/**
|
|
9
|
+
* Create a Grade.
|
|
10
|
+
* @param {number} x0 - start of the rising edge (membership 0)
|
|
11
|
+
* @param {number} x1 - end of the rising edge (membership 1)
|
|
12
|
+
*/
|
|
13
|
+
constructor(x0: number, x1: number);
|
|
8
14
|
/**
|
|
9
15
|
* Fuzzify
|
|
10
16
|
* @param {number} val - Point on X axis
|
package/lib/curve/grade.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grade.d.ts","sourceRoot":"","sources":["../../src/curve/grade.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC;;;;GAIG;AACH,qBAAa,KAAM,SAAQ,KAAK;IAC9B;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"grade.d.ts","sourceRoot":"","sources":["../../src/curve/grade.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC;;;;GAIG;AACH,qBAAa,KAAM,SAAQ,KAAK;IAC9B;;;;OAIG;gBACS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAGlC;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAqB7B"}
|
package/lib/curve/grade.js
CHANGED
|
@@ -8,6 +8,14 @@ const shape_1 = require("./shape");
|
|
|
8
8
|
* new Grade(0, 10)
|
|
9
9
|
*/
|
|
10
10
|
class Grade extends shape_1.Shape {
|
|
11
|
+
/**
|
|
12
|
+
* Create a Grade.
|
|
13
|
+
* @param {number} x0 - start of the rising edge (membership 0)
|
|
14
|
+
* @param {number} x1 - end of the rising edge (membership 1)
|
|
15
|
+
*/
|
|
16
|
+
constructor(x0, x1) {
|
|
17
|
+
super(x0, x1, x1, x1);
|
|
18
|
+
}
|
|
11
19
|
/**
|
|
12
20
|
* Fuzzify
|
|
13
21
|
* @param {number} val - Point on X axis
|
|
@@ -16,11 +24,13 @@ class Grade extends shape_1.Shape {
|
|
|
16
24
|
fuzzify(val) {
|
|
17
25
|
let result = 0;
|
|
18
26
|
const x = val;
|
|
19
|
-
// Handle case where x0 = x1 (vertical grade/step function)
|
|
27
|
+
// Handle case where x0 = x1 (vertical grade/step function).
|
|
28
|
+
// Treat it as the limit of the ramp: the foot at x0 is 0, like the normal
|
|
29
|
+
// grade below, so behaviour stays continuous as x1 approaches x0.
|
|
20
30
|
if (this.x1 === this.x0) {
|
|
21
|
-
if (x
|
|
31
|
+
if (x <= this.x0)
|
|
22
32
|
return 0;
|
|
23
|
-
return 1; // x
|
|
33
|
+
return 1; // x > x0
|
|
24
34
|
}
|
|
25
35
|
if (x <= this.x0) {
|
|
26
36
|
result = 0;
|
|
@@ -29,7 +39,7 @@ class Grade extends shape_1.Shape {
|
|
|
29
39
|
result = 1;
|
|
30
40
|
}
|
|
31
41
|
else {
|
|
32
|
-
result =
|
|
42
|
+
result = x / (this.x1 - this.x0) - this.x0 / (this.x1 - this.x0);
|
|
33
43
|
}
|
|
34
44
|
return result;
|
|
35
45
|
}
|
package/lib/curve/grade.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grade.js","sourceRoot":"","sources":["../../src/curve/grade.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,mCAAgC;AAChC;;;;GAIG;AACH,MAAa,KAAM,SAAQ,aAAK;IAC9B;;;;OAIG;IACH,OAAO,CAAC,GAAW;QACjB,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,MAAM,CAAC,GAAG,GAAG,CAAC;QAEd,
|
|
1
|
+
{"version":3,"file":"grade.js","sourceRoot":"","sources":["../../src/curve/grade.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,mCAAgC;AAChC;;;;GAIG;AACH,MAAa,KAAM,SAAQ,aAAK;IAC9B;;;;OAIG;IACH,YAAY,EAAU,EAAE,EAAU;QAChC,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACxB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAC,GAAW;QACjB,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,MAAM,CAAC,GAAG,GAAG,CAAC;QAEd,4DAA4D;QAC5D,0EAA0E;QAC1E,kEAAkE;QAClE,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;gBAAE,OAAO,CAAC,CAAC;YAC3B,OAAO,CAAC,CAAC,CAAC,SAAS;QACrB,CAAC;QAED,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACxB,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,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;QACnE,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAnCD,sBAmCC"}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Shape } from './shape';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a ReverseGrade.
|
|
4
|
+
* @example
|
|
5
|
+
* new ReverseGrade(0, 10)
|
|
6
|
+
*/
|
|
3
7
|
export declare class ReverseGrade extends Shape {
|
|
8
|
+
/**
|
|
9
|
+
* Create a ReverseGrade.
|
|
10
|
+
* @param {number} x0 - end of the full-membership plateau (membership 1)
|
|
11
|
+
* @param {number} x1 - end of the falling edge (membership 0)
|
|
12
|
+
*/
|
|
13
|
+
constructor(x0: number, x1: number);
|
|
4
14
|
/**
|
|
5
15
|
* Fuzzify
|
|
6
16
|
* @param {number} val - Point on X axis
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reverse-grade.d.ts","sourceRoot":"","sources":["../../src/curve/reverse-grade.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC
|
|
1
|
+
{"version":3,"file":"reverse-grade.d.ts","sourceRoot":"","sources":["../../src/curve/reverse-grade.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC;;;;OAIG;gBACS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAGlC;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAe7B"}
|
|
@@ -2,32 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReverseGrade = void 0;
|
|
4
4
|
const shape_1 = require("./shape");
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a ReverseGrade.
|
|
7
|
+
* @example
|
|
8
|
+
* new ReverseGrade(0, 10)
|
|
9
|
+
*/
|
|
6
10
|
class ReverseGrade extends shape_1.Shape {
|
|
11
|
+
/**
|
|
12
|
+
* Create a ReverseGrade.
|
|
13
|
+
* @param {number} x0 - end of the full-membership plateau (membership 1)
|
|
14
|
+
* @param {number} x1 - end of the falling edge (membership 0)
|
|
15
|
+
*/
|
|
16
|
+
constructor(x0, x1) {
|
|
17
|
+
super(x0, x1, x1, x1);
|
|
18
|
+
}
|
|
7
19
|
/**
|
|
8
20
|
* Fuzzify
|
|
9
21
|
* @param {number} val - Point on X axis
|
|
10
22
|
* @return {number} fuzzy output 0..1
|
|
11
23
|
*/
|
|
12
24
|
fuzzify(val) {
|
|
13
|
-
let result = 0;
|
|
14
25
|
const x = val;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Handle case where x0 = x1 (vertical reverse grade)
|
|
23
|
-
if (this.x1 === this.x0) {
|
|
24
|
-
result = 0;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
result = (-x / (this.x1 - this.x0)) + (this.x1 / (this.x1 - this.x0));
|
|
28
|
-
}
|
|
26
|
+
// Vertical reverse grade (x0 = x1): step down, the mirror of Grade.
|
|
27
|
+
// (The previous inline x0 === x1 handling sat in an unreachable branch:
|
|
28
|
+
// when x0 === x1 every value is caught by x <= x0 or x >= x1 first.)
|
|
29
|
+
if (this.x1 === this.x0) {
|
|
30
|
+
if (x <= this.x0)
|
|
31
|
+
return 1;
|
|
32
|
+
return 0; // x > x0
|
|
29
33
|
}
|
|
30
|
-
|
|
34
|
+
if (x <= this.x0)
|
|
35
|
+
return 1;
|
|
36
|
+
if (x >= this.x1)
|
|
37
|
+
return 0;
|
|
38
|
+
return -x / (this.x1 - this.x0) + this.x1 / (this.x1 - this.x0);
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
exports.ReverseGrade = ReverseGrade;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reverse-grade.js","sourceRoot":"","sources":["../../src/curve/reverse-grade.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,mCAAgC;AAChC
|
|
1
|
+
{"version":3,"file":"reverse-grade.js","sourceRoot":"","sources":["../../src/curve/reverse-grade.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AACb,mCAAgC;AAChC;;;;GAIG;AACH,MAAa,YAAa,SAAQ,aAAK;IACrC;;;;OAIG;IACH,YAAY,EAAU,EAAE,EAAU;QAChC,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACxB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAC,GAAW;QACjB,MAAM,CAAC,GAAG,GAAG,CAAC;QAEd,oEAAoE;QACpE,wEAAwE;QACxE,qEAAqE;QACrE,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;gBAAE,OAAO,CAAC,CAAC;YAC3B,OAAO,CAAC,CAAC,CAAC,SAAS;QACrB,CAAC;QAED,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,CAAC;QAC3B,OAAO,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;IAClE,CAAC;CACF;AA7BD,oCA6BC"}
|
package/lib/curve/shape.d.ts
CHANGED
package/lib/curve/shape.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../src/curve/shape.ts"],"names":[],"mappings":"AACA,uCAAuC;AACvC,8BAAsB,
|
|
1
|
+
{"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../src/curve/shape.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,uCAAuC;AACvC,8BAAsB,KAAM,YAAW,SAAS;IAC9C,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAC;IAErB;;;;;;OAMG;gBACS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAmB1D;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CACtC"}
|
package/lib/curve/shape.js
CHANGED
|
@@ -17,19 +17,19 @@ class Shape {
|
|
|
17
17
|
constructor(x0, x1, x2, x3) {
|
|
18
18
|
Object.defineProperty(this, 'x0', {
|
|
19
19
|
value: x0,
|
|
20
|
-
writable: false
|
|
20
|
+
writable: false,
|
|
21
21
|
});
|
|
22
22
|
Object.defineProperty(this, 'x1', {
|
|
23
23
|
value: x1,
|
|
24
|
-
writable: false
|
|
24
|
+
writable: false,
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(this, 'x2', {
|
|
27
27
|
value: x2,
|
|
28
|
-
writable: false
|
|
28
|
+
writable: false,
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(this, 'x3', {
|
|
31
31
|
value: x3,
|
|
32
|
-
writable: false
|
|
32
|
+
writable: false,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
package/lib/curve/shape.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.js","sourceRoot":"","sources":["../../src/curve/shape.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;
|
|
1
|
+
{"version":3,"file":"shape.js","sourceRoot":"","sources":["../../src/curve/shape.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEb,uCAAuC;AACvC,MAAsB,KAAK;IAChB,EAAE,CAAU;IACZ,EAAE,CAAU;IACZ,EAAE,CAAU;IACZ,EAAE,CAAU;IAErB;;;;;;OAMG;IACH,YAAY,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU;QACxD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE;YAChC,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE;YAChC,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE;YAChC,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE;YAChC,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;IACL,CAAC;CAQF;AAtCD,sBAsCC"}
|