Simpful

A user-friendly and lightweight Python library for fuzzy logic reasoning.

Simpful is a Python library for fuzzy logic reasoning designed to provide a simple and lightweight API, as close as possible to natural language.

It serves as a robust engine for both Mamdani and Sugeno inference, supporting complex rule parsing with AND, OR, and NOT operators, and arbitrarily shaped fuzzy sets.

GitHub stars PyPI version License

Fuzzy Logic Model Estimation

Why Simpful?

Most fuzzy logic libraries are either overly academic or computationally heavy. Simpful was built to be developer-centric:

  • Intuitive Syntax: Define rules as strings (e.g., "IF (OXI IS low_flow) THEN (POWER IS LOW_POWER)").
  • Flexible Inference: Supports any order of Sugeno reasoning and classic Mamdani controllers.
  • Advanced Tools: Includes AutoTriangle for rapid prototyping and approximate_fs_labels for automated linguistic labeling.

Quick Start

Mamdani Tipping System

Simpful makes defining a controller as easy as writing a paragraph.

pip install simpful
from simpful import *

FS = FuzzySystem()

# Define linguistic variables quickly with AutoTriangle
TLV = AutoTriangle(3, terms=['poor', 'average', 'good'], universe_of_discourse=[0,10])
FS.add_linguistic_variable("service", TLV)
FS.add_linguistic_variable("quality", TLV)

# Define custom output variables
O1 = TriangleFuzzySet(0,0,13,   term="low")
O2 = TriangleFuzzySet(0,13,25,  term="medium")
O3 = TriangleFuzzySet(13,25,25, term="high")
FS.add_linguistic_variable("tip", LinguisticVariable([O1, O2, O3], universe_of_discourse=[0,25]))

# Natural language rules
FS.add_rules([
	"IF (quality IS poor) OR (service IS poor) THEN (tip IS low)",
	"IF (service IS average) THEN (tip IS medium)",
	"IF (quality IS good) OR (service IS good) THEN (tip IS high)"
	])

# Perform inference
FS.set_variable("quality", 6.5) 
FS.set_variable("service", 9.8) 
print(FS.inference())

More examples and use cases are available in the Simpful GitHub repository.

Technical Highlights

Rule Parsing

Parses any complex fuzzy rules involving nested logic (AND, OR, NOT) and linguistic hedges without manual coding of logic gates.

Custom Sets

Native support for Triangular, Gaussian, Trapezoidal, and custom points-based fuzzy sets for high-precision modeling.

Hybrid Inference

Seamlessly switch between Mamdani and Sugeno (of any order) within the same environment to suit different regression or control needs.

Automated Reporting

Generate PDF reports automatically with membership function graphs and rule summaries via the cluster_labeling module.

Core Publication

2020

  1. Simpful: a user-friendly python library for fuzzy logic
    Simone Spolaor, Caro Fuchs, Paolo Cazzaniga, and 3 more authors
    International Journal of Computational Intelligence Systems, 2020