Term¶
- class floulib.Term(*args)¶
Bases:
Plot
This class contains methods to define and use a term for linguistic variable, especially for rules in fuzzy controller. In general, a term is the association of a string like “small” and its meaning, i.e. the membership function associated with the term.
In special cases, variable may contain purely linguistic terms which have no meaning associated with.
- prototype = None¶
Prototype associated with the term to be used in the symbolic defuzzification (method WAM-P). The prototype can be:
a scalar,
a list of scalars,
a dict containing scalar or list of scalars.
- __init__(*args)¶
Constructor
- Parameters:
*args (str | Multilinear) –
If the type of args is str, args defines the name of the term.
If args is Multilinear, args defines the meaning of the term.
- Raises:
Exception – Raised if the number of positional arguments is equal to 0 or greater than 2.
TypeError – Raised if there is one positional argument which is not an instance of str.
- Return type:
None.
Example
Generates the term A as the association of the Singleton(‘A’) and its meaning provided by the LR fuzzy subset LR(1, 0.5, 0.5).
>>> from floulib import Term >>> A = Term('A', LR(1, 0.5, 0.5))
Same as above
>>> A = Term(LR(1, 0.5, 0.5), 'A')
Creates the term A as the Singleton(‘A’) with no meaning.
>>> A = Term('A')
- area()¶
Area of the meaning of the term (see
floulib.LR.area()
).- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
LR
.- Returns:
The area.
- Return type:
float
- centroid()¶
Centroid of the meaning of the term (see
floulib.LR.centroid()
).- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
LR
.- Returns:
The centroid.
- Return type:
float
- membership(x)¶
Computes the grade of membership to the meaning for x (see
floulib.Multilinear.membership()
).- Parameters:
x (float) – Point where the grade of membership is computed.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
Grade of membership.
- Return type:
float
- mode()¶
Mode of the meaning of the term (see
floulib.LR.mode()
).- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
LR
.- Returns:
The mode.
- Return type:
float
- necessity(dpi)¶
Computes the necessity of the meaning of the term knowing the distribution of possibility dpi (see
floulib.Multilinear.necessity()
).- Parameters:
dpi (Multilinear) – The possibility distribution.
- Raises:
TypeError – Raised by the private method Term._get_meaning() if the parameter is not an instance of
Term
orMultilinear
.- Returns:
The necessity.
- Return type:
- possibility(dpi)¶
Computes the possibility of the meaning of the term knowing the distribution of possibility dpi (see
floulib.Multilinear.possibility()
).- Parameters:
dpi (Multilinear) – The possibility distribution.
- Raises:
TypeError – Raised by the private method Term._get_meaning() if the parameter is not an instance of
Term
orMultilinear
.- Returns:
The possibility.
- Return type:
- Certainty(level)¶
Adds a certainty level to the meaning of a term (see
floulib.Multilinear.Certainty()
).- Parameters:
level (float) – The certainty level.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The multilinear fuzzy subset with certainty level.
- Return type:
- Uncertainty(level)¶
Adds an uncertainty level to the meaning of a term (see
floulib.Multilinear.Uncertainty()
).- Parameters:
level (float) – The uncertainty level.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The multilinear fuzzy subset with uncertainty level.
- Return type:
- __and__(other)¶
Special method for using the operator & between two instances of Term. It returns the intersection of the meanings of the terms (see
floulib.Multilinear.__and__()
).- Parameters:
other (Term) – The RHS operand.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The intersection of the meanings.
- Return type:
- __invert__()¶
Special method for using the unary operator ~ as the complement of a term (see
floulib.Multilinear.__invert__()
).- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The complement of the meaning.
- Return type:
- __neg__()¶
Special method for using the unary operator - as the opposite of a term (see
floulib.Multilinear.__neg__()
).- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The opposite of the meaning.
- Return type:
- __or__(other)¶
Special method for using the operator | between two instances of Term. It returns the union of the meanings of the terms (see
floulib.Multilinear.__or__()
).- Parameters:
other (Term) – The RHS operand.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The union of the meanings.
- Return type:
- __rmul__(other)¶
Special method for using the opertor * with a number as the LHS operand. Its multiplies the grades of membership of themeaning of the term by the LHS operand and truncates them to 1 (see
floulib.Multilinear.__rmul__()
).- Parameters:
other (Term) – The RHS operand.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The result.
- Return type:
- __xor__(other)¶
Special method for using the opertor ^ between two instances of Term. It returns the symmetric difference of the meanings of the terms (see
floulib.Multilinear.__xor__()
).- Parameters:
other (Term) – The RHS operand.
- Raises:
TypeError – Raised is the meaning associated with the term is not an instance of
Multilinear
.- Returns:
The symmetric difference of the meanings.
- Return type: