MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / membership

Method membership

fuzzy_logic/fuzzy_operations.py:112–139  ·  view source on GitHub ↗

Calculate the membership value of an input 'x' in the fuzzy set. Returns: The membership value of 'x' in the fuzzy set. >>> a = FuzzySet("a", 0.1, 0.2, 0.3) >>> a.membership(0.09) 0.0 >>> a.membership(0.1) 0.0 >>> a.member

(self, x: float)

Source from the content-addressed store, hash-verified

110 )
111
112 def membership(self, x: float) -> float:
113 """
114 Calculate the membership value of an input 'x' in the fuzzy set.
115 Returns:
116 The membership value of 'x' in the fuzzy set.
117
118 >>> a = FuzzySet("a", 0.1, 0.2, 0.3)
119 >>> a.membership(0.09)
120 0.0
121 >>> a.membership(0.1)
122 0.0
123 >>> a.membership(0.11)
124 0.09999999999999995
125 >>> a.membership(0.4)
126 0.0
127 >>> FuzzySet("A", 0, 0.5, 1).membership(0.1)
128 0.2
129 >>> FuzzySet("B", 0.2, 0.7, 1).membership(0.6)
130 0.8
131 """
132 if x <= self.left_boundary or x >= self.right_boundary:
133 return 0.0
134 elif self.left_boundary < x <= self.peak:
135 return (x - self.left_boundary) / (self.peak - self.left_boundary)
136 elif self.peak < x < self.right_boundary:
137 return (self.right_boundary - x) / (self.right_boundary - self.peak)
138 msg = f"Invalid value {x} for fuzzy set {self}"
139 raise ValueError(msg)
140
141 def union(self, other) -> FuzzySet:
142 """

Callers 1

plotMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected