fuzzy_set.trapezoidal_fuzzy_number module#
- class fuzzy_set.trapezoidal_fuzzy_number.TrapezoidalFuzzyNumber(x1: float, x2: float, x3: float, x4: float)[source]#
Bases:
FuzzyNumberA Trapezoidal Fuzzy Number (TFN) is a Fuzzy Number (FN) which is piecewise linear and continuous. Thus, it has a trapezoidal shape. As a consequence, a TFN is fully characterized by a quadruple of real numbers, denoted by \([x_1, x_2, x_3, x_4]\), where:
\(x_1 \le ... \le x_4\);
\([x_1, x_4]\) is the support of the TFN;
\([x_2, x_3]\) is the core of the TFN.
Trapezoidal Fuzzy Numbers support arithmetic operators, i.e., +, -, *, /. See Reliability Range Through Upgraded Operation with TFN.
Example:
>>> from fuzzy_set import TrapezoidalFuzzyNumber >>> t1 = TrapezoidalFuzzyNumber(1, 3, 8, 10) >>> t2 = TrapezoidalFuzzyNumber(2, 5, 7, 8) >>> t1 + t2 TrapezoidalFuzzyNumber<(3, 8, 15, 18)> >>> t1 - t2 TrapezoidalFuzzyNumber<(-7, -4, 3, 8)> >>> t1 * t2 TrapezoidalFuzzyNumber<(2, 15, 56, 80)> >>> t1 / t2 TrapezoidalFuzzyNumber<(0.125, 0.42857142857142855, 1.6, 5.0)>
Example:
import matplotlib.pyplot as plt from operator import __add__, __sub__, __mul__, __truediv__ (fig, axs) = plt.subplots(2, 2) for (ij, (op, opname)) in { (0, 0): (__add__, "+"), (0, 1): (__sub__, "-"), (1, 0): (__mul__, "\cdot"), (1, 1): (__truediv__, "/"), }.items(): ax = axs[ij] title = f"$a_1 {opname} a_2$" ax.set_title(title) t1.plot(ax=ax, label="$a_1$") t2.plot(ax=ax, label="$a_2$") op(t1, t2).plot(ax=axs[ij], label=title) ax.grid() ax.legend() ax.legend(bbox_to_anchor=(1, 0.5), loc="center left") plt.tight_layout()