Metadata-Version: 2.4
Name: fuzzytool
Version: 0.3.0
Summary: A clean, extensible fuzzy-logic toolkit in pure Python + NumPy
Project-URL: Homepage, https://fuzzytool.github.io
Project-URL: Documentation, https://fuzzytool.github.io
Project-URL: Repository, https://github.com/fuzzytool/fuzzytool.github.io
Project-URL: Issues, https://github.com/fuzzytool/fuzzytool.github.io/issues
Author: Jose L. Salmeron
License: MIT
License-File: LICENSE
Keywords: anfis,fuzzy inference,fuzzy logic,mamdani,takagi-sugeno,type-2
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.9
Requires-Dist: numpy>=1.21
Provides-Extra: agents
Requires-Dist: langchain-core>=0.1; extra == 'agents'
Provides-Extra: dask
Requires-Dist: dask>=2022.0; extra == 'dask'
Provides-Extra: dev
Requires-Dist: joblib>=1.0; extra == 'dev'
Requires-Dist: langchain-core>=0.1; extra == 'dev'
Requires-Dist: optuna>=3.0; extra == 'dev'
Requires-Dist: pandas>=1.3; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: scikit-learn>=1.0; extra == 'dev'
Requires-Dist: scipy>=1.7; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material; extra == 'docs'
Requires-Dist: mkdocstrings[python]; extra == 'docs'
Provides-Extra: notebooks
Requires-Dist: ipykernel; extra == 'notebooks'
Requires-Dist: jupyter; extra == 'notebooks'
Requires-Dist: matplotlib>=3.4; extra == 'notebooks'
Requires-Dist: nbconvert; extra == 'notebooks'
Requires-Dist: nbformat; extra == 'notebooks'
Provides-Extra: optuna
Requires-Dist: optuna>=3.0; extra == 'optuna'
Provides-Extra: pandas
Requires-Dist: pandas>=1.3; extra == 'pandas'
Provides-Extra: parallel
Requires-Dist: joblib>=1.0; extra == 'parallel'
Provides-Extra: scipy
Requires-Dist: scipy>=1.7; extra == 'scipy'
Provides-Extra: sklearn
Requires-Dist: scikit-learn>=1.0; extra == 'sklearn'
Provides-Extra: torch
Requires-Dist: torch>=1.12; extra == 'torch'
Provides-Extra: viz
Requires-Dist: matplotlib>=3.4; extra == 'viz'
Description-Content-Type: text/markdown

<p align="center">
  <a href="https://pypi.org/project/fuzzytool/"><img src="https://img.shields.io/pypi/v/fuzzytool?logo=pypi&logoColor=white" alt="PyPI"></a>
  <a href="https://github.com/fuzzytool/fuzzytool.github.io/actions/workflows/ci.yml"><img src="https://github.com/fuzzytool/fuzzytool.github.io/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
  <a href="https://fuzzytool.github.io/"><img src="https://img.shields.io/badge/docs-fuzzytool.github.io-3f51b5" alt="Docs"></a>
  <img src="https://img.shields.io/pypi/pyversions/fuzzytool?logo=python&logoColor=white" alt="Python versions">
  <img src="https://img.shields.io/badge/license-MIT-blue" alt="License: MIT">
  <a href="https://doi.org/10.5281/zenodo.20836712"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.20836712.svg" alt="DOI"></a>
</p>

# 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.

```python
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, Optuna, Joblib/Dask, LLM agents | ✅ |

### 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`](ROADMAP.md).

## Install

```bash
pip install fuzzytool            # core (NumPy only)
pip install fuzzytool[viz]       # + matplotlib visualization
```

From source, for development:

```bash
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/>.

```bash
pip install -e ".[docs]"
mkdocs serve        # live portal at http://127.0.0.1:8000
```

## License

MIT. See [`LICENSE`](LICENSE).
