Adaptive Neuro-Fuzzy Inference System for Python based on PyTorch library
Project description
TorchANFIS
Adaptive Neuro-Fuzzy Inference System (ANFIS) implemented in PyTorch with a clean, sklearn-style API.
Features
Sklearn-style interface:
fit(X, y)predict(X)score(X, y)save(path)/load(path)
Training modes:
- Gradient Descent
- Hybrid Learning (Least Squares + Gradient)
Advanced capabilities:
- Hard (classical) rule selection
- Soft (differentiable) rule selection
- Feature masking (learn feature importance per rule)
- Rule sharpening (temperature scaling)
Compatible with:
- NumPy
- Scikit-learn pipelines
Architecture
Input → Membership Functions → Rule Layer → Normalization → Consequents → Output
Key Components
| Layer | Description |
|---|---|
| Membership Layer | Gaussian / Trapezoidal fuzzy sets |
| Rule Layer | Hard or differentiable rule selection |
| Consequent Layer | First-order Sugeno linear models |
Research Modes
Rule Modes Mode Description hard classical ANFIS soft differentiable rule selection
Feature Modes Mode Description full all features used masked learn feature importance per rule
Usage
Quick Example
import numpy as np from torchanfis import ANFISRegressor
Synthetic data
X = np.random.rand(200, 2) y = np.sin(X[:, 0]) + X[:, 1] ** 2
model = ANFISRegressor( n_mfs=3, n_rules=4, epochs=50 )
model.fit(X, y)
y_pred = model.predict(X)
print("RMSE:", model.score(X, y))
Testing
Install pytest:
pip install pytest
Run tests:
pytest tests/
Expected:
===================== 16 passed
Test Coverage
Test Purpose model_forward forward pass correctness membership_shapes MF outputs rule_layer_shapes rule logic no_nan_forward numerical stability fit_runs training loop learning_improves_loss model learns predict_shape output shape save_load persistence soft_mf_mode differentiable rules feature_mask_mode feature masking hybrid_training LSE step
Benchmark
Run:
python -m benchmarks.benchmark_torchanfis
or:
python benchmarks/benchmark_torchanfis.py Models Compared
- Linear Regression
Random Forest
Gradient Boosting
MLP
Classical ANFIS
Research ANFIS
Example Output model rmse MLP 0.50 RandomForest 0.54 GradientBoost 0.54 ResearchANFIS 0.54 ClassicalANFIS 0.61 Linear 0.74
Save / Load
model.save("model.pkl") loaded = ANFISRegressor.load("model.pkl")
License
This project is dual-licensed:
- Open-source: GPL-3.0
- Commercial: available on request
You may use this project under the terms of the GPL-3.0 license, or obtain a commercial license for proprietary use.
For commercial licensing, contact: mark.aull+torchanfis@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchanfis-0.1.0.tar.gz.
File metadata
- Download URL: torchanfis-0.1.0.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d48e97633575f09d4265b77ba8c5004ae8cebea4222e8a89d077449f447c36c0
|
|
| MD5 |
fd818ce2f948d1847883a224e45b4633
|
|
| BLAKE2b-256 |
edbe32980a6fff43f61c58b36fb6d27d01bee644b3d3a53eb76895d2c2be95e9
|
File details
Details for the file torchanfis-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torchanfis-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb1389f0423db6efd987482b93af0b095be68e6d910b425cd27b62261842f430
|
|
| MD5 |
fe4db0a13a33ff61d282f03f26fb5d6b
|
|
| BLAKE2b-256 |
1cfd807483e1ff0f05a5a4a75ae477c5dcabd597a4f6db7a559a5e5ec6fd6e0d
|