fuzzytool¶
A clean, extensible fuzzy-logic toolkit in pure Python + NumPy. Design priorities: 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 from a credit score + debt-to-income ratio.
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"])
sys.rule(score["fair"] & dti["moderate"], premium["medium"])
sys.rule(score["good"] | score["excellent"], premium["low"])
sys(score=800, dti=10) # -> a crisp risk premium
Why fuzzytool¶
- Rules read like logic.
&is the t-norm (AND),|the s-norm (OR),~the complement (NOT). NoAntecedent/Consequent/ControlSystemboilerplate. - Everything is pluggable behind small Protocols — membership functions, connectives (AND, OR and NOT), defuzzifiers, type reducers. Adding a variant is adding a callable, never editing the inference loop. See Extending.
- Every model explains itself.
sys.explain(...)reports which rules fired and how much each contributed — on every engine, including the classifier and the type-2 engines. - And audits itself.
audit(sys)finds contradictions, dead rules, indistinguishable terms and the regions where no rule fires at all — the defects a rule base hides behind a plausible-looking number. See Auditing a rule base. - Rules can be text.
sys.rule_from_text("IF score IS poor THEN premium IS high"), for config files, spreadsheets, and LLM-authored rules. - Pure Python + NumPy. Universal wheel, no compilation.
Next steps¶
- Installation
- Getting started
- Tutorials — end-to-end walkthroughs
- The guide
Author¶
Created and maintained by Jose L. Salmeron. If you use fuzzytool in academic work, please cite it.