Skip to content

ANFIS Toolbox

ANFIS Toolbox Logo

The most user-friendly Python library for Adaptive Neuro-Fuzzy Inference Systems (ANFIS)


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.



Key Features

✨ Easy to Use
Get started with just 3 lines of code
πŸ€– Versatile Modeling
Supports both classification and regression tasks
πŸ—οΈ Flexible Architecture
13 membership functions
πŸš€ Adaptive Initialization
Fuzzy c-means, grid, and random initialization strategies
πŸ“‰ Flexible Optimization
Multiple optimization algorithms
πŸ“ Comprehensive Metrics
Rich collection of evaluation metrics
πŸ“š Rich Documentation
Comprehensive examples

Why ANFIS Toolbox?

πŸš€ Simplicity First

Most fuzzy logic libraries require extensive boilerplate code. ANFIS Toolbox gets you running in seconds:

from anfis_toolbox import ANFISRegressor

model = ANFISRegressor()
model.fit(X, y)
from anfis_toolbox import ANFISClassifier

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

⚑ Quick Example

import numpy as np
from anfis_toolbox import ANFISRegressor

X = np.random.uniform(-2, 2, (100, 2))  # 2 inputs
y = X[:, 0]**2 + X[:, 1]**2  # Target: x1Β² + x2Β²

model = ANFISRegressor()
model.fit(X, y)
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 & Evaluation

Want a structured report instead of a plain dictionary? Use evaluate to detect the task type automatically and access every score.

metrics = model.evaluate(X, y)

That's it! πŸŽ‰ You just created, trained and evaluate a neuro-fuzzy system!

Installation

Install the core package with minimal dependencies:

pip install anfis-toolbox

Use Cases

Application Description
Function Approximation Learn complex mathematical functions
Regression Predict continuous values
Classification Predict discrete class labels
Time Series Forecast future values

Architecture

ANFIS Toolbox implements the complete 4-layer ANFIS architecture:

flowchart LR

    %% Layer 1
    subgraph L1 [layer 1]
      direction TB
      A1["A1"]
      A2["A2"]
      B1["B1"]
      B2["B2"]
    end

    %% Inputs
    x_input[x] --> A1
    x_input --> A2
    y_input[y] --> B1
    y_input --> B2

    %% Layer 2
    subgraph L2 [layer 2]
      direction TB
      P1((Ξ ))
      P2((Ξ ))
    end
    A1 --> P1
    B1 --> P1
    A2 --> P2
    B2 --> P2

    %% Layer 3
    subgraph L3 [layer 3]
      direction TB
      N1((N))
      N2((N))
    end
    P1 -- w₁ --> N1
    P1 ----> N2
    P2 ----> N1
    P2 -- wβ‚‚ --> N2

    %% Layer 4
    subgraph L4 [layer 4]
      direction TB
      L4_1[x y]
      L4_2[x y]
    end
    N1 -- w̅₁ --> L4_1
    N2 -- wΜ…β‚‚ --> L4_2

    %% Layer 5
    subgraph L5 [layer 5]
      direction TB
      Sum((Ξ£))
    end
    L4_1 -- "w₁ f₁" --> Sum
    L4_2 -- "wβ‚‚ fβ‚‚" --> Sum

    %% Output
    Sum -- f --> f_out[f]

Supported Membership Functions

  • 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 Methods

  • 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

What's Next?

Community & Support


Ready to dive into fuzzy neural networks?
Get started now