@thi.ng/fuzzy 2.1.80 → 2.1.82

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.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:18Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/fuzzy",
3
- "version": "2.1.80",
3
+ "version": "2.1.82",
4
4
  "description": "Fuzzy logic operators & configurable rule inferencing engine",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/fuzzy#readme",
13
+ "homepage": "https://thi.ng/fuzzy",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,14 +36,14 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/math": "^5.10.12"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/math": "^5.11.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@microsoft/api-extractor": "^7.43.0",
44
- "esbuild": "^0.20.2",
45
- "typedoc": "^0.25.12",
46
- "typescript": "^5.4.3"
43
+ "@microsoft/api-extractor": "^7.47.0",
44
+ "esbuild": "^0.21.5",
45
+ "typedoc": "^0.25.13",
46
+ "typescript": "^5.5.2"
47
47
  },
48
48
  "keywords": [
49
49
  "agent",
@@ -92,9 +92,6 @@
92
92
  "./strategies/maxima": {
93
93
  "default": "./strategies/maxima.js"
94
94
  },
95
- "./strategies/opts": {
96
- "default": "./strategies/opts.js"
97
- },
98
95
  "./tnorms": {
99
96
  "default": "./tnorms.js"
100
97
  },
@@ -105,5 +102,5 @@
105
102
  "thi.ng": {
106
103
  "year": 2020
107
104
  },
108
- "gitHead": "5dd66c18a3862a3af69a5b2f49563f7cbdd960c2\n"
105
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
109
106
  }
@@ -12,10 +12,12 @@ import type { DefuzzStrategy, DefuzzStrategyOpts } from "../api.js";
12
12
  * Also see {@link DefuzzStrategyOpts}
13
13
  *
14
14
  * @example
15
- * ```ts
15
+ * ```ts tangle:../../export/bisector-strategy.ts
16
16
  * import { bisectorStrategy, trapezoid } from "@thi.ng/fuzzy";
17
17
  *
18
- * bisectorStrategy()(trapezoid(0,1,5,6), [0,6])
18
+ * console.log(
19
+ * bisectorStrategy()(trapezoid(0,1,5,6), [0,6])
20
+ * );
19
21
  * // 2.97
20
22
  *
21
23
  * // ......▁█████████████|█████████████▁.....
@@ -1,7 +1,7 @@
1
1
  import { fit } from "@thi.ng/math/fit";
