A class for representing and manipulating triangular fuzzy sets. Attributes: name: The name or label of the fuzzy set. left_boundary: The left boundary of the fuzzy set. peak: The peak (central) value of the fuzzy set. right_boundary: The right boundary of th
| 14 | |
| 15 | @dataclass |
| 16 | class FuzzySet: |
| 17 | """ |
| 18 | A class for representing and manipulating triangular fuzzy sets. |
| 19 | Attributes: |
| 20 | name: The name or label of the fuzzy set. |
| 21 | left_boundary: The left boundary of the fuzzy set. |
| 22 | peak: The peak (central) value of the fuzzy set. |
| 23 | right_boundary: The right boundary of the fuzzy set. |
| 24 | Methods: |
| 25 | membership(x): Calculate the membership value of an input 'x' in the fuzzy set. |
| 26 | union(other): Calculate the union of this fuzzy set with another fuzzy set. |
| 27 | intersection(other): Calculate the intersection of this fuzzy set with another. |
| 28 | complement(): Calculate the complement (negation) of this fuzzy set. |
| 29 | plot(): Plot the membership function of the fuzzy set. |
| 30 | |
| 31 | >>> sheru = FuzzySet("Sheru", 0.4, 1, 0.6) |
| 32 | >>> sheru |
| 33 | FuzzySet(name='Sheru', left_boundary=0.4, peak=1, right_boundary=0.6) |
| 34 | >>> str(sheru) |
| 35 | 'Sheru: [0.4, 1, 0.6]' |
| 36 | |
| 37 | >>> siya = FuzzySet("Siya", 0.5, 1, 0.7) |
| 38 | >>> siya |
| 39 | FuzzySet(name='Siya', left_boundary=0.5, peak=1, right_boundary=0.7) |
| 40 | |
| 41 | # Complement Operation |
| 42 | >>> sheru.complement() |
| 43 | FuzzySet(name='¬Sheru', left_boundary=0.4, peak=0.6, right_boundary=0) |
| 44 | >>> siya.complement() # doctest: +NORMALIZE_WHITESPACE |
| 45 | FuzzySet(name='¬Siya', left_boundary=0.30000000000000004, peak=0.5, |
| 46 | right_boundary=0) |
| 47 | |
| 48 | # Intersection Operation |
| 49 | >>> siya.intersection(sheru) |
| 50 | FuzzySet(name='Siya ∩ Sheru', left_boundary=0.5, peak=0.6, right_boundary=1.0) |
| 51 | |
| 52 | # Membership Operation |
| 53 | >>> sheru.membership(0.5) |
| 54 | 0.16666666666666663 |
| 55 | >>> sheru.membership(0.6) |
| 56 | 0.0 |
| 57 | |
| 58 | # Union Operations |
| 59 | >>> siya.union(sheru) |
| 60 | FuzzySet(name='Siya U Sheru', left_boundary=0.4, peak=0.7, right_boundary=1.0) |
| 61 | """ |
| 62 | |
| 63 | name: str |
| 64 | left_boundary: float |
| 65 | peak: float |
| 66 | right_boundary: float |
| 67 | |
| 68 | def __str__(self) -> str: |
| 69 | """ |
| 70 | >>> FuzzySet("fuzzy_set", 0.1, 0.2, 0.3) |
| 71 | FuzzySet(name='fuzzy_set', left_boundary=0.1, peak=0.2, right_boundary=0.3) |
| 72 | """ |
| 73 | return ( |
no outgoing calls
no test coverage detected