1111import numpy as np
1212import matplotlib .pyplot as plt
1313
14+
1415@dataclass
1516class GaussianFuzzySet :
1617 """
1718 A class for representing and manipulating Gaussian fuzzy sets.
18-
19+
1920 Attributes:
2021 name: The name or label of the fuzzy set.
2122 mean: The mean value (center) of the Gaussian fuzzy set.
@@ -26,7 +27,7 @@ class GaussianFuzzySet:
2627 membership(x): Calculate the membership value of an input 'x' in the fuzzy set.
2728 complement(): Create a new GaussianFuzzySet instance representing the complement.
2829 plot(): Plot the membership function of the fuzzy set.
29-
30+
3031 >>> fuzzy_set = GaussianFuzzySet("Medium Temperature", mean=25, std_dev=5)
3132 >>> fuzzy_set.membership(25)
3233 1.0
@@ -45,7 +46,7 @@ def membership(self, x: float) -> float:
4546 """
4647 Calculate the membership value of an input 'x' in the Gaussian fuzzy set.
4748 If it's a complement set, returns 1 - the Gaussian membership.
48-
49+
4950 >>> GaussianFuzzySet("Medium", 0, 1).membership(0)
5051 1.0
5152 >>> GaussianFuzzySet("Medium", 0, 1).membership(1)
@@ -57,25 +58,34 @@ def membership(self, x: float) -> float:
5758 def complement (self ) -> GaussianFuzzySet :
5859 """
5960 Create a new GaussianFuzzySet instance representing the complement.
60-
61+
6162 >>> GaussianFuzzySet("Medium", 0, 1).complement().membership(0)
6263 0.0
6364 """
64- return GaussianFuzzySet (f"¬{ self .name } " , self .mean , self .std_dev , is_complement = not self .is_complement )
65+ return GaussianFuzzySet (
66+ f"¬{ self .name } " ,
67+ self .mean ,
68+ self .std_dev ,
69+ is_complement = not self .is_complement ,
70+ )
6571
6672 def plot (self ):
6773 """
6874 Plot the membership function of the Gaussian fuzzy set.
6975 """
70- x = np .linspace (self .mean - 3 * self .std_dev , self .mean + 3 * self .std_dev , 1000 )
76+ x = np .linspace (
77+ self .mean - 3 * self .std_dev , self .mean + 3 * self .std_dev , 1000
78+ )
7179 y = [self .membership (xi ) for xi in x ]
7280 plt .plot (x , y , label = self .name )
7381 plt .xlabel ("x" )
7482 plt .ylabel ("Membership" )
7583 plt .legend ()
7684
85+
7786if __name__ == "__main__" :
7887 from doctest import testmod
88+
7989 testmod ()
8090
8191 # Create an instance of GaussianFuzzySet
@@ -84,7 +94,9 @@ def plot(self):
8494 # Display some membership values
8595 print (f"Membership at mean (25): { fuzzy_set .membership (25 )} " )
8696 print (f"Membership at 30: { fuzzy_set .membership (30 )} " )
87- print (f"Complement Membership at mean (25): { fuzzy_set .complement ().membership (25 )} " )
97+ print (
98+ f"Complement Membership at mean (25): { fuzzy_set .complement ().membership (25 )} "
99+ )
88100
89101 # Plot the Gaussian Fuzzy Set and its complement
90102 fuzzy_set .plot ()
0 commit comments