This repository contains implementations and experiments with fuzzy logic-based systems focused on nonlinear function approximation, regression, and predictive modeling.
The main goal of this project is to investigate and validate methods for:
- Automatic fuzzy rule extraction;
- Neuro-fuzzy learning systems;
- Nonlinear function approximation;
- Dynamic system modeling;
- Prediction of complex and chaotic behaviors.
The project explores two main approaches:
- Wang-Mendel fuzzy rule extraction, focused on interpretability and symbolic knowledge generation;
- ANFIS (Adaptive Neuro-Fuzzy Inference System), focused on parameter optimization through neural learning.
- Python
- NumPy
- TensorFlow / Keras
- Fuzzy Logic Systems
- ANFIS
- Wang-Mendel Algorithm
- Neuro-Fuzzy Networks
- Scientific Computing
- Data Analysis
The classical Wang-Mendel (WM) algorithm is implemented to generate an interpretable fuzzy knowledge base from numerical data.
The model maps input-output relationships by extracting fuzzy rules directly from observations.
The input space is partitioned dynamically using five triangular membership functions based on statistical properties of the dataset:
min, q25, q50, q75, max
This approach allows the model to automatically adapt the fuzzy universe of discourse according to the distribution of the input data.
The fuzzy antecedents are combined using the product T-norm:
where each membership value contributes to the final rule activation degree.
The output prediction is obtained using a weighted center-of-area approach:
where:
-
$w_i$ represents the rule activation degree; -
$c_i$ represents the consequent center.
One of the main contributions of this implementation is an adaptive extrapolation mechanism.
When a combination of fuzzy antecedents has no corresponding training samples, the model performs a geometric neighborhood search.
The algorithm searches for rules sharing exactly:
common antecedents.
The final prediction is estimated using:
- Euclidean distance between membership-function centers;
- Degree of certainty (
DOC) weighting.
This allows the model to generalize beyond observed regions of the input space.
The project also implements a neuro-fuzzy model based on the Takagi-Sugeno architecture.
Unlike Wang-Mendel, which generates static fuzzy rules, ANFIS represents the fuzzy inference system as a trainable neural architecture.
The model optimizes:
- Membership function parameters (antecedent layer);
- Linear consequent coefficients.
Optimization is performed through learning algorithms such as:
- Gradient descent;
- Hybrid optimization strategies.
The model follows the classical five-layer structure:
-
Fuzzification layer
- Computes membership values.
-
Rule layer
- Calculates rule activation strengths.
-
Normalization layer
- Normalizes firing strengths.
-
Consequent layer
- Computes Takagi-Sugeno functions.
-
Output layer
- Aggregates the final prediction.
The classical XOR (Exclusive OR) problem was used to evaluate the ability of fuzzy systems to represent nonlinear decision boundaries.
Since XOR is not linearly separable, it is a useful benchmark for testing whether fuzzy rules and overlapping membership functions can generate complex decision surfaces.
The experiment evaluates:
- Rule granularity;
- Membership overlap;
- Nonlinear separation capability.
Both models were evaluated:
- Wang-Mendel;
- ANFIS.
Although both achieved satisfactory results, ANFIS obtained better performance due to its adaptive parameter optimization capability.
To evaluate the capability of fuzzy models to approximate nonlinear and chaotic dynamics, the classical Narendra-Li benchmark was used.
The dataset is transformed into an autoregressive temporal representation using a lag window.
The model receives five input variables.
The target variable represents the continuous nonlinear dynamic signal:
The benchmark evaluates the ability of fuzzy systems to model temporal dependencies and nonlinear behavior.
| Model | RMSE | MAE |
|---|---|---|
| Wang-Mendel | 0.1376 | 0.2974 |
| ANFIS | 0.0005 | 0.0168 |
├── fuzzy_model.py # WMModel implementation and rule extrapolation logic
├── anfis_model.py # ANFIS neural fuzzy architecture
├── utils.py # Membership functions, inference utilities, and helpers
├── teste_narendra_li.py # Narendra-Li benchmark training and evaluation
├── validacao_xor.py # XOR experiment and validation
├── pyproject.toml # Project configuration and dependencies (uv)
└── logs/ # Training logs, JSON metrics, and CSV results
Possible future extensions:
- Add additional fuzzy partitioning strategies;
- Compare different membership functions (Gaussian, trapezoidal, triangular);
- Implement alternative T-norm operators;
- Add GPU acceleration for ANFIS training;
- Compare against traditional neural networks;
- Create visualization dashboards for fuzzy rules;
- Evaluate additional nonlinear dynamic benchmarks.
- Wang, L. X., & Mendel, J. M. (1992). Generating fuzzy rules by learning from examples.
- Jang, J. S. R. (1993). ANFIS: Adaptive-Network-Based Fuzzy Inference System.
- Narendra, K. S., & Li, C. (1996). Identification and control of dynamical systems using neural networks.

