Skip to main content

X-ANFIS: Modular ANFIS Library with Classic, Gradient, and Bio-inspired Training Strategies

GitHub release Wheel PyPI version PyPI - Python Version PyPI - Downloads Downloads Tests & Publishes to PyPI Documentation Status Chat DOI License: GPL v3


X-ANFIS is a Python library offering a powerful and extensible implementation of Adaptive Neuro-Fuzzy Inference System (ANFIS) using PyTorch and Scikit-Learn. The library is written with object-oriented principles and modular architecture, enabling easy customization, integration, and experimentation.It supports:

  • 🔧 Classic ANFIS (Hybrid: Gradient Descent + Least Squares)
  • 🌊 Gradient-based ANFIS (Fully differentiable training)
  • 🧠 Bio-inspired ANFIS (Metaheuristics + Least Squares)

✨ Key Features

  • Modular, object-oriented design for ease of extension.
  • Scikit-Learn API: .fit(), .predict(), .score() and compatible with GridSearchCV, Pipeline, etc.
  • Wide range of Gradient-based training optimizers: SGD, Adam, RMSprop, Adagrad, AdamW, ...
  • Wide range of Bio-inspired optimizers: GA, PSO, ACO, WOA, BA, FFA, CSA, GWO, ABC, DE, ...
  • Rich membership functions: Triangular, Gaussian, Bell, ...
  • Over 67 built-in metrics and losses.

🧠 Model Zoo

Model Class Training Method Type
AnfisRegressor, AnfisClassifier Classic Hybrid Regression / Classification
GdAnfisRegressor, GdAnfisClassifier Gradient-based Regression / Classification
BioAnfisRegressor, BioAnfisClassifier Metaheuristic-based Regression / Classification

📌 Citation

Please include these citations if you plan to use this library:

@software{thieu20250414,
  author  = {Nguyen Van Thieu},
  title   = {X-ANFIS: An Extensible and Cross-Learning ANFIS Framework for Machine Learning Tasks},
  month   = June,
  year    = 2025,
  doi     = {10.6084/m9.figshare.28802531},
  url     = {https://github.com/thieu1995/X-ANFIS}
}

@article{van2023mealpy,
  title   = {MEALPY: An open-source library for latest meta-heuristic algorithms in Python},
  author  = {Van Thieu, Nguyen and Mirjalili, Seyedali},
  journal = {Journal of Systems Architecture},
  year    = {2023},
  publisher = {Elsevier},
  doi     = {10.1016/j.sysarc.2023.102871}
}

⚙️ General tutorial

Below tutorial is how you can install and use this library. For more complex examples and documentation please check the examples folder and documentation website.

📦 Installation

Install the latest version using pip:

pip install xanfis

After that, check the version to ensure successful installation:

$ python
>>> import xanfis
>>> xanfis.__version__

🧪 Quick Example

Let's say I want to use Adam optimization-based ANFIS for Iris classification dataset. Here how to do it.

from xanfis import Data, GdAnfisClassifier
from sklearn.datasets import load_iris

## Load data object
X, y = load_iris(return_X_y=True)
data = Data(X, y)

## Split train and test
data.split_train_test(test_size=0.2, random_state=2, inplace=True, shuffle=True)
print(data.X_train.shape, data.X_test.shape)

## Scaling dataset
data.X_train, scaler_X = data.scale(data.X_train, scaling_methods=("standard", "minmax"))
data.X_test = scaler_X.transform(data.X_test)

data.y_train, scaler_y = data.encode_label(data.y_train)
data.y_test = scaler_y.transform(data.y_test)

print(type(data.X_train), type(data.y_train))

## Create model
model = GdAnfisClassifier(num_rules=20, mf_class="Gaussian",
                          act_output=None, vanishing_strategy="blend", reg_lambda=None,
                          epochs=50, batch_size=16, optim="Adam", optim_params={"lr": 0.01},
                          early_stopping=True, n_patience=10, epsilon=0.001, valid_rate=0.1,
                          seed=42, verbose=True)
## Train the model
model.fit(X=data.X_train, y=data.y_train)

## Test the model
y_pred = model.predict(data.X_test)
print(y_pred)
print(model.predict_proba(data.X_test))

## Calculate some metrics
print(model.evaluate(y_true=data.y_test, y_pred=y_pred, list_metrics=["F2S", "CKS", "FBS", "PS", "RS", "NPV", "F1S"]))

💬 Contributing

We welcome contributions to X-ANFIS! If you have suggestions, improvements, or bug fixes, feel free to fork the repository, create a pull request, or open an issue.

X-ANFIS allows for customization at various levels, including:

  • Membership Functions: You can define custom membership functions to fit your problem requirements.

  • Learning Strategies: Easily switch between gradient-based or bio-inspired algorithms for training.

  • Model Components: Customize the architecture of the ANFIS model, including the number of input and output nodes, output activation function, number of rules, and rule strengths, L2 regularization, training methods.

📞 Community & Support

🧩 Related Projects

Explore other projects by the author:


Developed by: Thieu @ 2025

Metadata

Release files for xanfis 1.1.0

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

Source distribution (sdist)

Source distribution for xanfis 1.1.0
File Size Uploaded
xanfis-1.1.0.tar.gz 54.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xanfis 1.1.0
File Interpreter ABI Platform
xanfis-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 107.2 kB

Release files / xanfis-1.1.0.tar.gz

Download URL xanfis-1.1.0.tar.gz
Size 54.0 kB
Tags Source
SHA-256 checksum
How to use checksums
93c8e24651dfed5fd2216261a00dc21e0b7471008c588869d4a041ed305df0f3
BLAKE2b-256 checksum
How to use checksums
f7082dad0d6929407af0ea1b251d17a8e661d899c5fb5be6ffad128456268171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2025.

Transparency log

Release files / xanfis-1.1.0-py3-none-any.whl

Download URL xanfis-1.1.0-py3-none-any.whl
Size 53.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6e0ae8d55fd1d8fa6d4f627987ba5d1b9231b6f5041daeed3e11cbbc373004b
BLAKE2b-256 checksum
How to use checksums
ab0c1777b47bc44b27ed42a11b7a55036c0e6dabcbc6716a7dfaab07c83dfd70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

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