Term
Activated
¶
Bases: Term
Special term that represents the activation of terms when processing the antecedent of a rule.
Equation
\(\mu(x) = \alpha_a \otimes \mu_a(x)\)
where
- \(\alpha_a\): activation degree of term \(a\)
- \(\otimes\): implication operator
- \(\mu_a\): activated term \(a\)
related
Attributes¶
degree
property
writable
¶
degree: Scalar
Get/Set the activation degree of the term.
Getter¶
Returns:
Type | Description |
---|---|
Scalar
|
activation degree of the term. |
Setter¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Scalar
|
activation degree of the term, with replacements of |
required |
Note
replacements of {nan: 0.0, -inf: 0.0, inf: 1.0}
are made to sensibly deal with non-finite activations (eg, NaN
input values)
Functions¶
__init__
¶
__repr__
¶
__repr__() -> str
Return the code to construct the term in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in Python. |
fuzzy_value
¶
membership
¶
Aggregated
¶
Bases: Term
Special term that represents a fuzzy set of activated terms to mainly serve as the fuzzy output value of output variables.
Equation
\(\mu(x)=\bigoplus_i^n\alpha_i\otimes\mu_i(x) = \alpha_1\otimes\mu_1(x) \oplus \ldots \oplus \alpha_n\otimes\mu_n(x)\)
where
- \(\alpha_i\): activation degree of term \(i\)
- \(\mu_i\): membership function of term \(i\)
- \(\otimes\): implication operator
- \(\oplus\): aggregation operator
related
Attributes¶
Functions¶
__init__
¶
__init__(
name: str = "",
minimum: float = nan,
maximum: float = nan,
aggregation: SNorm | None = None,
terms: Iterable[Activated] | None = None,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the aggregated term |
''
|
minimum
|
float
|
minimum value of the range of the fuzzy set |
nan
|
maximum
|
float
|
maximum value of the range of the fuzzy set |
nan
|
aggregation
|
SNorm | None
|
aggregation operator |
None
|
terms
|
Iterable[Activated] | None
|
list of activated terms |
None
|
__repr__
¶
__repr__() -> str
Return the code to construct the term in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in Python. |
activation_degree
¶
grouped_terms
¶
highest_activated_term
¶
highest_activated_term() -> Activated | None
Find the term with the maximum aggregated activation degree.
Returns:
Type | Description |
---|---|
Activated | None
|
term with the maximum aggregated activation degree. |
Raises:
Type | Description |
---|---|
ValueError
|
when working with vectorization (eg, size(activation_degree) > 1) |
membership
¶
Aggregate the activated terms' membership function values of \(x\) using the aggregation operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x)=\bigoplus_i^n\alpha_i\otimes\mu_i(x) = \alpha_1\otimes\mu_1(x) \oplus \ldots \oplus \alpha_n\otimes\mu_n(x)\) |
Arc
¶
Bases: Term
Edge term that represents the arc-shaped membership function.
Equation
\(\mu(x)=\dfrac{h\sqrt{r^2 - (x-c)^2}}{|r|}\)
where
- \(h\): height of the Term
- \(r\): radius of the Arc
- \(c\): center of the Arc
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
tsukamoto
¶
Compute the tsukamoto value of the monotonic term for activation degree \(y\).
Equation
\(y=\dfrac{h\sqrt{r^2 - (x-c)^2}}{|r|}\)
\(x=c\pm \sqrt{r^2-\dfrac{yr}{h}}\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Scalar
|
activation degree |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(x=c\pm \sqrt{r^2-\dfrac{yr}{h}}\) |
Bell
¶
Bases: Term
Extended term that represents the generalized bell curve membership function.
Equation
\(\mu(x)=\dfrac{h}{1 + \left(\dfrac{|x-c|}{w}\right)^{2s}}\)
where
- \(h\): height of the Term
- \(c\): center of the Bell
- \(w\): width of the Bell
- \(s\): slope of the Bell
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Binary
¶
Bases: Term
Edge Term that represents the binary membership function.
Equation
\(\mu(x) = \begin{cases} h & \mbox{if } (d=\infty \wedge x \ge s) \vee (d=-\infty \wedge x \le s) \cr 0 & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(s\): start of the Binary
- \(d\): direction of the Binary
Concave
¶
Bases: Term
Edge Term that represents the concave membership function.
Equation
\(\mu(x) = \begin{cases} h \dfrac{e - i} {2e - i - x} & \mbox{if } i \leq e \wedge x < e \mbox{ (increasing concave)} \cr h \dfrac{i - e} {-2e + i + x} & \mbox{if } i > e \wedge x > e \mbox{ (decreasing concave)} \cr h & \mbox{otherwise} \cr \end{cases}\)
where
- \(h\): height of the Term
- \(i\): inflection of the Concave
- \(e\): end of the Concave
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Compute the membership function value of \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x) = \begin{cases} h \dfrac{e - i} {2e - i - x} & \mbox{if } i \leq e \wedge x < e \mbox{ (increasing concave)} \cr h \dfrac{i - e} {-2e + i + x} & \mbox{if } i > e \wedge x > e \mbox{ (decreasing concave)} \cr h & \mbox{otherwise} \cr \end{cases}\) |
tsukamoto
¶
Compute the tsukamoto value of the monotonic term for activation degree \(y\).
Equation
\(y = h \dfrac{e - i} {2e - i - x}\)
\(x = h \dfrac{e-i}{y} + 2e -i\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Scalar
|
activation degree |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(x = h \dfrac{e-i}{y} + 2e -i\) |
Constant
¶
Bases: Term
Zero polynomial term \(k\) that represents a constant value.
Equation
\(\mu(x) = k\)
where
- \(k\): value of the Constant
Attributes¶
Functions¶
__init__
¶
__repr__
¶
__repr__() -> str
Return the code to construct the term in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in Python. |
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Cosine
¶
Bases: Term
Extended term that represents the cosine membership function.
Equation
\(\mu(x) = \begin{cases} \dfrac{h}{2} \left(1 + \cos\left(\dfrac{2.0}{w}\pi(x-c)\right)\right) & \mbox{if } c - \dfrac{w}{2} \le x \le c + \dfrac{w}{2} \cr 0 & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(c\): center of the Cosine
- \(w\): width of the Cosine
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Compute the membership function value of \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x) = \begin{cases} \dfrac{h}{2} \left(1 + \cos\left(\dfrac{2.0}{w}\pi(x-c)\right)\right) & \mbox{if } c - \dfrac{w}{2} \le x \le c + \dfrac{w}{2} \cr 0 & \mbox{otherwise} \end{cases}\) |
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
Function
¶
Bases: Term
Polynomial term that represents a generic function.
Equation
\(f : x \mapsto f(x)\)
The function term is also used to convert the text of the antecedent of a rule from infix to postfix notation.
related
Attributes¶
Classes¶
Element
¶
Representation of a single element in a formula: either a function or an operator.
If the Element represents a function, its parameter is the arity of the function (only unary or binary supported)
If the Element represents an operator, its parameters are: arity
, precedence
, and associativity
.
Attributes¶
Classes¶
Functions¶
__init__
¶
__init__(
name: str,
description: str,
type: Type | str,
method: Callable[..., Scalar],
arity: int = 0,
precedence: int = 0,
associativity: int = -1,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the element |
required |
description
|
str
|
description of the element |
required |
type
|
Type | str
|
type of the element |
required |
method
|
Callable[..., Scalar]
|
reference to the function (only supports unary or binary) |
required |
arity
|
int
|
number of operands required |
0
|
precedence
|
int
|
precedence of operators, where higher precedence comes first (see Order of operations) |
0
|
associativity
|
int
|
precedence of grouping operators in the absence of parentheses (see Operator associativity) |
-1
|
__repr__
¶
__repr__() -> str
Return the code to construct the element in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the element in Python. |
is_function
¶
is_function() -> bool
Return whether the element is a fuzzylite.term.Function.Element.Type.Function.
Returns:
Type | Description |
---|---|
bool
|
is_operator
¶
is_operator() -> bool
Return whether the element is a fuzzylite.term.Function.Element.Type.Operator.
Returns:
Type | Description |
---|---|
bool
|
Node
¶
Basic binary tree structure.
A node can point to left and right nodes to build a binary tree.
A node can represent:
- an element (Function or Operator),
- an input or output variable by name,
- a constant floating-point value
Attributes¶
Functions¶
__init__
¶
__init__(
element: Element | None = None,
variable: str = "",
constant: float = nan,
left: Node | None = None,
right: Node | None = None,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element
|
Element | None
|
node refers to a function or an operator |
None
|
variable
|
str
|
node refers to a variable by name |
''
|
constant
|
float
|
node refers to an arbitrary floating-point value |
nan
|
right
|
Node | None
|
node has an expression tree on the right |
None
|
left
|
Node | None
|
node has an expression tree on the left. |
None
|
__repr__
¶
__repr__() -> str
Return the code to construct the node in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the node in Python. |
evaluate
¶
Recursively evaluate the node and substitute the variables with the given values (if any).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_variables
|
dict[str, Scalar] | None
|
map of substitutions of variable names for scalars |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
scalar as the result of the evaluation. |
Raises:
Type | Description |
---|---|
ValueError
|
when function arity is not met with left and right nodes |
ValueError
|
when the node represents a variable but the map does not contain its substitution value |
infix
¶
postfix
¶
prefix
¶
Functions¶
__init__
¶
__init__(
name: str = "",
formula: str = "",
engine: Engine | None = None,
variables: dict[str, Scalar] | None = None,
load: bool = False,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the term |
''
|
formula
|
str
|
formula defining the membership function |
''
|
engine
|
Engine | None
|
engine to which the Function can have access |
None
|
variables
|
dict[str, Scalar] | None
|
map of substitution variables |
None
|
load
|
bool
|
load the function on creation. |
False
|
__repr__
¶
__repr__() -> str
Return the code to construct the term in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in Python. |
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
create
staticmethod
¶
Create and configure a function term.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the term |
required |
formula
|
str
|
formula defining the membership function |
required |
engine
|
Engine | None
|
engine to which the Function can have access |
None
|
Returns:
Type | Description |
---|---|
Function
|
configured function term |
Raises:
Type | Description |
---|---|
SyntaxError
|
when the formula has a syntax error |
evaluate
¶
Evaluate the function value using the map of variable substitutions (if any).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variables
|
dict[str, Scalar] | None
|
map containing substitutions of variable names for values |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
function value using the map of variable substitutions (if any). |
Raises:
Type | Description |
---|---|
RuntimeError
|
when the function is not loaded |
format_infix
classmethod
¶
infix_to_postfix
classmethod
¶
Convert the formula to postfix notation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula
|
str
|
right-hand side of an equation expressed in infix notation |
required |
Returns:
Type | Description |
---|---|
str
|
formula in postfix notation |
Raises:
Type | Description |
---|---|
SyntaxError
|
when the formula has syntax errors. |
membership
¶
Computes the membership function evaluated at \(x\).
The value of variable x
will be added to the variables
map, and so will the current values of the input
variables and output variables if the engine has been set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(f(x)\) |
Raises:
Type | Description |
---|---|
ValueError
|
when an input or output variable is named |
ValueError
|
when the map of variables contain names of input or output variables |
parse
classmethod
¶
Create a node as a binary expression tree of the formula.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula
|
str
|
right-hand side of an equation expressed in infix notation |
required |
Returns:
Type | Description |
---|---|
Node
|
node as a binary expression tree of the formula |
Raises:
Type | Description |
---|---|
SyntaxError
|
when the formula has syntax errors. |
Gaussian
¶
Bases: Term
Extended term that represents the gaussian curve membership function.
Equation
\(\mu(x) = h \exp\left(-\dfrac{(x-\mu)^2}{2\sigma^2}\right)\)
where
- \(h\): height of the Term
- \(\mu\): mean of the Gaussian
- \(\sigma\): standard deviation of the Gaussian
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
GaussianProduct
¶
Bases: Term
Extended term that represents the two-sided gaussian membership function.
Equation
\(a = \begin{cases} \mbox{Gaussian}^{\mu_a}_{\sigma_a}(x) & \mbox{if } x < \mu_a \cr 1.0 & \mbox{otherwise} \cr \end{cases}\)
\(b = \begin{cases} \mbox{Gaussian}^{\mu_b}_{\sigma_b}(x) & \mbox{if } x > \mu_b \cr 1.0 & \mbox{otherwise} \cr \end{cases}\)
\(\mu(x) = h (a \times b)\)
where
- \(h\): height of the Term
- \(\mu_a, \sigma_a\): mean and standard deviation of the first Gaussian
- \(\mu_b, \sigma_b\): mean and standard deviation of the second Gaussian
Attributes¶
Functions¶
__init__
¶
__init__(
name: str = "",
mean_a: float = nan,
standard_deviation_a: float = nan,
mean_b: float = nan,
standard_deviation_b: float = nan,
height: float = 1.0,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the Term |
''
|
mean_a
|
float
|
mean of the first Gaussian |
nan
|
standard_deviation_a
|
float
|
standard deviation of the first Gaussian |
nan
|
mean_b
|
float
|
mean of the second Gaussian |
nan
|
standard_deviation_b
|
float
|
standard deviation of the second Gaussian |
nan
|
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 |
membership
¶
Linear
¶
Bases: Term
Linear polynomial term.
Equation
\(\mu(x)= \mathbf{c}\mathbf{v}+k = \sum_i c_iv_i + k\)
where
- \(x\): irrelevant
- \(\mathbf{v}\): vector of values from the input variables
- \(\mathbf{c}\) vector of coefficients for the input variables
- \(k\) is a constant
Attributes¶
Functions¶
__init__
¶
__repr__
¶
__repr__() -> str
Return the code to construct the term in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in Python. |
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
coefficients |
required |
membership
¶
Compute the membership function evaluated at \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x)=\sum_i c_iv_i + k\) |
Raises:
Type | Description |
---|---|
ValueError
|
when the number of coefficients (+1) is different from the number of input variables |
PiShape
¶
Bases: Term
Extended term that represents the Pi-shaped membership function.
Equation
\(\mu(x) = h \left(\mbox{SShape}_{a}^{b}(x) \times \mbox{ZShape}_{c}^{d}(x)\right)\)
where
- \(h\): height of the Term
- \(a, b\): bottom left and top left parameters of the PiShape
- \(c, d\): top right and bottom right parameters of the PiShape
Attributes¶
Functions¶
__init__
¶
__init__(
name: str = "",
bottom_left: float = nan,
top_left: float = nan,
top_right: float = nan,
bottom_right: float = nan,
height: float = 1.0,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the Term |
''
|
bottom_left
|
float
|
bottom-left value of the PiShape |
nan
|
top_left
|
float
|
top-left value of the PiShape |
nan
|
top_right
|
float
|
top-right value of the PiShape |
nan
|
bottom_right
|
float
|
bottom-right value of the PiShape |
nan
|
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 |
membership
¶
Ramp
¶
Bases: Term
Edge term that represents the ramp membership function.
Equation
\(\mu(x) = \begin{cases} h \dfrac{x - s} {e - s} & \mbox{if } s < x < e \cr h \dfrac{s - x} {s - e} & \mbox{if } e < x < s \cr h & \mbox{if } s < e \wedge x \ge e \cr h & \mbox{if } s > e \wedge x \le e \cr 0 & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(s\): start of the Ramp
- \(e\): end of the Ramp
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Compute the membership function evaluated at \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x) = \begin{cases} h \dfrac{x - s} {e - s} & \mbox{if } s < x < e \cr h \dfrac{s - x} {s - e} & \mbox{if } e < x < s \cr h & \mbox{if } s < e \wedge x \ge e \cr h & \mbox{if } s > e \wedge x \le e \cr 0 & \mbox{otherwise} \end{cases}\) |
tsukamoto
¶
Rectangle
¶
Bases: Term
Basic term that represents the rectangle membership function.
Equation
\(\mu(x) = \begin{cases} h & \mbox{if } s \le x \le e \cr 0 & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(s\): start of the Rectangle
- \(e\): end of the Rectangle
SShape
¶
Bases: Term
Edge Term that represents the S-shaped membership function.
Equation:
\(\mu(x) = \begin{cases} 0 & \mbox{if } x \leq s \cr 2h \left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x \leq \dfrac{s+e}{2}\cr h - 2h\left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} < x < e\cr h & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(s\): start of the SShape
- \(e\): end of the SShape
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Computes the membership function evaluated at \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x) = \begin{cases} 0 & \mbox{if } x \leq s \cr 2h \left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x \leq \dfrac{s+e}{2}\cr h - 2h\left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} < x < e\cr h & \mbox{otherwise} \end{cases}\) |
tsukamoto
¶
Compute the tsukamoto value of the monotonic term for activation degree \(y\).
Equation
\(y = \begin{cases} 0 & \mbox{if } x \leq s \cr 2h \left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x \leq \dfrac{s+e}{2}\cr h - 2h\left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} < x < e\cr h & \mbox{otherwise} \end{cases}\)
\(x = \begin{cases} s + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr e - (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Scalar
|
activation degree |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(x = \begin{cases} s + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr e - (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\) |
SemiEllipse
¶
Bases: Term
Basic term that represents the semi-ellipse membership function.
Equation
\(\mu(x) = h \dfrac{\sqrt{r^2- (x-c)^2}}{r}\)
where
- \(h\): height of the Term
- \(r\): radius of the SemiEllipse
- \(c\): center of the SemiEllipse
Sigmoid
¶
Bases: Term
Edge Term that represents the sigmoid membership function.
Equation
\(\mu(x) = \dfrac{h}{1 + \exp(-s(x-i))}\)
where
- \(h\): height of the Term
- \(s\): slope of the Sigmoid
- \(i\): inflection of the Sigmoid
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
tsukamoto
¶
Compute the tsukamoto value of the monotonic term for activation degree \(y\).
Equation
\(y=\dfrac{h}{1 + \exp(-s(x-i))}\)
\(x=i\dfrac{\log{\left(\dfrac{h}{y}-1\right)}}{-s}\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Scalar
|
activation degree |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(x=i\dfrac{\log{\left(\dfrac{h}{y}-1\right)}}{-s}\) |
SigmoidDifference
¶
Bases: Term
Extended Term that represents the difference between two sigmoid membership functions.
Equation
\(a = \mbox{Sigmoid}_\mbox{left}^\mbox{rise}(x)\)
\(b = \mbox{Sigmoid}_\mbox{right}^\mbox{fall}(x)\)
\(\mu(x) = h (a-b)\)
where
- \(h\): height of the Term
- \(\mbox{left}, \mbox{rise}\): inflection and slope of left Sigmoid
- \(\mbox{right}, \mbox{fall}\): inflection and slope of right Sigmoid
Attributes¶
Functions¶
__init__
¶
__init__(
name: str = "",
left: float = nan,
rising: float = nan,
falling: float = nan,
right: float = nan,
height: float = 1.0,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the Term |
''
|
left
|
float
|
inflection of the left Sigmoid |
nan
|
rising
|
float
|
slope of the left Sigmoid |
nan
|
falling
|
float
|
slope of the right Sigmoid |
nan
|
right
|
float
|
inflection of the right Sigmoid |
nan
|
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 |
membership
¶
SigmoidProduct
¶
Bases: Term
Extended Term that represents the product of two sigmoid membership functions.
Equation
\(a = \mbox{Sigmoid}_\mbox{left}^\mbox{rise}(x)\)
\(b = \mbox{Sigmoid}_\mbox{right}^\mbox{fall}(x)\)
\(\mu(x) = h (a \times b)\)
where
- \(h\): height of the Term
- \(\mbox{left}, \mbox{rise}\): inflection and slope of left Sigmoid
- \(\mbox{right}, \mbox{fall}\): inflection and slope of right Sigmoid
Attributes¶
Functions¶
__init__
¶
__init__(
name: str = "",
left: float = nan,
rising: float = nan,
falling: float = nan,
right: float = nan,
height: float = 1.0,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the Term |
''
|
left
|
float
|
inflection of the left Sigmoid |
nan
|
rising
|
float
|
slope of the left Sigmoid |
nan
|
falling
|
float
|
slope of the right Sigmoid |
nan
|
right
|
float
|
inflection of the right Sigmoid |
nan
|
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 |
membership
¶
Spike
¶
Bases: Term
Extended Term that represents the spike membership function.
Equation
\(\mu(x)=h \exp\left(-\left|\dfrac{10}{w} (x - c)\right|\right)\)
where
- \(h\): height of the Term
- \(w\): width of the Spike
- \(c\): center of the Spike
Term
¶
Bases: ABC
Abstract class for linguistic terms.
The linguistic terms in this library can be divided into four groups, namely basic
, extended
, edge
, and function
.
related
Attributes¶
Functions¶
__init__
¶
__repr__
¶
__repr__() -> str
Return the code to construct the term in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in Python. |
__str__
¶
__str__() -> str
Return the code to construct the term in the FuzzyLite Language.
Returns:
Type | Description |
---|---|
str
|
code to construct the term in the FuzzyLite Language. |
_parameters
¶
_parse
¶
Parse the required values from the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
required
|
int
|
number of values to parse |
required |
parameters
|
str
|
text containing the values |
required |
height
|
bool
|
whether |
True
|
Returns:
Type | Description |
---|---|
list[float]
|
list of floating-point values parsed from the parameters. |
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
The parameters
is a list of space-separated values,
with an optional value at the end to set the height
(defaults to 1.0
if absent)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
space-separated parameter values to configure the term. |
required |
discretize
¶
membership
abstractmethod
¶
parameters
¶
parameters() -> str
Return the parameters of the term.
Returns:
Type | Description |
---|---|
str
|
list of space-separated parameters of the term. |
tsukamoto
¶
Compute the tsukamoto value of the monotonic term for activation degree \(y\).
Equation
\(g(y) = \{ z \in\mathbb{R} : \mu(z) = y \}\)
Warning
Raises RuntimeError
because the term does not support Tsukamoto
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Scalar
|
activation degree |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
because the term does not support Tsukamoto |
Trapezoid
¶
Bases: Term
Basic Term that represents the trapezoid membership function.
Equation
\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > d\cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b\cr h & \mbox{if } (b \le x \le c) \vee (a=-\infty \wedge x < b) \vee (d=\infty \wedge x > c) \cr h \dfrac{d - x}{d - c} & \mbox{if } c < x \le d\cr \text{NaN} & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(a\): bottom left vertex of the Trapezoid
- \(b\): top left vertex of the Trapezoid
- \(c\): top right vertex of the Trapezoid
- \(d\): bottom right vertex of the trapezoid
Attributes¶
Functions¶
__init__
¶
__init__(
name: str = "",
bottom_left: float = nan,
top_left: float = nan,
top_right: float = nan,
bottom_right: float = nan,
height: float = 1.0,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of the Term |
''
|
bottom_left
|
float
|
first vertex of the Trapezoid |
nan
|
top_left
|
float
|
second vertex of the Trapezoid |
nan
|
top_right
|
float
|
third vertex of the Trapezoid |
nan
|
bottom_right
|
float
|
fourth vertex of the Trapezoid |
nan
|
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 |
membership
¶
Computes the membership function evaluated at \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > d\cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b\cr h & \mbox{if } (b \le x \le c) \vee (a=-\infty \wedge x < b) \vee (d=\infty \wedge x > c) \cr h \dfrac{d - x}{d - c} & \mbox{if } c < x \le d\cr \text{NaN} & \mbox{otherwise} \end{cases}\) |
Triangle
¶
Bases: Term
Basic Term that represents the triangle membership function.
Equation
\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > c \cr h & \mbox{if } (x = b) \vee (a=-\infty \wedge x < b) \vee (c=\infty \wedge x > b) \cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b \cr h \dfrac{c - x}{c - b} & \mbox{if } b < x \le c \end{cases}\)
where
- \(h\): height of the Term
- \(a\): left vertex of the Triangle
- \(b\): top vertex of the Triangle
- \(c\): right vertex of the Triangle
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Computes the membership function evaluated at \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x)= \begin{cases} 0 & \mbox{if } x < a \vee x > c \cr h & \mbox{if } (x = b) \vee (a=-\infty \wedge x < b) \vee (c=\infty \wedge x > b) \cr h \dfrac{x - a}{b - a} & \mbox{if } a \le x < b \cr h \dfrac{c - x}{c - b} & \mbox{if } b < x \le c \end{cases}\) |
ZShape
¶
Bases: Term
Edge Term that represents the ZShape membership function.
Equation
\(\mu(x) = \begin{cases} 1 & \mbox{if } x \leq s \cr h - 2h\left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x < \dfrac{s+e}{2} \cr 2h \left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} \le x < e\cr 0 & \mbox{otherwise} \end{cases}\)
where
- \(h\): height of the Term
- \(s\): start of the ZShape
- \(e\): end of the ZShape
Attributes¶
Functions¶
__init__
¶
configure
¶
configure(parameters: str) -> None
Configure the term with the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
str
|
|
required |
membership
¶
Computes the membership function evaluated at \(x\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Scalar
|
scalar |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(\mu(x) = \begin{cases} 1 & \mbox{if } x \leq s \cr h - 2h\left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x < \dfrac{s+e}{2} \cr 2h \left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} \le x < e\cr 0 & \mbox{otherwise} \end{cases}\) |
tsukamoto
¶
Compute the tsukamoto value of the monotonic term for activation degree \(y\).
Equation
\(y = \begin{cases} 1 & \mbox{if } x \leq s \cr h - 2h\left(\dfrac{x - s}{e-s}\right)^2 & \mbox{if } s < x < \dfrac{s+e}{2} \cr 2h \left(\dfrac{x - e}{e-s}\right)^2 & \mbox{if } \dfrac{s+e}{2} \le x < e\cr 0 & \mbox{otherwise} \end{cases}\)
\(x = \begin{cases} e + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr s + (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
Scalar
|
activation degree |
required |
Returns:
Type | Description |
---|---|
Scalar
|
\(x = \begin{cases} e + (e-s) \sqrt{\dfrac{y}{2h}} & \mbox{if } y \le \dfrac{h}{2} \cr s + (e-s) \sqrt{\dfrac{h-y}{2h}} & \mbox{otherwise} \end{cases}\) |