fuzzytool
A clean, extensible fuzzy-logic toolkit in pure Python + NumPy. Its design priorities are a composable API, algorithm comparison, visualization and code clarity — a modern alternative to the verbose control API of scikit-fuzzy.
import fuzzytool as fz
# Credit-risk premium: a lender turns a credit score + debt-to-income ratio
# into the risk points it adds on top of its base interest rate.
score = fz.Variable("score", (300, 850), terms=["poor", "fair", "good", "excellent"])
dti = fz.Variable("dti", (0, 50), terms=["low", "moderate", "high"])
premium = fz.Variable("premium", (0, 12), terms=["low", "medium", "high"])
sys = fz.Mamdani(defuzz="centroid")
sys.rule(score["poor"] | dti["high"], premium["high"]) # |=OR &=AND ~=NOT
sys.rule(score["fair"] & dti["moderate"], premium["medium"])
sys.rule(score["good"] | score["excellent"], premium["low"])
print(sys(score=800, dti=10)) # the system is just callable -> a low premium
The design idea (extensibility)
The inference loop knows nothing about any concrete variant. Everything that changes lives behind small Python Protocols:
MembershipFunction(fuzzytool/membership.py) — a callablex -> degree. A new shape = a new callable.Norm(fuzzytool/norms.py) — t-norms (AND), s-norms (OR) and complements (NOT), resolved by name. A new connective = one registered function.- defuzzifiers (
fuzzytool/defuzz.py) — centroid, bisector, MOM/SOM/LOM, weighted average, COA, resolved by name.
Rules read like logic thanks to operator overloading: & is the t-norm, | the
s-norm, ~ the complement. They can also be written the way a policy document
writes them:
sys.rule_from_text("IF score IS poor OR dti IS high THEN premium IS high",
[score, dti, premium])
Every model explains and audits itself
A fuzzy system is supposed to be readable — but nothing stops a rule base from contradicting itself or leaving regions where no rule fires, and neither is visible at the call site. So every engine answers why, and the whole rule base can be checked:
sys.explain(score=520, dti=42) # the output + which rules produced it
print(audit(sys)) # contradictions, dead rules, coverage holes
audit: 3 rules, coverage 91.7%
unused terms (1):
dti[low]
uncovered inputs (10):
{'score': 630.0, 'dti': 0.0}
...
What it includes / roadmap
| Phase | Content | Status |
|---|---|---|
| 1 | Core: membership functions, t-/s-norms, Variable, operator rules, Mamdani + defuzzification, fraud-alert example, tests |
✅ |
| 2 | Takagi-Sugeno (TSK) inference + viz (membership plots, control surface) |
✅ (TSK + viz) |
| 3 | Type-2 / interval type-2 sets (footprint of uncertainty) + Karnik-Mendel type reduction | ✅ |
| 4 | Fuzzy clustering: fuzzy c-means, Gustafson-Kessel, possibilistic | ✅ |
| 5 | ANFIS (trainable TSK) + F-transform (direct/inverse) | ✅ |
| 6 | Notebooks, JOSS paper.md, Zenodo DOI, PyPI release |
✅ |
| 7 | Ecosystem integrations: pandas, scikit-learn, PyTorch, SciPy, turboswarm, Optuna, Joblib/Dask, LLM agents | ✅ |
| 8 | Classification, auditing, relations & measures, rules as text, scatter partitions | ✅ |
v0.7.0
- Fuzzy classification:
FuzzyClassifier(class-label consequents with certainty factors,predict_proba, an explicit reject option) and thechilearning algorithm, plus scikit-learn estimators. - Rule-base auditing:
auditfinds contradictions, duplicates, dead rules, unused and indistinguishable terms, and coverage holes;pruneremoves what carries no information;interpretabilityreports readability metrics. - Rules as text:
rule_from_text/parse_rule— the syntax a policy document (or an LLM) writes. explain/summary/firingon every engine, promoted from the agents integration into the core.- Fuzzy relations and measures: the compositional rule of inference, six implication operators, composition, transitive closure; distances, similarity, subsethood, entropy.
- Faster: antecedent evaluation is memoized per call (~8× on a 125-rule
system),
predictchunks large batches, andeiasctype reduction is 6-12× faster than Karnik-Mendel with identical results. - Scatter partitions:
subtractive_clustering,chiu_tsk,cmeans_tsk, andANFIS(partition="cluster")— 42× faster with 24× fewer rules on a 5-input problem. - More shapes and connectives:
smf,zmf,pimf,gauss2,singleton; Einstein/Hamacher/drastic/nilpotent norms and the Yager, Dombi and Frank families; a pluggable complement;wtaverandcoadefuzzifiers.
v0.5.0
- General type-2 (GT2) fuzzy sets via the zSlices / alpha-plane
representation:
GeneralType2MF, thegt2_*constructors,GeneralType2Mamdaniinference andcentroid_gt2type reduction — reusing the existing interval type-2 / Karnik-Mendel machinery.
v0.4.0
- turboswarm integration: gradient-free, global tuning of a fuzzy system's
membership functions with Particle Swarm Optimization
(
integrations.turboswarm.tune) — the metaheuristic sibling of the SciPy tuner.
v0.3.0
- Integrations (
fuzzytool.integrations.*, each behind its own extra): pandas (DataFrame I/O), scikit-learn (Fuzzifier, regressors), PyTorch (differentiableFuzzyLayer), SciPy (MF tuning), Optuna (hyperparameter search), Joblib/Dask (parallel inference) and LLM agents (explainableinference_tool). - Tutorials and an Integrations guide page, with rendered plots and computed outputs throughout the docs.
v0.2.0
- Fuzzy numbers & MCDM: triangular/trapezoidal fuzzy-number arithmetic, Fuzzy TOPSIS and Fuzzy AHP.
- Rule learning: Wang-Mendel rule-base generation from data; Tsukamoto inference (monotonic consequents).
- Engineering: vectorized batch inference (
predict), JSON save/load, and a scikit-learn estimator interface for ANFIS.
See ROADMAP.md.
Install
pip install fuzzytool # core (NumPy only)
pip install fuzzytool[viz] # + matplotlib visualization
From source, for development:
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev,viz,docs]"
pytest -q
python examples/fraud_alert.py
python examples/loan_decision.py # classification + explanation + audit
python benchmarks/benchmark.py # reproducible timings
Documentation
A documentation portal (narrative guide + API reference from docstrings) is built with MkDocs Material and published to GitHub Pages: https://fuzzytool.github.io/.
pip install -e ".[docs]"
mkdocs serve # live portal at http://127.0.0.1:8000
License
MIT. See LICENSE.
Release files for fuzzytool 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fuzzytool-0.7.0.tar.gz | 1.3 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fuzzytool-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.4 MB
Release files / fuzzytool-0.7.0.tar.gz
| Download URL | fuzzytool-0.7.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22a80356a6bc7acaaa28d5ca7d5841da4aba8649cbb5a96df44a704c3781419a
|
|
BLAKE2b-256 checksum How to use checksums |
e82c4275a5f4a2e9c3c5f21cb35ea975b47d0311ab31aa95c7c91075d39c2107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.
Transparency logRelease files / fuzzytool-0.7.0-py3-none-any.whl
| Download URL | fuzzytool-0.7.0-py3-none-any.whl |
|---|---|
| Size | 101.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
136c411db6c5ee3ab61299eb024bc6b0d94a495b089d2e85b2d5f0a0ad170e8f
|
|
BLAKE2b-256 checksum How to use checksums |
38d63876af5a59c28299b284a9b0a0faa0195ea2a261226099aae72b58507def
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.
Transparency log