Skip to main content

A clean, extensible fuzzy-logic toolkit in pure Python + NumPy

Project description

PyPI CI Docs Python versions License: MIT DOI

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 callable x -> degree. A new shape = a new callable.
  • Norm (fuzzytool/norms.py) — t-norms (AND) and s-norms (OR), resolved by name. A new connective = one registered function.
  • defuzzifiers (fuzzytool/defuzz.py) — centroid, bisector, MOM/SOM/LOM, resolved by name.

Rules read like logic thanks to operator overloading: & is the t-norm, | the s-norm, ~ the complement.

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

v0.5.0

  • General type-2 (GT2) fuzzy sets via the zSlices / alpha-plane representation: GeneralType2MF, the gt2_* constructors, GeneralType2Mamdani inference and centroid_gt2 type 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 (differentiable FuzzyLayer), SciPy (MF tuning), Optuna (hyperparameter search), Joblib/Dask (parallel inference) and LLM agents (explainable inference_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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fuzzytool-0.5.0.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fuzzytool-0.5.0-py3-none-any.whl (62.1 kB view details)

Uploaded Python 3

File details

Details for the file fuzzytool-0.5.0.tar.gz.

File metadata

  • Download URL: fuzzytool-0.5.0.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fuzzytool-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5e173394f6a0d7feb29f2c41aeeb07a1780a891418325d5a505157059f4e7f87
MD5 79be196d47ca50381c68042726461608
BLAKE2b-256 41b594081ec94a341f08c7043e1fc65a5f017d8e24defa49f0fdd7e3c2b59881

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzytool-0.5.0.tar.gz:

Publisher: release-pypi.yml on fuzzytool/fuzzytool.github.io

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzytool-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: fuzzytool-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 62.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fuzzytool-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8470ef44ffd01ff39df108c7bd43e4a70623285de4cfc446ad8cfe3173a8ba1e
MD5 fd2b53a65ffce342d300e9325baeb146
BLAKE2b-256 a1a28d16b0e5a50df3dc1c9bb01c7f0820b4f1fac65b5279d68bed0a951fa149

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzytool-0.5.0-py3-none-any.whl:

Publisher: release-pypi.yml on fuzzytool/fuzzytool.github.io

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page