2.1.144 • Published 7 days ago

@thi.ng/fuzzy-viz v2.1.144

Weekly downloads
20
License
Apache-2.0
Repository
github
Last release
7 days ago

fuzzy-viz

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Visualization, instrumentation & introspection utils for @thi.ng/fuzzy.

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/fuzzy-viz

ES module import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/fuzzy-viz"></script>

Skypack documentation

For Node.js REPL:

# with flag only for < v16
node --experimental-repl-await

> const fuzzyViz = await import("@thi.ng/fuzzy-viz");

Package sizes (gzipped, pre-treeshake): ESM: 1.06 KB

Dependencies

API

Generated API docs

Linguistic variable visualization

Generate an SVG visualization of all fuzzy sets defined in a linguistic variable:

fuzzy set visualization of the example l-var

import { varToSvg } from "@thi.ng/fuzzy-viz";

// temperature sets (in celsius)
const temp = variable(
    [-20, 40],
    {
        freezing: invSigmoid(0, 2),
        cold: trapezoid(-1, 2, 16, 20),
        warm: trapezoid(15, 20, 30, 34),
        hot: sigmoid(32, 2)
    }
);

// generate & write SVG file
writeFileSync("temperature.svg", varToSvg(temp, { samples: 200 }));

See VisualizeVarOpts for further options to configure the visualization.

Instrument a DefuzzStrategy

instrumentStrategy() is an higher order function. It takes an existing DefuzzStrategy and an instrumentation function. Returns new DefuzzStrategy which first executes original strategy, then calls instrument with the same args AND the computed result obtained from strategy. Returns result of original strategy.

The instrumentation function is intended to perform side effects (e.g. debug outputs) and/or produce secondary results (e.g. visualizations). The latter can be obtained through the IDeref mechanism implemented by the returned function. Since defuzz() might call the strategy multiple times (i.e. if there are multiple output vars used), .deref() will always return an array of secondary results.

Note: The secondary results from the instrumentation function will persist & accumulate. If re-using the instrumented strategy for multiple defuzz() invocations, it's highly recommended to clear any previous results using .clear().

const strategy = instrumentStrategy(
  cogStrategy({ samples: 1000 }),
  fuzzySetToAscii({ width: 40, height: 8 })
);

// apply strategy as normal (well, usually done via defuzz())
strategy(gaussian(5, 2), [0, 10]);
// 4.995

strategy.deref().forEach((viz) => console.log(viz));
// .................▄▆█|█▆▄.................
// ...............▅████|████▅...............
// .............▄██████|██████▄.............
// ...........▂▇███████|███████▇▂...........
// ..........▅█████████|█████████▅..........
// .......▁▅███████████|███████████▅▁.......
// .....▃▆█████████████|█████████████▆▃.....
// ▃▄▅▇████████████████|████████████████▇▅▄▃
//                     ^ 5.00

// cleanup (optional)
strategy.clear();

Using fuzzySetToHiccup()/fuzzySetToSvg() visualizations like below can be created following the same pattern as above:

fuzzySetToSvg() visualization example

Authors

Karsten Schmidt

If this project contributes to an academic publication, please cite it as:

@misc{thing-fuzzy-viz,
  title = "@thi.ng/fuzzy-viz",
  author = "Karsten Schmidt",
  note = "https://thi.ng/fuzzy-viz",
  year = 2020
}

License

© 2020 - 2021 Karsten Schmidt // Apache Software License 2.0

2.1.144

7 days ago

2.1.143

9 days ago

2.1.142

12 days ago

2.1.141

21 days ago

2.1.140

24 days ago

2.1.139

1 month ago

2.1.138

1 month ago

2.1.137

1 month ago

2.1.136

1 month ago

2.1.135

1 month ago

2.1.134

1 month ago

2.1.133

2 months ago

2.1.132

2 months ago

2.1.131

2 months ago

2.1.130

2 months ago

2.1.129

