Discrete
Discrete
¶
Bases: Term
Basic term that represents a discrete membership function.
Equation
\(\mu(x) = h\dfrac{(y_\max - y_\min)}{(x_\max - x_\min)} (x - x_\min) + y_\min\)
where
- \(h\): height of the Term
- \(x_{\min}, x_{\max}\): lower and upper bounds of \(x\), respectively
- \(y_{\min}, y_{\max}\): membership function values \(\mu(x_{\min})\) and \(\mu(x_{\max})\), respectively
related
Warning
The pairs of values in any Discrete term must be sorted in ascending order by the \(x\) coordinate because the membership function is computed using binary search to find the lower and upper bounds of \(x\).
Attributes¶
Functions¶
__init__
¶
__init__(name: str = '', values: ScalarArray | Sequence[Floatable] | None = None, height: float = 1.0) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the term |
''
|
values |
ScalarArray | Sequence[Floatable] | None
|
2D array of \((x,y)\) pairs |
None
|
height |
float
|
height of the term. |
1.0
|
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
str
|
|
required |
create
staticmethod
¶
create(
name: str,
xy: str | Sequence[Floatable] | tuple[Sequence[Floatable], Sequence[Floatable]] | dict[Floatable, Floatable],
height: float = 1.0,
) -> Discrete
Create a discrete term from the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the term |
required |
xy |
str | Sequence[Floatable] | tuple[Sequence[Floatable], Sequence[Floatable]] | dict[Floatable, Floatable]
|
coordinates |
required |
height |
float
|
height of the term |
1.0
|
Returns:
Type | Description |
---|---|
Discrete
|
Discrete term. |
membership
¶
Compute the membership function value of \(x\).
The function uses binary search to find the lower and upper bounds of \(x\) and then linearly interpolates the membership function value between the bounds.
Warning
The pairs of values in any Discrete term must be sorted in ascending order by the \(x\) coordinate because the membership function is computed using binary search to find the lower and upper bounds of \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x) = h\dfrac{(y_\max - y_\min)}{(x_\max - x_\min)} (x - x_\min) + y_\min\) |
parameters
¶
parameters() -> str
Return the space-separated parameters of the term.
Returns:
Type | Description |
---|---|
str
|
|
to_dict
¶
to_list
¶
to_xy
staticmethod
¶
to_xy(x: Any, y: Any) -> ScalarArray
Create list of values from the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Any
|
\(x\)-coordinate(s) that can be converted into scalar(s) |
required |
y |
Any
|
\(y\)-coordinate(s) that can be converted into scalar(s) |
required |
Returns:
Type | Description |
---|---|
ScalarArray
|
array of \(n\)-rows and \(2\)-columns \((n,2)\). |
Raises:
Type | Description |
---|---|
ValueError
|
when the shapes of \(x\) and \(y\) are different. |
x
¶
x() -> ScalarArray
y
¶
y() -> ScalarArray