Skip to content
Marco S. Nobile edited this page Feb 26, 2020 · 7 revisions

What is simpful

Simpful is a lightweight python library for fuzzy reasoning based on the Takagi-Sugeno inference system.

Installing Simpful

Simpful can be installed with pip:

pip install simpful

Using Simpful

The first step is to import Simpful and create a FuzzySystem object:

from simpful import *
...
FuzzySys = FuzzySystem()

Then, the fuzzy sets must be created using Simpful's FuzzySet objects. Fuzzy sets can be specified using a list of vertices, i.e., pairs (u, m(u)) where u is an element of the universe of discourse, and m(u) is the membership degree of u to the fuzzy set. The user must also specify a linguistic term associated to the fuzzy set. For instance, a trapezoidal fuzzy set can be specified as follows:

FS_1 = FuzzySet( points=[[0, 1.],  [1., 1.],  [1.5, 0]], term="low" );

Alternatively, fuzzy sets can be specified using pre-baked functions (i.e., Gaussian, inverted Gaussian, double Gaussian, Sigmoid, inverted Sigmoid). For instance, a Gaussian fuzzy set with mu=0 and sigma=1 can be specified as follows:

FS_2 = FuzzySet( function=Gaussian_MF(0, 1), term="high" );

The user can also specify fuzzy sets using a custom function. In order to do so, the user must re-implement the evaluate() method of Simpful's MF_object.

Once all fuzzy sets related to a specific linguistic variable are defined, they must be aggregated into a single linguistic variable as follows:

LV_1 = LinguisticVariable([FS_1, FS_2])

Finally, the linguistic variable must be added to the FuzzySystem, by specifying a specific term that will be used in fuzzy rule:

FuzzySys.add_linguistic_variable( "specificterm", LV_1 )

Now, the fuzzy reasoner can exploit the term to build rules. For instance, we can specify the following rules:

RULE_1 = "IF specificterm IS high THEN (consequent IS high_cons)"
RULE_2 = "IF specificterm IS low THEN (consequent IS low_cons)"

Please note that the keywords "IF", "IS" and "THEN" must be capitalized.

The information about consequents for the Takagi-Sugeno inference can be specified using crisp output values (i.e., 0-order systems) or custom functions (i.e., first- or higher order systems). For instance:

FuzzySys.set_crisp_output_value("low_cons", 0)
FuzzySys.set_output_function("high_cons", "specificterm**2")

When all rules are prepared, they can be added to the FuzzySystem by using the add_rules() method, e.g.:

FuzzySys.add_rules([RULE_1, RULE_2])

Now, the fuzzy system is ready for inference: we can specify the input values of the antecedents and perform the reasoning over a list of consequent variables:

FuzzySys.set_variable("specificterm", 1)
result = FuzzySys.Sugeno_inference(["consequent"])

Plotting and optional arguments

In order to exploit the plotting facilities, some additional arguments can be used. For instance, it is possible to specify the universe of discourse of a LinguisticVariable:

FuzzySys.add_linguistic_variable( "specificterm", LV_1, universe_of_discourse=[-100, 100] )

A figure summarizing all linguistic variables of the system can be plotted to a file by using the produce_figure() method of FuzzySystem:

FuzzySys.produce_figure("filename.pdf")
Clone this wiki locally