2 months ago

2.1.128

2 months ago

2.1.127

2 months ago

2.1.126

2 months ago

2.1.123

2 months ago

2.1.122

2 months ago

2.1.125

2 months ago

2.1.124

2 months ago

2.1.121

2 months ago

2.1.119

3 months ago

2.1.118

3 months ago

2.1.117

3 months ago

2.1.114

3 months ago

2.1.116

3 months ago

2.1.115

3 months ago

2.1.112

3 months ago

2.1.111

3 months ago

2.1.109

4 months ago

2.1.110

4 months ago

2.1.108

4 months ago

2.1.105

5 months ago

2.1.104

5 months ago

2.1.107

4 months ago

2.1.106

4 months ago

2.1.103

5 months ago

2.1.102

5 months ago

2.1.101

5 months ago

2.1.100

5 months ago

2.1.89

7 months ago

2.1.87

7 months ago

2.1.88

7 months ago

2.1.85

7 months ago

2.1.86

7 months ago

2.1.83

8 months ago

2.1.84

8 months ago

2.1.81

8 months ago

2.1.82

8 months ago

2.1.80

8 months ago

2.1.98

6 months ago

2.1.99

5 months ago

2.1.97

6 months ago

2.1.94

6 months ago

2.1.95

6 months ago

2.1.92

6 months ago

2.1.93

6 months ago

2.1.90

6 months ago

2.1.91

6 months ago

2.1.69

10 months ago

2.1.78

8 months ago

2.1.79

8 months ago

2.1.76

8 months ago

2.1.77

8 months ago

2.1.74

9 months ago

2.1.75

9 months ago

2.1.72

9 months ago

2.1.73

9 months ago

2.1.70

9 months ago

2.1.67

11 months ago

2.1.68

11 months ago

2.1.65

1 year ago

2.1.66

12 months ago

2.1.64

1 year ago

2.1.58

1 year ago

2.1.59

1 year ago

2.1.56

1 year ago

2.1.57

1 year ago

2.1.54

1 year ago

2.1.55

1 year ago

2.1.53

1 year ago

2.1.63

1 year ago

2.1.61

1 year ago

2.1.62

1 year ago

2.1.60

1 year ago

2.1.52

1 year ago

2.1.50

1 year ago

2.1.51

1 year ago

2.1.49

1 year ago

2.1.48

1 year ago

2.1.46

1 year ago

2.1.45

1 year ago

2.1.43

1 year ago

2.1.44

1 year ago

2.1.41

1 year ago

2.1.42

1 year ago

2.1.40

1 year ago

2.1.29

2 years ago

2.1.38

1 year ago

2.1.39

1 year ago

2.1.36

2 years ago

2.1.37

1 year ago

2.1.34

2 years ago

2.1.35

2 years ago

2.1.32

2 years ago

2.1.33

2 years ago

2.1.30

2 years ago

2.1.31

2 years ago

2.1.27

2 years ago

2.1.28

2 years ago

2.1.26

2 years ago

2.1.16

2 years ago

2.1.17

2 years ago

2.1.15

2 years ago

2.1.18

2 years ago

2.1.19

2 years ago

2.1.25

2 years ago

2.1.23

2 years ago

2.1.24

2 years ago

2.1.21

2 years ago

2.1.22

2 years ago

2.1.20

2 years ago

2.1.14

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.9

2 years ago

2.1.8

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.7

2 years ago

2.0.10

2 years ago

2.1.0

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.7

3 years ago

2.0.3

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.1.33

3 years ago

1.0.3

3 years ago

0.1.31

3 years ago

0.1.32

3 years ago

0.1.30

3 years ago

0.1.29

3 years ago

0.1.28

3 years ago

0.1.27

3 years ago

0.1.26

3 years ago

0.1.25

3 years ago

0.1.24

3 years ago

0.1.23

3 years ago

0.1.22

3 years ago

0.1.21

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago