simpful documentation
simpful documentation
Index 17
i
ii
CHAPTER
ONE
Simpful is a Python library for fuzzy logic reasoning, designed to provide a simple and lightweight API, as close as
possible to natural language. This page presents detailed documentation on the classes and methods implemented in
it.
1.1 Installation
If you want to check out some examples or need more information on the usage of the library, please visit our GitHub
repository, or check our published article here.
simpful.simpful module
1
Simpful
get_rules()
Returns the rule base of the fuzzy system.
Returns a list containing the fuzzy rules as strings, in the same order they were added.
inference(terms=None, subdivisions=1000, aggregation_function=<built-in function max>, ig-
nore_errors=False, ignore_warnings=False, verbose=False)
Performs the fuzzy inference, trying to automatically choose the correct inference engine.
Parameters
• terms – list of the names of the variables on which inference must be performed. If
empty, all variables appearing in the consequent of a fuzzy rule are inferred.
• subdivisions – the number of integration steps to be performed for calculating fuzzy
set area (default: 1000).
• aggregation_function – pointer to function used to aggregate fuzzy sets during
Mamdani inference, default is max. Use Python sum function, or simpful’s probor function
for sum and probabilistic OR, respectively.
• ignore_errors – True/False, toggles the raising of errors during the inference.
• ignore_warnings – True/False, toggles the raising of warnings during the inference.
• verbose – True/False, toggles verbose mode.
Returns a dictionary, containing as keys the variables’ names and as values their numerical
inferred values.
plot_surface(variables, output, detail=40, color_map='plasma')
Plots the surface induced by the rules.
Parameters
• variables – a pair of linguistic variables for the x and y axis.
• output – the output variable to be computed.
• detail – number of subdivisions along each axis.
• color_map – the color map to be used for the plot.
Returns a matplotlib figure object.
plot_variable(var_name, outputfile='', TGT=None, element=None, highlight=None, ax=None, xs-
cale='linear')
Plots all fuzzy sets contained in a liguistic variable. Options for saving the figure and draw on a matplotlib
ax are provided.
Parameters
• var_name – string containing the name of the linguistic variable to plot.
• outputfile – string containing path and filename where the plot must be saved.
• TGT – (deprecated) show the memberships of a specific element of discourse TGT in the
figure.
• element – show the memberships of a specific element of discourse in the figure.
• highlight – string, indicating the linguistic term/fuzzy set to highlight in the plot.
• ax – a matplotlib ax where the variable will be plotted.
• xscale – default “linear”, supported scales “log”. Changes the scale of the xaxis.
simpful.fuzzy_sets module
Parameters points – a list of points to define a polygonal fuzzy sets. Each point is defined as
a list of two coordinates in the universe of discourse/membership degree space.
class simpful.fuzzy_sets.GaussianFuzzySet(mu, sigma, term)
Bases: simpful.fuzzy_sets.FuzzySet
Creates a new Gaussian fuzzy set.
Parameters
• mu – mean of the distribution.
• sigma – standard deviation of the distribution.
• term – string representing the linguistic term to be associated to the fuzzy set.
set_params(mu=None, sigma=None)
Changes parameters of the Gaussian fuzzy set.
Parameters
• mu – mean of the distribution.
• sigma – standard deviation of the distribution.
class simpful.fuzzy_sets.Gaussian_MF(mu, sigma)
Bases: simpful.fuzzy_sets.MF_object
Creates a Gaussian membership function.
Parameters
• mu – mean of the distribution.
• sigma – standard deviation of the distribution.
class simpful.fuzzy_sets.InvGaussianFuzzySet(mu, sigma, term)
Bases: simpful.fuzzy_sets.FuzzySet
Creates a new inversed Gaussian fuzzy set.
Parameters
• mu – mean of the distribution.
• sigma – standard deviation of the distribution.
• term – string representing the linguistic term to be associated to the fuzzy set.
set_params(mu=None, sigma=None)
Changes parameters of the inversed Gaussian fuzzy set.
Parameters
• mu – mean of the distribution.
• sigma – standard deviation of the distribution.
class simpful.fuzzy_sets.InvGaussian_MF(mu, sigma)
Bases: simpful.fuzzy_sets.MF_object
Creates an inversed Gaussian membership function.
Parameters
• mu – mean of the distribution.
• sigma – standard deviation of the distribution.
1 | .
| / \
| / \
0 |/ \
---------
a b c
Parameters
• a – universe of discourse coordinate of the leftmost vertex.
• b – universe of discourse coordinate of the upper vertex.
• c – universe of discourse coordinate of the rightmost vertex.
simpful.fuzzy_aggregation module
class simpful.fuzzy_aggregation.FuzzyAggregator(verbose=False)
Bases: object
Creates a new fuzzy aggregation object.
Parameters verbose – True/False, toggles verbose mode.
add_variables(*args)
Adds variables and their fuzzy sets to perform fuzzy aggregation.
Parameters *args – ‘FuzzySet’ objects, whose ‘term’ argument is the name of the variable.
aggregate(variables=None, aggregation_fun='product')
Performs fuzzy aggregation.
Parameters
• variables – list of variables names to be aggregated. If empty, all added variables are
aggregated.
• aggregation_fun – pointer to a fuzzy aggregation function or string name of an im-
plemented aggregation method. Default method is “product”. Currently implemented
methods: product, min, max, arit_mean
Returns Numerical result of the aggregation, as provided by the aggregation function.
set_variable(name, value)
Sets the numerical value of a variable to be aggregated.
Parameters
• name – name of the variables to be set.
• value – numerical value to be set.
s
simpful.fuzzy_aggregation, 12
simpful.fuzzy_sets, 7
simpful.simpful, 1
15
Simpful
D M
Mamdani_inference() (simp-
DoubleGaussian_MF (class in simpful.fuzzy_sets), 8 ful.simpful.FuzzySystem method), 2
DoubleGaussianFuzzySet (class in simp- module
ful.fuzzy_sets), 7 simpful.fuzzy_aggregation, 12
draw() (simpful.simpful.LinguisticVariable method), 6 simpful.fuzzy_sets, 7
simpful.simpful, 1
F
FuzzyAggregator (class in simp- P
ful.fuzzy_aggregation), 12 plot() (simpful.simpful.LinguisticVariable method), 6
FuzzySet (class in simpful.fuzzy_sets), 8 plot_surface() (simpful.simpful.FuzzySystem
FuzzySystem (class in simpful.simpful), 1 method), 4
plot_variable() (simpful.simpful.FuzzySystem
G method), 4
Gaussian_MF (class in simpful.fuzzy_sets), 9 probor() (in module simpful.simpful), 6
GaussianFuzzySet (class in simpful.fuzzy_sets), 9 prod() (in module simpful.simpful), 6
get_firing_strengths() (simp- produce_figure() (simpful.simpful.FuzzySystem
ful.simpful.FuzzySystem method), 3 method), 4
get_fuzzy_set() (simpful.simpful.FuzzySystem
method), 3 R
get_fuzzy_sets() (simpful.simpful.FuzzySystem replace_rule() (simpful.simpful.FuzzySystem
method), 3 method), 5
17
Simpful
S U
set_constant() (simpful.simpful.FuzzySystem UndefinedUniverseOfDiscourseError, 6
method), 5
set_crisp_output_value() (simp-
ful.simpful.FuzzySystem method), 5
set_output_function() (simp-
ful.simpful.FuzzySystem method), 5
set_params() (simpful.fuzzy_sets.CrispSet method),
7
set_params() (simp-
ful.fuzzy_sets.DoubleGaussianFuzzySet
method), 7
set_params() (simpful.fuzzy_sets.GaussianFuzzySet
method), 9
set_params() (simp-
ful.fuzzy_sets.InvGaussianFuzzySet method),
9
set_params() (simp-
ful.fuzzy_sets.InvSigmoidFuzzySet method),
10
set_params() (simpful.fuzzy_sets.SigmoidFuzzySet
method), 10
set_params() (simpful.fuzzy_sets.SingletonsSet
method), 11
set_params() (simpful.fuzzy_sets.TrapezoidFuzzySet
method), 11
set_params() (simpful.fuzzy_sets.TriangleFuzzySet
method), 12
set_points() (simpful.fuzzy_sets.FuzzySet method),
8
set_variable() (simp-
ful.fuzzy_aggregation.FuzzyAggregator
method), 13
set_variable() (simpful.simpful.FuzzySystem
method), 5
Sigmoid_MF (class in simpful.fuzzy_sets), 10
SigmoidFuzzySet (class in simpful.fuzzy_sets), 10
simpful.fuzzy_aggregation
module, 12
simpful.fuzzy_sets
module, 7
simpful.simpful
module, 1
Singletons_MF (class in simpful.fuzzy_sets), 11
SingletonsSet (class in simpful.fuzzy_sets), 10
Sugeno_inference() (simpful.simpful.FuzzySystem
method), 2
T
Trapezoidal_MF (class in simpful.fuzzy_sets), 11
TrapezoidFuzzySet (class in simpful.fuzzy_sets), 11
TriangleFuzzySet (class in simpful.fuzzy_sets), 12
Triangular_MF (class in simpful.fuzzy_sets), 12
18 Index