fuzzy_set.fuzzy_number module#

class fuzzy_set.fuzzy_number.FuzzyNumber(mu: dict[float, float])[source]#

Bases: FuzzySet

A Fuzzy Number (FN) is Fuzzy Set \(A = (U, \mu)\) such that:

  • \(U = \mathbb{R}\);

  • \(\mu\) is a \(\mathbb{R}\) is a piecewise continuous function;

  • \(\mu\) is convex;

  • \(\mu\) is normalized (i.e., \(\mu(\mathbb{R}) = [0, 1]\)).

As such, a fuzzy number models a fuzzy interval of real numbers.

The FuzzySet class assumes a discrete Fuzzy Set. Therefore, the FuzzyNumber takes a list of \({(x_1, y_1), ..., (x_n, y_n)}\) points enough to describe \(\mu\) such that:

  • \(x_1 \le ... \le x_n\);

  • \(\mu(x_1) = 0\) and \(\mu(x_n) = 0\);

  • \(\forall x \le x_1 = 0\);

  • \(\forall x \ge x_n = 0\);

  • for all \(i \in \{1, ..., n-1\}\), for all \(x \in [x_i, x_{i+1}]\), \(\mu\) matches the linear function that traverses \((x_i, y_i)\) and \((x_{i+1}, y_{i+1})\).

Example:

>>> import matplotlib.pyplot as plt
>>> from fuzzy_set import FuzzyNumber
>>> a1 = FuzzyNumber(dict(
...     enumerate([0, 0.6, 0.8, 1, 1, 0.9, 0.75, 0.4, 0]))
... )
>>> a1.plot(label="$a_1$", marker=".", with_xis=False, with_ei=True)
<matplotlib.collections.PathCollection object at ...>
>>> plt.legend()
<matplotlib.legend.Legend object at ...>
>>> plt.grid()
core() tuple[source]#

Computes the core of this fuzzy number, denoted by \(A^{=1}\).

Returns:

The interval of reals corresponding to the core of this fuzzy number.

ei() tuple[source]#

Computes the Expected Interval, formally defined by: \(\text{EI}(A) = [\text{EI}_L(A), \text{EI}_U(A)]\).

See also the FuzzyNumber.ei_l(), FuzzyNumber.ei_u(), FuzzyNumber.ev() methods.

Returns:

The Expected Interval.

ei_l() float[source]#

Computes the Expected Interval Lower Bound, formally defined by: \(\text{EI}_L(A) = \int_{0}^1 A_L(\alpha).d\alpha\) where: \(A_L(\alpha) = \inf({x \in \mathbb{R} : \mu_A(x) \ge \alpha})\)

Intuitively, \(\text{EI}_L(A)\) is the \(\ell \in \mathbb{R}\) value such that \(\mu_A(\ell)\) equals average value of the left arm of this Fuzzy Number.

Returns:

The Expected Interval Lower Bound.

ei_u() float[source]#

Computes the Expected Interval Upper Bound, formally defined by: \(\text{EI}_L(A) = \int_{0}^1 A_U(\alpha).d\alpha\). where: \(A_U(\alpha) = \sup({x \in \mathbb{R} : \mu_A(x) \ge \alpha})\)

Intuitively, \(\text{EI}_L(A)\) is the \(r \in \mathbb{R}\) value such that \(\mu_A(r)\) equals average value of the right arm of this Fuzzy Number.

Returns:

The Expected Interval Upper Bound.

ev(q: float = 0.5) float[source]#

Computes the (Weighed) Expected Value of this fuzzy number, formally defined as the middle of the Expected Interval: \(\text{EV}(A) = q \cdot \text{EI}_L(A) + (1 - q) \cdot \text{EI}_U(A)\)

See also the FuzzyNumber.ei_l(), FuzzyNumber.ei_u(), FuzzyNumber.ei() methods.

Parameters:

q (float) – A value in \([0, 1]\). Default to 0.5.

Returns:

The weighted expected value of this fuzzy number.

plot(*args, ax=None, with_xis: bool = False, with_ei: bool = False, **kwargs) PathCollection[source]#

Plots this Fuzzy Number.

Parameters:
  • cls – See the plt.plot() function.

  • args – See the plt.plot() function.

  • ax (matplotlib.axes.Axes) – The axes of the figure where this FuzzySet instance must be plotted. Pass None if not needed.

  • with_xis (bool) –

    Pass True to display the support and the core of this Fuzzy Number. See also:

Returns:

The resulting corresponding plot.

support() tuple[source]#

Computes the support of this fuzzy number, denoted by \(A^{>0}\).

Returns:

The interval of reals corresponding to the support of this fuzzy number.

width() float[source]#

Computes the width of this fuzzy number, formally defined as the middle of the Expected Interval: \(\text{w}(A) = \text{EI}_U(A) - \text{EI}_L(A))\)

See also the FuzzyNumber.ei_l(), FuzzyNumber.ei_u(), FuzzyNumber.ei() methods.

Returns:

The width of this fuzzy number.