fuzlog 0.1.0__tar.gz

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.
fuzlog-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 coredegon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
fuzlog-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: fuzlog
3
+ Version: 0.1.0
4
+ Summary: Simple and enjoyable Python library for fuzzy logic.
5
+ Keywords: fuzzy,fuzzy-logic,fuzzy-sets,fuzzy-inference,membership-functions,mamdani,sugeno
6
+ Author: coredegon
7
+ Author-email: coredegon <valikalik15@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Typing :: Typed
22
+ Requires-Dist: numpy>=2.0
23
+ Requires-Dist: matplotlib>=3.9 ; extra == 'plot'
24
+ Requires-Python: >=3.12
25
+ Project-URL: Repository, https://github.com/coredegon/fuzlog
26
+ Project-URL: Documentation, https://github.com/coredegon/fuzlog/tree/main/docs
27
+ Project-URL: Issues, https://github.com/coredegon/fuzlog/issues
28
+ Provides-Extra: plot
29
+ Description-Content-Type: text/markdown
30
+
31
+ # fuzlog
32
+
33
+ Fuzzy logic for Python: membership functions, linguistic variables, Mamdani and
34
+ Sugeno inference. Three small modules on top of NumPy, fully typed, Python 3.12+.
35
+
36
+ ```sh
37
+ pip install fuzlog # NumPy is the only dependency
38
+ pip install "fuzlog[plot]" # adds matplotlib for the plots
39
+ ```
40
+
41
+ ## Example
42
+
43
+ How much to tip, given the service and the food:
44
+
45
+ ```pycon
46
+ >>> import fuzlog as fz
47
+
48
+ >>> service = fz.partition("service", (0, 10), ["poor", "good", "excellent"])
49
+ >>> food = fz.Variable("food", (0, 10), rancid=fz.z_shape(1, 4), tasty=fz.s_shape(6, 9))
50
+ >>> tip = fz.partition("tip", (0, 30), cheap=5, average=15, generous=25)
51
+
52
+ >>> tipper = fz.Mamdani(
53
+ ... service.poor | food.rancid >> tip.cheap,
54
+ ... service.good >> tip.average,
55
+ ... service.excellent | food.tasty >> tip.generous,
56
+ ... )
57
+ >>> round(tipper(service=3, food=8), 2)
58
+ 17.03
59
+ >>> tipper(service=[1, 5, 9], food=[2, 5, 8]).round(2).tolist()
60
+ [8.2, 15.0, 21.8]
61
+ >>> print(*tipper.rules, sep="\n")
62
+ if service is poor or food is rancid then tip is cheap
63
+ if service is good then tip is average
64
+ if service is excellent or food is tasty then tip is generous
65
+ ```
66
+
67
+ `tipper.plot(service=3, food=8)` and `tipper.surface("service", "food")` draw:
68
+
69
+ ![The output set inferred for service 3 and food 8, and the tip over both inputs](https://raw.githubusercontent.com/coredegon/fuzlog/main/docs/img/tipper.png)
70
+
71
+ ## What is inside
72
+
73
+ - **Sets.** 16 shapes: `triangle`, `trapezoid`, `rising`, `falling`, `rectangle`,
74
+ `singleton`, `piecewise`, `gauss`, `gauss2`, `bell`, `sigmoid`, `dsigmoid`,
75
+ `psigmoid`, `s_shape`, `z_shape`, `pi_shape`; any function of your own through
76
+ `MF`. Sets combine with `&`, `|`, `~` and `**`.
77
+ - **Variables.** `Variable` names the terms of a quantity; `partition` builds terms
78
+ that always sum to 1, also on periodic universes such as angles.
79
+ - **Rules.** `temp.hot & ~humid.dry >> fan.fast`, with weights and the hedges
80
+ `very`, `extremely`, `somewhat`.
81
+ - **Inference.** `Mamdani` with any t-norm, s-norm, implication and aggregation and
82
+ the defuzzifiers `centroid`, `bisector`, `mom`, `som`, `lom`; `Sugeno` with
83
+ constant or functional conclusions.
84
+ - **Arrays.** A scalar gives a float, arrays give arrays, and inputs broadcast
85
+ against each other.
86
+ - **Plots.** `variable.plot()`, `system.plot(...)`, `system.surface(x, y)`, in
87
+ scripts and notebooks alike.
88
+
89
+ ## Documentation
90
+
91
+ - [Guide](https://github.com/coredegon/fuzlog/blob/main/docs/guide.md): the library from sets to inference
92
+ - [Membership functions](https://github.com/coredegon/fuzlog/blob/main/docs/shapes.md): every shape, its definition and its name elsewhere
93
+ - [Reference](https://github.com/coredegon/fuzlog/blob/main/docs/reference.md): every public name on one page
94
+
95
+ ## Development
96
+
97
+ ```sh
98
+ uv sync # environment with the dev tools
99
+ uv run pytest # tests, including every example in the documentation
100
+ uv run ruff check # lint; `uv run ruff format` formats
101
+ uv run ty check # types
102
+ ```
103
+
104
+ MIT license.
fuzlog-0.1.0/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # fuzlog
2
+
3
+ Fuzzy logic for Python: membership functions, linguistic variables, Mamdani and
4
+ Sugeno inference. Three small modules on top of NumPy, fully typed, Python 3.12+.
5
+
6
+ ```sh
7
+ pip install fuzlog # NumPy is the only dependency
8
+ pip install "fuzlog[plot]" # adds matplotlib for the plots
9
+ ```
10
+
11
+ ## Example
12
+
13
+ How much to tip, given the service and the food:
14
+
15
+ ```pycon
16
+ >>> import fuzlog as fz
17
+
18
+ >>> service = fz.partition("service", (0, 10), ["poor", "good", "excellent"])
19
+ >>> food = fz.Variable("food", (0, 10), rancid=fz.z_shape(1, 4), tasty=fz.s_shape(6, 9))
20
+ >>> tip = fz.partition("tip", (0, 30), cheap=5, average=15, generous=25)
21
+
22
+ >>> tipper = fz.Mamdani(
23
+ ... service.poor | food.rancid >> tip.cheap,
24
+ ... service.good >> tip.average,
25
+ ... service.excellent | food.tasty >> tip.generous,
26
+ ... )
27
+ >>> round(tipper(service=3, food=8), 2)
28
+ 17.03
29
+ >>> tipper(service=[1, 5, 9], food=[2, 5, 8]).round(2).tolist()
30
+ [8.2, 15.0, 21.8]
31
+ >>> print(*tipper.rules, sep="\n")
32
+ if service is poor or food is rancid then tip is cheap
33
+ if service is good then tip is average
34
+ if service is excellent or food is tasty then tip is generous
35
+ ```
36
+
37
+ `tipper.plot(service=3, food=8)` and `tipper.surface("service", "food")` draw:
38
+
39
+ ![The output set inferred for service 3 and food 8, and the tip over both inputs](https://raw.githubusercontent.com/coredegon/fuzlog/main/docs/img/tipper.png)
40
+
41
+ ## What is inside
42
+
43
+ - **Sets.** 16 shapes: `triangle`, `trapezoid`, `rising`, `falling`, `rectangle`,
44
+ `singleton`, `piecewise`, `gauss`, `gauss2`, `bell`, `sigmoid`, `dsigmoid`,
45
+ `psigmoid`, `s_shape`, `z_shape`, `pi_shape`; any function of your own through
46
+ `MF`. Sets combine with `&`, `|`, `~` and `**`.
47
+ - **Variables.** `Variable` names the terms of a quantity; `partition` builds terms
48
+ that always sum to 1, also on periodic universes such as angles.
49
+ - **Rules.** `temp.hot & ~humid.dry >> fan.fast`, with weights and the hedges
50
+ `very`, `extremely`, `somewhat`.
51
+ - **Inference.** `Mamdani` with any t-norm, s-norm, implication and aggregation and
52
+ the defuzzifiers `centroid`, `bisector`, `mom`, `som`, `lom`; `Sugeno` with
53
+ constant or functional conclusions.
54
+ - **Arrays.** A scalar gives a float, arrays give arrays, and inputs broadcast
55
+ against each other.
56
+ - **Plots.** `variable.plot()`, `system.plot(...)`, `system.surface(x, y)`, in
57
+ scripts and notebooks alike.
58
+
59
+ ## Documentation
60
+
61
+ - [Guide](https://github.com/coredegon/fuzlog/blob/main/docs/guide.md): the library from sets to inference
62
+ - [Membership functions](https://github.com/coredegon/fuzlog/blob/main/docs/shapes.md): every shape, its definition and its name elsewhere
63
+ - [Reference](https://github.com/coredegon/fuzlog/blob/main/docs/reference.md): every public name on one page
64
+
65
+ ## Development
66
+
67
+ ```sh
68
+ uv sync # environment with the dev tools
69
+ uv run pytest # tests, including every example in the documentation
70
+ uv run ruff check # lint; `uv run ruff format` formats
71
+ uv run ty check # types
72
+ ```
73
+
74
+ MIT license.
@@ -0,0 +1,91 @@
1
+ [project]
2
+ name = "fuzlog"
3
+ version = "0.1.0"
4
+ description = "Simple and enjoyable Python library for fuzzy logic."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ dependencies = ["numpy>=2.0"]
10
+ keywords = [
11
+ "fuzzy",
12
+ "fuzzy-logic",
13
+ "fuzzy-sets",
14
+ "fuzzy-inference",
15
+ "membership-functions",
16
+ "mamdani",
17
+ "sugeno",
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "Intended Audience :: Science/Research",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Programming Language :: Python :: 3.15",
29
+ "Topic :: Scientific/Engineering",
30
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
31
+ "Typing :: Typed",
32
+ ]
33
+
34
+ [[project.authors]]
35
+ name = "coredegon"
36
+ email = "valikalik15@gmail.com"
37
+
38
+ [project.optional-dependencies]
39
+ plot = ["matplotlib>=3.9"]
40
+
41
+ [project.urls]
42
+ Repository = "https://github.com/coredegon/fuzlog"
43
+ Documentation = "https://github.com/coredegon/fuzlog/tree/main/docs"
44
+ Issues = "https://github.com/coredegon/fuzlog/issues"
45
+
46
+ [build-system]
47
+ requires = ["uv_build>=0.13.7,<0.14.0"]
48
+ build-backend = "uv_build"
49
+
50
+ [dependency-groups]
51
+ dev = [
52
+ "matplotlib>=3.9",
53
+ "pytest>=9.2.0",
54
+ "ruff>=0.17.5",
55
+ "ty>=0.0.104",
56
+ ]
57
+
58
+ [tool.ruff.lint]
59
+ select = [
60
+ "E",
61
+ "W",
62
+ "F",
63
+ "I",
64
+ "N",
65
+ "D",
66
+ "UP",
67
+ "B",
68
+ "C4",
69
+ "SIM",
70
+ "PT",
71
+ "NPY",
72
+ "PERF",
73
+ "RUF",
74
+ ]
75
+ ignore = [
76
+ "D105",
77
+ "D107",
78
+ ]
79
+
80
+ [tool.ruff.lint.pydocstyle]
81
+ convention = "google"
82
+
83
+ [tool.ruff.lint.per-file-ignores]
84
+ "tests/*" = ["D"]
85
+ "docs/*" = ["D"]
86
+
87
+ [tool.pytest]
88
+ minversion = "9.0"
89
+ strict = true
90
+ testpaths = ["tests"]
91
+ filterwarnings = ["error::RuntimeWarning"]
@@ -0,0 +1,96 @@
1
+ [project]
2
+ name = "fuzlog"
3
+ version = "0.1.0"
4
+ description = "Simple and enjoyable Python library for fuzzy logic."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "coredegon", email = "valikalik15@gmail.com" }
10
+ ]
11
+ requires-python = ">=3.12"
12
+ dependencies = [
13
+ "numpy>=2.0",
14
+ ]
15
+ keywords = [
16
+ "fuzzy",
17
+ "fuzzy-logic",
18
+ "fuzzy-sets",
19
+ "fuzzy-inference",
20
+ "membership-functions",
21
+ "mamdani",
22
+ "sugeno",
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 3 - Alpha",
26
+ "Intended Audience :: Developers",
27
+ "Intended Audience :: Science/Research",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python :: 3 :: Only",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Programming Language :: Python :: 3.14",
33
+ "Programming Language :: Python :: 3.15",
34
+ "Topic :: Scientific/Engineering",
35
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
36
+ "Typing :: Typed",
37
+ ]
38
+
39
+ [project.optional-dependencies]
40
+ plot = [
41
+ "matplotlib>=3.9",
42
+ ]
43
+
44
+ [project.urls]
45
+ Repository = "https://github.com/coredegon/fuzlog"
46
+ Documentation = "https://github.com/coredegon/fuzlog/tree/main/docs"
47
+ Issues = "https://github.com/coredegon/fuzlog/issues"
48
+
49
+ [build-system]
50
+ requires = ["uv_build>=0.13.7,<0.14.0"]
51
+ build-backend = "uv_build"
52
+
53
+ [dependency-groups]
54
+ dev = [
55
+ "matplotlib>=3.9",
56
+ "pytest>=9.2.0",
57
+ "ruff>=0.17.5",
58
+ "ty>=0.0.104",
59
+ ]
60
+
61
+ [tool.ruff.lint]
62
+ select = [
63
+ "E", "W", # pycodestyle
64
+ "F", # pyflakes
65
+ "I", # import order
66
+ "N", # naming
67
+ "D", # docstrings
68
+ "UP", # modern syntax
69
+ "B", # likely bugs
70
+ "C4", # comprehensions
71
+ "SIM", # simplifications
72
+ "PT", # pytest style
73
+ "NPY", # numpy
74
+ "PERF", # performance
75
+ "RUF", # ruff's own
76
+ ]
77
+ ignore = [
78
+ "D105", # operators are documented by their class
79
+ "D107", # and so is __init__
80
+ ]
81
+
82
+ [tool.ruff.lint.pydocstyle]
83
+ convention = "google"
84
+
85
+ [tool.ruff.lint.per-file-ignores]
86
+ "tests/*" = ["D"]
87
+ "docs/*" = ["D"]
88
+
89
+ # ty needs no table: it checks against the oldest Python in `requires-python`
90
+ # and fails on warnings by default.
91
+
92
+ [tool.pytest]
93
+ minversion = "9.0"
94
+ strict = true
95
+ testpaths = ["tests"]
96
+ filterwarnings = ["error::RuntimeWarning"] # a leaked overflow or 0/0 is a bug
@@ -0,0 +1,86 @@
1
+ """Fuzzy logic for Python: small, fast, typed.
2
+
3
+ ``import fuzlog as fz`` gives the whole library:
4
+
5
+ - sets: ``triangle``, ``trapezoid``, ``gauss`` and 13 more shapes, combined with
6
+ ``& | ~ **``;
7
+ - variables: ``Variable`` and ``partition``;
8
+ - rules: ``temp.hot & humidity.high >> fan.fast``;
9
+ - inference: ``Mamdani`` and ``Sugeno``;
10
+ - plots: ``variable.plot()``, ``system.plot(...)``, ``system.surface(...)``.
11
+ """
12
+
13
+ from fuzlog.core import (
14
+ Mamdani,
15
+ Sugeno,
16
+ bell,
17
+ bisector,
18
+ bounded_diff,
19
+ bounded_sum,
20
+ centroid,
21
+ dsigmoid,
22
+ extremely,
23
+ falling,
24
+ gauss,
25
+ gauss2,
26
+ lom,
27
+ mom,
28
+ partition,
29
+ pi_shape,
30
+ piecewise,
31
+ probor,
32
+ psigmoid,
33
+ rectangle,
34
+ rising,
35
+ s_shape,
36
+ sigmoid,
37
+ singleton,
38
+ som,
39
+ somewhat,
40
+ trapezoid,
41
+ triangle,
42
+ very,
43
+ z_shape,
44
+ )
45
+ from fuzlog.types import MF, Array, Defuzzifier, Kernel, Norm, Prop, Rule, Variable
46
+
47
+ __all__ = [
48
+ "MF",
49
+ "Array",
50
+ "Defuzzifier",
51
+ "Kernel",
52
+ "Mamdani",
53
+ "Norm",
54
+ "Prop",
55
+ "Rule",
56
+ "Sugeno",
57
+ "Variable",
58
+ "bell",
59
+ "bisector",
60
+ "bounded_diff",
61
+ "bounded_sum",
62
+ "centroid",
63
+ "dsigmoid",
64
+ "extremely",
65
+ "falling",
66
+ "gauss",
67
+ "gauss2",
68
+ "lom",
69
+ "mom",
70
+ "partition",
71
+ "pi_shape",
72
+ "piecewise",
73
+ "probor",
74
+ "psigmoid",
75
+ "rectangle",
76
+ "rising",
77
+ "s_shape",
78
+ "sigmoid",
79
+ "singleton",
80
+ "som",
81
+ "somewhat",
82
+ "trapezoid",
83
+ "triangle",
84
+ "very",
85
+ "z_shape",
86
+ ]