Skip to main content

ANFIS Toolbox

ANFIS Toolbox

anfis-toolbox version doi License: MIT docs Python versions CI Coverage

ANFIS Toolbox is a comprehensive Python library for creating, training, and deploying Adaptive Neuro-Fuzzy Inference Systems (ANFIS). It provides an intuitive API that makes fuzzy neural networks accessible to both beginners and experts.

🚀 Overview

  • Takagi–Sugeno–Kang (TSK) ANFIS with the classic four-layer architecture (Membership → Rules → Normalization → Consequent).
  • Regressor and classifier facades with a familiar scikit-learn style (fit, predict, score).
  • Trainers (Hybrid, SGD, Adam, RMSProp, PSO) decoupled from the model for easy experimentation.
  • 10+ membership function families. The primary public interfaces are ANFISRegressor and ANFISClassifier.
  • Thorough test coverage (100%+).

📦 Installation

Install from PyPI:

pip install anfis-toolbox

🧠 Quick start

Regression

import numpy as np
from anfis_toolbox import ANFISRegressor

X = np.random.uniform(-2, 2, (100, 2))
y = X[:, 0]**2 + X[:, 1]**2

model = ANFISRegressor()
model.fit(X, y)
metrics = model.evaluate(X, y)

Classification

import numpy as np
from anfis_toolbox import ANFISClassifier

X = np.r_[np.random.normal(-1, .3, (50, 2)), np.random.normal(1, .3, (50, 2))]
y = np.r_[np.zeros(50, int), np.ones(50, int)]

model = ANFISClassifier()
model.fit(X, y)
metrics = model.evaluate(X, y)

🧩 Membership functions at a glance

  • Gaussian (GaussianMF) - Smooth bell curves
  • Gaussian2 (Gaussian2MF) - Two-sided Gaussian with flat region
  • Triangular (TriangularMF) - Simple triangular shapes
  • Trapezoidal (TrapezoidalMF) - Plateau regions
  • Bell-shaped (BellMF) - Generalized bell curves
  • Sigmoidal (SigmoidalMF) - S-shaped transitions
  • Diff-Sigmoidal (DiffSigmoidalMF) - Difference of two sigmoids
  • Prod-Sigmoidal (ProdSigmoidalMF) - Product of two sigmoids
  • S-shaped (SShapedMF) - Smooth S-curve transitions
  • Linear S-shaped (LinSShapedMF) - Piecewise linear S-curve
  • Z-shaped (ZShapedMF) - Smooth Z-curve transitions
  • Linear Z-shaped (LinZShapedMF) - Piecewise linear Z-curve
  • Pi-shaped (PiMF) - Bell with flat top

🛠️ Training options

  • SGD (Stochastic Gradient Descent) – Classic gradient-based optimization with incremental updates
  • Adam – Adaptive learning rates with momentum for faster convergence
  • RMSProp – Scales learning rates by recent gradient magnitudes for stable training
  • PSO (Particle Swarm Optimization) – Population-based global search strategy
  • Hybrid SGD + OLS – Combines gradient descent with least-squares parameter refinement
  • Hybrid Adam + OLS – Integrates adaptive optimization with analytical least-squares adjustment

📚 Documentation

  • Comprehensive guides, API reference, and examples: docs/ (built with MkDocs).

🧪 Testing & quality

Local setup

Clone the repository:

git clone https://github.com/dcruzf/anfis-toolbox.git
cd anfis-toolbox

Create a virtual environment:

python -m venv .venv

Activate it:

Linux / macOS

source .venv/bin/activate

Windows (PowerShell)

.venv\Scripts\Activate.ps1

Install the project in editable mode with development dependencies (this includes Hatch and all test tools):

pip install -e .[dev]

Running tests

Run the full test suite with coverage:

hatch test -c --all

This project is tested on Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14 across Linux, Windows and macOS.

Linting & Formatting

Run the linter and format the codebase:

hatch fmt

Typing

Run static type checks:

hatch run typing

Security

Run security checks with Bandit:

hatch run security

🤝 Contributing

Issues and pull requests are welcome! Please open a discussion if you’d like to propose larger changes. See the docs/guide section for architecture notes and examples.

📄 License

Distributed under the MIT License. See LICENSE for details.

📚 References

  1. Jang, J. S. (1993). ANFIS: adaptive-network-based fuzzy inference system. IEEE transactions on systems, man, and cybernetics, 23(3), 665-685. https://doi.org/10.1109/21.256541

Metadata

Release files for anfis-toolbox 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anfis-toolbox 0.2.2
File Size Uploaded
anfis_toolbox-0.2.2.tar.gz 139.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anfis-toolbox 0.2.2
File Interpreter ABI Platform
anfis_toolbox-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 230.6 kB

Release files / anfis_toolbox-0.2.2.tar.gz

Download URL anfis_toolbox-0.2.2.tar.gz
Size 139.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7f7b3b8bb304c3b21a0709d9d650809bcf154bc25756e221f9a8369991d17182
BLAKE2b-256 checksum
How to use checksums
88ccb69157886cc8efb711bd9411c66aa5fe4b472a73db795e02ce511b57aacb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.3 cpython/3.12.3 HTTPX/0.28.1

Release files / anfis_toolbox-0.2.2-py3-none-any.whl

Download URL anfis_toolbox-0.2.2-py3-none-any.whl
Size 90.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
886faad6066cacb05d5bb7237b538f92441b67d48f769125f54466aa749f6357
BLAKE2b-256 checksum
How to use checksums
2c04e950c675f7da834d8f629a9c5c8cad23e14089f6a5553e3bd4197c255b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.3 cpython/3.12.3 HTTPX/0.28.1

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page