-
-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Add FuzzySet Class for Triangular Fuzzy Sets #11036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
bb8f7f7
48f246d
5e1dfe6
6d751f8
e778cb3
abe9361
c51022b
cb77a2a
5486668
231b33e
798e78f
a7b7a91
c6022c2
1183dd9
ee0a7c0
de13593
cacc1d1
472e739
5565063
d2cdcb8
d091358
0db5402
70c3787
81340cd
26cf8e7
54a3a42
f0f581a
8a01993
14410df
10bc341
3ff4ec9
06db239
4e9ded8
8ccf12a
a357f85
d961a50
050debb
ae179fa
f3ae7ed
d9a8c65
faed044
2b1cef8
2dd8521
c343a09
16a712a
005f852
dc849bd
8c8b200
cec6c1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,161 @@ | ||||||||||
| import matplotlib.pyplot as plt | ||||||||||
| import numpy as np | ||||||||||
|
|
||||||||||
| """" | ||||||||||
| FuzzySet class for triangular fuzzy sets | ||||||||||
| Author: Shreya123714 | ||||||||||
| Source: https://en.wikipedia.org/wiki/Fuzzy_set | ||||||||||
| """ | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class FuzzySet: | ||||||||||
| """ | ||||||||||
| A class for representing and | ||||||||||
| manipulating triangular fuzzy sets. | ||||||||||
|
|
||||||||||
| Attributes: | ||||||||||
| name (str): The name or label of the fuzzy set. | ||||||||||
| a (float): The left boundary of the fuzzy set. | ||||||||||
| b (float): The peak (central) value of the fuzzy set. | ||||||||||
| c (float): The right boundary of the fuzzy set. | ||||||||||
|
|
||||||||||
| Methods: | ||||||||||
| membership(x): Calculate the membership value | ||||||||||
| of an input 'x' in the fuzzy set. | ||||||||||
| union(other): Calculate the union of this fuzzy set | ||||||||||
| with another fuzzy set. | ||||||||||
| intersection(other): Calculate the intersection of this fuzzy set | ||||||||||
| with another fuzzy set. | ||||||||||
| complement(): Calculate the complement (negation) | ||||||||||
| of this fuzzy set. | ||||||||||
| plot(): Plot the membership function of the fuzzy set. | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| def __init__(self, name: str, left_boundary: float, peak: float, right_boundary: float) -> None: | ||||||||||
| """ | ||||||||||
| Initializes a triangular fuzzy set | ||||||||||
| with the given parameters. | ||||||||||
|
|
||||||||||
| Args: | ||||||||||
| name (str): The name or label of the fuzzy set. | ||||||||||
| a (float): The left boundary of the fuzzy set. | ||||||||||
| b (float): The peak (central) value of | ||||||||||
| the fuzzy set. | ||||||||||
| c (float): The right boundary of the fuzzy set. | ||||||||||
| """ | ||||||||||
| self.name = name # Fuzzy set name | ||||||||||
| self.left_boundary = left_boundary # Left boundary | ||||||||||
| self.peak = peak # Peak value | ||||||||||
| self.right_boundary = right_boundary # Right boundary | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def membership(self, x): | ||||||||||
|
||||||||||
| def membership(self, x): | |
| def membership(self, value: FuzzySet) -> float: |
cclauss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function membership
Please provide return type hint for the function: membership. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: membership. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: x
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def union(self, other): | |
| def union(self, other: FuzzySet) -> FuzzySet: |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function union
Please provide return type hint for the function: union. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function union
Please provide return type hint for the function: union. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: union. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
cclauss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function intersection
Please provide return type hint for the function: intersection. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: intersection. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
cclauss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function complement
Please provide return type hint for the function: complement. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: complement. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All methods should have at least one doctest.
| """ | |
| >>> FuzzySet("test", 10, 20, 30).complement() | |
| '¬test: [-30, -10, -20]' | |
| """ |
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function plot
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function plot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function plot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function plot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: plot. If the function does not return a value, please provide the type hint as: def function() -> None:
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function __str__
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function __str__
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function __str__
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function __str__
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file fuzzy_logic/fuzzy_operations.py, please provide doctest for the function __str__
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __str__. If the function does not return a value, please provide the type hint as: def function() -> None:
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| A = FuzzySet("A", 0, 0.5, 1) | |
| B = FuzzySet("B", 0.2, 0.7, 1) | |
| fuzzy_set_a = FuzzySet("A", 0, 0.5, 1) | |
| fuzzy_set_b = FuzzySet("B", 0.2, 0.7, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this a https://docs.python.org/3/library/dataclasses.html