2
- import { defaultOpts } from "./opts.js";
2
+ import { __defaultOpts } from "./opts.js";
3
3
  const bisectorStrategy = (opts) => {
4
- let { samples } = defaultOpts(opts);
4
+ let { samples } = __defaultOpts(opts);
5
5
  return (fn, [min, max]) => {
6
6
  const delta = (max - min) / samples;
7
7
  let sum = [];
@@ -9,8 +9,7 @@ const bisectorStrategy = (opts) => {
9
9
  acc += fn(min + i * delta);
10
10
  sum.push(acc);
11
11
  }
12
- if (!sum.length)
13
- return min;
12
+ if (!sum.length) return min;
14
13
  const mean = sum[samples] * 0.5;
15
14
  for (let i = 1; i <= samples; i++) {
16
15
  if (sum[i] >= mean) {
@@ -12,10 +12,12 @@ import type { DefuzzStrategy, DefuzzStrategyOpts } from "../api.js";
12
12
  * Also see {@link DefuzzStrategyOpts}
13
13
  *
14
14
  * @example
15
- * ```ts
15
+ * ```ts tangle:../../export/centroid-strategy.ts
16
16
  * import { centroidStrategy, trapezoid } from "@thi.ng/fuzzy";
17
17
  *
18
- * centroidStrategy()(trapezoid(0,1,5,6), [0,6])
18
+ * console.log(
19
+ * centroidStrategy()(trapezoid(0,1,5,6), [0,6])
20
+ * );
19
21
  * // 3.0000000000000004
20
22
  *
21
23
  * // ......▁█████████████|█████████████▁.....
@@ -1,6 +1,6 @@
1
- import { defaultOpts } from "./opts.js";
1
+ import { __defaultOpts } from "./opts.js";
2
2
  const centroidStrategy = (opts) => {
3
- let { samples } = defaultOpts(opts);
3
+ let { samples } = __defaultOpts(opts);
4
4
  return (fn, [min, max]) => {
5
5
  const delta = (max - min) / samples;
6
6
  let num = 0;
@@ -9,10 +9,12 @@ import type { DefuzzStrategy, DefuzzStrategyOpts } from "../api.js";
9
9
  * Also see {@link DefuzzStrategyOpts}
10
10
  *
11
11
  * @example
12
- * ```ts
12
+ * ```ts tangle:../../export/mean-of-maxima-strategy.ts
13
13
  * import { meanOfMaximaStrategy, trapezoid } from "@thi.ng/fuzzy";
14
14
  *
15
- * meanOfMaximaStrategy()(trapezoid(0,1,5,6), [0,6])
15
+ * console.log(
16
+ * meanOfMaximaStrategy()(trapezoid(0,1,5,6), [0,6])
17
+ * );
16
18
  * // 3
17
19
  *
18
20
  * // ......▁█████████████|█████████████▁.....
@@ -40,10 +42,12 @@ export declare const meanOfMaximaStrategy: (opts?: Partial<DefuzzStrategyOpts>)
40
42
  * Also see {@link DefuzzStrategyOpts}
41
43
  *
42
44
  * @example
43
- * ```ts
45
+ * ```ts tangle:../../export/first-of-maxima-strategy.ts
44
46
  * import { firstOfMaximaStrategy, trapezoid } from "@thi.ng/fuzzy";
45
47
  *
46
- * firstOfMaximaStrategy()(trapezoid(0,1,5,6), [0,6])
48
+ * console.log(
49
+ * firstOfMaximaStrategy()(trapezoid(0,1,5,6), [0,6])
50
+ * );
47
51
  * // 1.02
48
52
  *
49
53
  * // ......▁|██████████████████████████▁.....
@@ -71,10 +75,12 @@ export declare const firstOfMaximaStrategy: (opts?: Partial<DefuzzStrategyOpts>)
71
75
  * Also see {@link DefuzzStrategyOpts}
72
76
  *
73
77
  * @example
74
- * ```ts
78
+ * ```ts tangle:../../export/last-of-maxima-strategy.ts
75
79
  * import { lastOfMaximaStrategy, trapezoid } from "@thi.ng/fuzzy";
76
80
  *
77
- * lastOfMaximaStrategy()(trapezoid(0,1,5,6), [0,6])
81
+ * console.log(
82
+ * lastOfMaximaStrategy()(trapezoid(0,1,5,6), [0,6])
83
+ * );
78
84
  * // 4.98
79
85
  *
80
86
  * // ......▁██████████████████████████|▁.....
@@ -1,7 +1,7 @@
1
1
  import { eqDelta } from "@thi.ng/math/eqdelta";
2
- import { defaultOpts } from "./opts.js";
2
+ import { __defaultOpts } from "./opts.js";
3
3
  const meanOfMaximaStrategy = (opts) => {
4
- const { samples, eps } = defaultOpts(opts);
4
+ const { samples, eps } = __defaultOpts(opts);
5
5
  return (fn, [min, max]) => {
6
6
  const delta = (max - min) / samples;
7
7
  let peak = -Infinity;
@@ -23,7 +23,7 @@ const meanOfMaximaStrategy = (opts) => {
23
23
  };
24
24
  };
25
25
  const firstOfMaximaStrategy = (opts) => {
26
- const { samples } = defaultOpts(opts);
26
+ const { samples } = __defaultOpts(opts);
27
27
  return (fn, [min, max]) => {
28
28
  const delta = (max - min) / samples;
29
29
  let peak = -Infinity;
@@ -1,3 +1,4 @@
1
1
  import type { DefuzzStrategyOpts } from "../api.js";
2
- export declare const defaultOpts: (opts?: Partial<DefuzzStrategyOpts>) => DefuzzStrategyOpts;
2
+ /** @internal */
3
+ export declare const __defaultOpts: (opts?: Partial<DefuzzStrategyOpts>) => DefuzzStrategyOpts;
3
4
  //# sourceMappingURL=opts.d.ts.map
@@ -1,8 +1,8 @@
1
- const defaultOpts = (opts) => ({
1
+ const __defaultOpts = (opts) => ({
2
2
  samples: 100,
3
3
  eps: 1e-6,
4
4
  ...opts
5
5
  });
6
6
  export {
7
- defaultOpts
7
+ __defaultOpts
8
8
  };
package/var.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Maybe } from "@thi.ng/api";
2
- import type { LVar } from "./api.js";
2
+ import type { LVar, LVarDomain } from "./api.js";
3
3
  /**
4
4
  * Takes a `domain` interval and on object of named fuzzy sets and returns a new
5
5
  * Linguistic variable, which can then be used as input or output var for
@@ -21,7 +21,7 @@ import type { LVar } from "./api.js";
21
21
  * @param domain -
22
22
  * @param terms -
23
23
  */
24
- export declare const variable: <K extends string>(domain: import("@thi.ng/api").Range, terms: LVar<K>["terms"]) => LVar<K>;
24
+ export declare const variable: <K extends string>(domain: LVarDomain, terms: LVar<K>["terms"]) => LVar<K>;
25
25
  /**
26
26
  * Takes an LVar and a domain value `x`. Returns the ID of the var's fuzzy set
27
27
  * term which yields the max truth value for given `x`. If `threshold` is
@@ -29,7 +29,7 @@ export declare const variable: <K extends string>(domain: import("@thi.ng/api").
29
29
  * considered. The function returns undefined if classification failed.
30
30
  *
31
31
  * @example
32
- * ```ts
32
+ * ```ts tangle:../export/classify.ts
33
33
  * import { classify, variable, invSigmoid, sigmoid, trapezoid } from "@thi.ng/fuzzy";
34
34
  *
35
35
  * // temperature sets (in celsius)
@@ -40,7 +40,7 @@ export declare const variable: <K extends string>(domain: import("@thi.ng/api").
40
40
  * hot: sigmoid(30, 2)
41
41
  * });
42
42
  *
43
- * classify(temp, 28)
43
+ * console.log(classify(temp, 28));
44
44
  * // "warm"
45
45
  * ```
46
46
  *
@@ -54,7 +54,7 @@ export declare const classify: <K extends string>({ terms }: LVar<K>, x: number,
54
54
  * `x` and returns object of results.
55
55
  *
56
56
  * @example
57
- * ```ts
57
+ * ```ts tangle:../export/evaluate.ts
58
58
  * import { evaluate, variable, invSigmoid, sigmoid, trapezoid } from "@thi.ng/fuzzy";
59
59
  *
60
60
  * // temperature sets (in celsius)
@@ -65,7 +65,7 @@ export declare const classify: <K extends string>({ terms }: LVar<K>, x: number,
65
65
  * hot: sigmoid(30, 2)
66
66
  * });
67
67
  *
68
- * evaluate(temp, 28)
68
+ * console.log(evaluate(temp, 28));
69
69
  * // { freezing: 0, cold: 0, warm: 0.4, hot: 0.01798620996209156 }
70
70
  * ```
71
71
  *
package/var.js CHANGED
@@ -2,7 +2,7 @@ const variable = (domain, terms) => ({
2
2
  domain,
3
3
  terms
4
4
  });
5
- const classify = ({ terms }, x, threshold = 0.5) => {
5
+ const classify = ({ terms }, x, threshold = 0) => {
6
6
  let max = threshold;
7
7
  let maxID;
8
8
  for (let id in terms) {