Many fuzzy control systems are tasked to keep a certain variable close to a specific value. For instance, the temperature for an industrial chemical process or for home heating management system might need to be kept relatively constant.
In order to do this, the system could look like this:
-
Antecednets (Inputs):
error
: How far away is the temperature from where we want it to be?delta
: How fast is the temperature changing?
-
Consequents (Outputs):
output
: How much should we adjust the temperature?
-
Fuzzy sets (Membership Functions):
- Negative Big: nb = -2
- Negative Small: ns = -1
- Zero: ze = 0
- Positive Small: ps = 1
- Positive Big: pb = 2
-
Rules:
- Negative Big: IF
error
== nb ORdelta
== nb - Negative Small: IF
error
<= ns ANDdelta
<= ps ORerror
<= ps ANDdelta
<= ns - Zero: IF
error
ANDdelta
== ze - Positive Small: IF
error
>= ps ANDdelta
>= ns ORerror
>= ns ANDdelta
>= ps - Positive Big: IF
error
== pb ORdelta
== pb
- Negative Big: IF
The system is implemented in Python and uses the scikit-fuzzy library.
To install the system, you must first install the dependencies. The dependencies are listed in the requirements.txt
file. To install the dependencies, run the following command:
pip install -r requirements.txt
To use the system, you must first create a new Python file. In this file, you must import the fuzzy_system
function from the fuzzy_system
module. You can then create a new instance of the Fuzzy System and get output predictions based on your input values.
from fuzzy_system import fuzzy_system
sim = fuzzy_system()
sim.input["error"] = -2
sim.input["delta"] = 0
print(sim.output["output"])
# Prints -1
sim.input["error"] = 2
sim.input["delta"] = 0
print(sim.output["output"])
# Prints 1
sim.input["error"] = 0
sim.input["delta"] = 0
print(sim.output["output"])
# Prints 0
Rule Negative Big:
- IF
error
== nb ANDdelta
== nb THENoutput
= nb. - IF
error
== nb ANDdelta
== ns THENoutput
= nb. - IF
error
== ns ANDdelta
== nb THENoutput
= nb.
Rule Negative Small:
- IF
error
== nb ANDdelta
== ze THENoutput
= ns. - IF
error
== nb ANDdelta
== ps THENoutput
= ns. - IF
error
== ns ANDdelta
== ns THENoutput
= ns. - IF
error
== ns ANDdelta
== ze THENoutput
= ns. - IF
error
== ze ANDdelta
== ns THENoutput
= ns. - IF
error
== ze ANDdelta
== nb THENoutput
= ns. - IF
error
== ps ANDdelta
== nb THENoutput
= ns.
Rule Zero:
- IF
error
== nb ANDdelta
== pb THENoutput
= ze. - IF
error
== ns ANDdelta
== ps THENoutput
= ze. - IF
error
== ze ANDdelta
== ze THENoutput
= ze. - IF
error
== ps ANDdelta
== ns THENoutput
= ze. - IF
error
== pb ANDdelta
== nb THENoutput
= ze.
Rule Positive Small:
- IF
error
== ns ANDdelta
== pb THENoutput
= ps. - IF
error
== ze ANDdelta
== pb THENoutput
= ps. - IF
error
== ze ANDdelta
== ps THENoutput
= ps. - IF
error
== ps ANDdelta
== ps THENoutput
= ps. - IF
error
== ps ANDdelta
== ze THENoutput
= ps. - IF
error
== pb ANDdelta
== ze THENoutput
= ps. - IF
error
== pb ANDdelta
== ns THENoutput
= ps.
Rule Positive Big:
- IF
error
== ps ANDdelta
== pb THENoutput
= pb. - IF
error
== pb ANDdelta
== ps THENoutput
= pb. - IF
error
== pb ANDdelta
== pb THENoutput
= pb.