Membership and sets
Eight membership families, explicit universes and immutable scalar fuzzy sets.
Choose a curve →
Python · Fuzzy mathematics · Open source
Turn measurements into interpretable grades with membership functions, fuzzy sets and linguistic scales. Build models for expert systems, risk assessment and engineering decisions.
CPython 3.13–3.14 · Typed scalar API · No mandatory NumPy dependency · Apache-2.0
Technologies · Knowledge · Science
How well does a room temperature of 24 °C fit the idea of “comfortable”? Define full comfort at 22 °C, decreasing to zero at 16 and 28 °C, then evaluate the measurement.
Use Python 3.13 or 3.14 in your project environment.
This example uses the 2.0 API. Install the matching version from PyPI; historical 1.x releases do not provide this API.
python -m pip install fuzzyroutines==2.0.0
Save this as comfort.py and run python comfort.py.
from fuzzyroutines import (
ContinuousUniverse, ScalarFuzzySet, Triangle,
)
universe = ContinuousUniverse(
0, 40, leftClosed=True, rightClosed=True,
)
comfort = ScalarFuzzySet(universe, Triangle(16, 22, 28))
temperature = 24
grade = comfort.Membership(temperature)
print(f"Temperature: {temperature} °C")
print(f"Comfort membership: {grade:.3f}")
Temperature: 24 °C
Comfort membership: 0.667
The temperature is on the descending side of the triangle: (28 − 24) / (28 − 22) = 2/3. A grade of 0.667 describes partial membership in the comfort set, not a probability.
These thresholds are illustrative model choices. Add other terms to distinguish comfortable, warm and hot conditions in your application.
Continue with a two-term scale →Historical model · Modern API
Min · Low · Med · High · Max
Reconstruct the historical scale with its original coefficients and compare it with the modern implementation. The guide includes membership curves, boundary cases and selection rules.
Use linguistic levels to describe normalized risk scores, security findings or control effectiveness. Define what a higher score means for your model; fuzzy membership is not an incident probability.
Eight membership families, explicit universes and immutable scalar fuzzy sets.
Choose a curve →Norms, negations, intersection, union and directed difference with explicit policies.
Worked scenarios →Linguistic classification, alpha-cuts and centroid computation with exact or numerical evidence.
API reference →Nine worked scenarios, reproducible graphs and a reference for the public API.
Implemented in 2.0: the modern scalar API and historical compatibility facade, with explicit validation and documented numerical corrections.
Future work: additional defuzzification methods, executable convexity queries, symmetric difference and production vectorized execution. These are outside the current scalar API.