mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
fe0cc8dbf8
commit
a05f867d5b
|
@ -11,6 +11,7 @@ from dataclasses import dataclass
|
|||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
@dataclass
|
||||
class GaussianFuzzySet:
|
||||
"""
|
||||
|
@ -61,21 +62,30 @@ class GaussianFuzzySet:
|
|||
>>> GaussianFuzzySet("Medium", 0, 1).complement().membership(0)
|
||||
0.0
|
||||
"""
|
||||
return GaussianFuzzySet(f"¬{self.name}", self.mean, self.std_dev, is_complement=not self.is_complement)
|
||||
return GaussianFuzzySet(
|
||||
f"¬{self.name}",
|
||||
self.mean,
|
||||
self.std_dev,
|
||||
is_complement=not self.is_complement,
|
||||
)
|
||||
|
||||
def plot(self):
|
||||
"""
|
||||
Plot the membership function of the Gaussian fuzzy set.
|
||||
"""
|
||||
x = np.linspace(self.mean - 3 * self.std_dev, self.mean + 3 * self.std_dev, 1000)
|
||||
x = np.linspace(
|
||||
self.mean - 3 * self.std_dev, self.mean + 3 * self.std_dev, 1000
|
||||
)
|
||||
y = [self.membership(xi) for xi in x]
|
||||
plt.plot(x, y, label=self.name)
|
||||
plt.xlabel("x")
|
||||
plt.ylabel("Membership")
|
||||
plt.legend()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from doctest import testmod
|
||||
|
||||
testmod()
|
||||
|
||||
# Create an instance of GaussianFuzzySet
|
||||
|
@ -84,7 +94,9 @@ if __name__ == "__main__":
|
|||
# Display some membership values
|
||||
print(f"Membership at mean (25): {fuzzy_set.membership(25)}")
|
||||
print(f"Membership at 30: {fuzzy_set.membership(30)}")
|
||||
print(f"Complement Membership at mean (25): {fuzzy_set.complement().membership(25)}")
|
||||
print(
|
||||
f"Complement Membership at mean (25): {fuzzy_set.complement().membership(25)}"
|
||||
)
|
||||
|
||||
# Plot the Gaussian Fuzzy Set and its complement
|
||||
fuzzy_set.plot()
|
||||
|
|
Loading…
Reference in New Issue
Block a user