fuzzy_set.fuzzy_set module#
- class fuzzy_set.fuzzy_set.FuzzySet(mu: dict[float, float], is_continuous: bool = True, e: tuple[float, float] = (-inf, inf))[source]#
Bases:
dictA fuzzy set is defined by a \(A = (U, \mu)\) pair, where:
\(U\) is a set called universe;
\(m: E \rightarrow [0, 1]\) is the membership function of :math:̀`A`.
The
FuzzySetclass implements a Fuzzy set \(U \subseteq \mathbb{R}\) having eithera piecewise linear membership function;
a discrete membership function.
In the
FuzzySetclass implementation, you should choose a universe as tight as possible with respect to the support of the fuzzy set you need to manipulate.Example:
>>> import matplotlib.pyplot as plt >>> from fuzzy_set import FuzzySet >>> a1 = FuzzySet( ... dict(enumerate([0, 0, 0.1, 0.2, 0.7, 1, 1, 0.7, 0.2, 0.1, 0])) ... ) >>> a1.plot(label="$a_1$", marker="x") [<matplotlib.lines.Line2D object at ...>] >>> plt.legend() <matplotlib.legend.Legend object at ...> >>> plt.grid()
- absolute_difference(other: FuzzySet) FuzzySet[source]#
Computes the absolute default difference of two fuzzy-sets.
- Parameters:
other (FuzzySet) – The right operand.
- Returns:
The default fuzzy set absolute difference.
- at(alpha: float) set[source]#
Assuming this fuzzy set is discrete, retrieves the element that matches a given arbitrary \(alpha\) value.
- Parameters:
alpha (float) – The \(alpha value, contained in the :math:`[0.0, 1.0]\) interval.
- card() float[source]#
Computes the scalar cardinality of a fuzzy set.
- Returns:
The scalar cardinality of this fuzzy set.
- concentration() FuzzySet[source]#
Computes the concentration of this fuzzy set.
- Returns:
The corresponding fuzzy set.
- core() set[source]#
Assuming this fuzzy set is discrete, computes the core of this fuzzy set, denoted by \(A^{=1}\).
- Returns:
The crisp set containing every element involved in the core.
- cut(alpha: float) set[source]#
Computes an \(\alpha\)-cut of this fuzzy set, denoted by \(A^{x \ge \alpha}\).
- Parameters:
alpha (float) – The threshold involved in the \(\alpha\)-cut.
- Returns:
The crisp set containing every element involved in the \(\alpha\)-cut.
- difference(other: FuzzySet, tnorm: callable) FuzzySet[source]#
Computes the difference of two fuzzy-sets.
- doesnt_contain(x: float) bool[source]#
Checks whether this
FuzzySetinstance doesn’t contains an element.- Parameters:
x (float) – The considered element.
- Returns:
Trueifxisn’t contained inself,Falseotherwise.
- fully_contains(x: float) bool[source]#
Checks whether this
FuzzySetinstance fully contains an element.- Parameters:
x (float) – The considered element.
- Returns:
Trueifxis fully contained inself,Falseotherwise.
- height() float[source]#
Computes the height of this fuzzy set.
- Returns:
The height of this fuzzy set.
- intersection(other: ~fuzzy_set.fuzzy_set.FuzzySet, tnorm: callable = <built-in function min>) FuzzySet[source]#
Computes the intersection of two fuzzy-sets according to an arbitrary T-norm (e.g., \(min\) ).
- is_crossover(x: float) bool[source]#
Checks whether a value is a crossover point of this fuzzy set.
- Parameters:
x (float) – A value in
self.- Returns:
Trueifxis a crossover points of this fuzzy set,Falseotherwise.
- is_disjoint(other: FuzzySet) bool[source]#
Tests whether this fuzzy set and another are disjoint.
- Parameters:
other (FuzzySet) – The fuzzy set compared to
self.- Returns:
Trueif the fuzzy sets are disjoint,Falseotherwise.
- is_empty() bool[source]#
Assuming this fuzzy set is discrete, checks whether this fuzzy set is empty.
- Returns:
Trueif this fuzzy set is empty,Falseotherwise.
- is_normalized() bool[source]#
Tests whether this fuzzy set is normalized.
- Returns:
Trueif this fuzzy set is normalized,Falseotherwise.
- m(x: float) float[source]#
Retrieves the membership degrees of an element.
If this
FuzzySetinstance is continuous, (i.e., if self.is_continuous), the value use obtained using a linear interpolation.- Parameters:
x (float) – The considered element.
- Returns:
The membership value corresponding to x.
- partially_contains(x: float) bool[source]#
Checks whether this
FuzzySetinstance partially contains an element.- Parameters:
x (float) – The considered element.
- Returns:
Trueifxis partially contained inself,Falseotherwise.
- plot(*cls, ax: Axes = None, **kwargs) PathCollection[source]#
Plots this Fuzzy Set.
- Parameters:
cls – See the
plt.plot()function.args – See the
plt.plot()function.ax (matplotlib.axes.Axes) – The axes of the figure where this
FuzzySetinstance must be plotted. Pass None if not needed.
- Returns:
The resulting corresponding plot.
- relative_card(other: FuzzySet = None) float[source]#
Computes the relative cardinality of this fuzzy set or the intersection of two fuzzy set.
- Parameters:
g (FuzzySet) – Another fuzzy set. Pass
Noneorselfis equivalent.- Returns:
The relative cardinality of this fuzzy set.
- strong_cut(alpha: float) set[source]#
Assuming this fuzzy set is discrete, computes a strong \(\alpha\)-cut of this fuzzy set, denoted by \(A^{x \gt \alpha}\).
- Parameters:
alpha (float) – The \(alpha value, contained in the :math:`[0.0, 1.0]\) interval.
- Returns:
The crisp set containing every element involved in the \(\alpha\)-cut.
- support() set[source]#
Assuming this fuzzy set is discrete, computes the support of this fuzzy set, denoted by \(A^{>0}\).
- Returns:
The crisp set containing every element involved in the support.
- fuzzy_set.fuzzy_set.INFINITY = inf#
Infinity (\(\infty\))
- fuzzy_set.fuzzy_set.REALS = (-inf, inf)#
The set of real numbers (\(\mathbb{R}`\))