A Python implementation of a Fuzzy Logic inference engine, originally ported from the C# code accompanying the book L'Intelligence Artificielle pour les développeurs - Concepts et implémentations en C# by Virginie Mathivet (Editions ENI).
You can install this library directly from GitHub using pip:
pip install git+https://github.com/gregory-chatelier/fuzzy-logic.gitOr, if you have cloned the repository:
pip install .from fuzzy_system.fuzzy_system import FuzzySystem
from fuzzy_system.linguistic_variable import LinguisticVariable
from fuzzy_system.linguistic_value import LinguisticValue
from fuzzy_system.fuzzy_sets.left_fuzzy_set import LeftFuzzySet
from fuzzy_system.fuzzy_sets.trapezoidal_fuzzy_set import TrapezoidalFuzzySet
from fuzzy_system.fuzzy_sets.right_fuzzy_set import RightFuzzySet
# 1. Create System
system = FuzzySystem("Blinds Control")
# 2. Define Input Variables
# Temperature: 0-35 degrees
temp = LinguisticVariable("Temperature", 0, 35)
temp.add_value(LinguisticValue("Cold", LeftFuzzySet(0, 35, 10, 12)))
temp.add_value(LinguisticValue("Fresh", TrapezoidalFuzzySet(0, 35, 10, 12, 15, 17)))
temp.add_value(LinguisticValue("Good", TrapezoidalFuzzySet(0, 35, 15, 17, 20, 25)))
temp.add_value(LinguisticValue("Hot", RightFuzzySet(0, 35, 20, 25)))
system.add_input_variable(temp)
# ... (Add more variables and rules) ...
# 3. Solve
# system.set_input_variable(temp, 21)
# result = system.solve()See the examples/ directory for complete working scripts.
This library was created primarily for educational purposes and to port specific logic from the referenced book. If you are looking for a robust, actively maintained fuzzy logic library for production use in Python, consider these established alternatives:
- scikit-fuzzy: The standard fuzzy logic toolkit for SciPy.
- Simpful: A user-friendly and lightweight library for fuzzy logic.
- pyfuzzylite: A comprehensive fuzzy logic control library.
src/fuzzy_system: Core library code.examples/: Example scripts (example_app1.py,example_app2.py) and plotting scripts.tests/: Unit tests.
This project uses pytest.
pip install pytest
pytestThis project is licensed under the MIT License - see the LICENSE file for details.