Skip to content

Commit a357f85

Browse files
committed
Fixed the bug, made a FuzzySet dataclass
1 parent 8ccf12a commit a357f85

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

fuzzy_logic/fuzzy_operations.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
3+
from dataclasses import dataclass
4+
"""
5+
By @Shreya123714
36
7+
#How fuzzy set is created using FuzzySet Class
8+
>>>me = FuzzySet("Sheru",0.4,1,0.6)
9+
>>>me.__str__()
10+
'Sheru: [0.4, 1, 0.6]'
11+
>>>me
12+
FuzzySet(name='Sheru', left_boundary=0.4, peak=1, right_boundary=0.6)
13+
>>>s = FuzzySet("Siya",0.5,1,0.7)
414
15+
#Union Operations
16+
>>>s.union(me)
17+
FuzzySet(name='Siya ∪ Sheru', left_boundary=0.4, peak=0.7, right_boundary=1.0)
18+
19+
#Intersection Operation
20+
>>>s.intersection(me)
21+
FuzzySet(name='Siya ∩ Sheru', left_boundary=0.5, peak=0.6, right_boundary=1.0)
22+
23+
#Complement Operation
24+
>>>s.complement()
25+
FuzzySet(name='¬Siya', left_boundary=0.30000000000000004, peak=0.5, right_boundary=0)
26+
"""
27+
28+
29+
@dataclass
530
class FuzzySet:
631
"""
732
A class for representing and manipulating triangular fuzzy sets.
@@ -21,22 +46,26 @@ class FuzzySet:
2146
this fuzzy set.
2247
plot(): Plot the membership function of the fuzzy set.
2348
"""
24-
25-
def __init__(
26-
self, name: str, left_boundary: float, peak: float, right_boundary: float
27-
) -> None:
28-
"""
49+
name: str
50+
left_boundary: float
51+
peak: float
52+
right_boundary: float
53+
54+
# def __init__(
55+
# self, name: str, left_boundary: float, peak: float, right_boundary: float
56+
# ) -> None:
57+
"""
2958
Initializes a triangular fuzzy set with the given parameters.
3059
Args:
3160
name (str): The name or label of the fuzzy set.
3261
left_boundary (float): The left boundary of the fuzzy set.
3362
peak (float): The peak (central) value of the fuzzy set.
3463
right_boundary (float): The right boundary of the fuzzy set.
35-
"""
36-
self.name = name # Fuzzy set name
37-
self.left_boundary = left_boundary # Left boundary
38-
self.peak = peak # Peak value
39-
self.right_boundary = right_boundary # Right boundary
64+
"""
65+
# self.name = name # Fuzzy set name
66+
# self.left_boundary = left_boundary # Left boundary
67+
# self.peak = peak # Peak value
68+
# self.right_boundary = right_boundary # Right boundary
4069

4170
def membership(self, x: float) -> float:
4271
"""

0 commit comments

Comments
 (0)