Rule
Rule
¶
Conditional statement that contributes to the control of an Engine.
A rule consists of an Antecedent and a Consequent, each with propositions in the form variable is term
.
The propositions in the Antecedent are connected by the conjunctive and
or the disjunctive or
,
which are fuzzy logic operators represented as TNorm and SNorm (respectively).
The propositions in the Consequent are independent and separated by a symbolic and
.
The term in any proposition can be preceded by a hedge that modifies its membership function value of the term.
The contribution of a rule to the control of the engine can be determined by its weight \(w \in [0.0, 1.0]\), which is equal to 1.0 if omitted.
structure
The structure of a rule is:
if (antecedent) then (consequent) [with weight]
The structure of the antecedent is:
if variable is [hedge]* term [(and|or) variable is [hedge]* term]*
The structure of the consequent is:
then variable is [hedge]* term [and variable is [hedge]* term]* [with w]?
where elements in brackets are optional,
elements in parentheses are compulsory,
*
-marked elements may appear zero or more times, and
?
-marked elements may appear once or not at all.
related
Attributes¶
Functions¶
__init__
¶
__init__(
enabled: bool = True,
weight: float = 1.0,
antecedent: Antecedent | None = None,
consequent: Consequent | None = None,
) -> None
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled |
bool
|
enable the rule |
True
|
weight |
float
|
weight of the rule |
1.0
|
antecedent |
Antecedent | None
|
antecedent of the rule |
None
|
consequent |
Consequent | None
|
consequent of the rule |
None
|
__repr__
¶
__repr__() -> str
Return the code to construct the rule in Python.
Returns:
Type | Description |
---|---|
str
|
code to construct the rule in Python. |
__str__
¶
__str__() -> str
Return the code to construct the rule in the FuzzyLite Language.
Returns:
Type | Description |
---|---|
str
|
code to construct the rule in the FuzzyLite Language. |
activate_with
¶
Compute and set activation degree of the rule with the conjunction and disjunction operators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conjunction |
TNorm | None
|
conjunction operator |
required |
disjunction |
SNorm | None
|
disjunction operator |
required |
Returns:
Type | Description |
---|---|
Scalar
|
activation degree of the rule. |
create
staticmethod
¶
load
¶
load(engine: Engine) -> None
Load the rule using the engine to identify and get references to the input and output variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine |
Engine
|
engine that the rule (partially) controls |
required |
parse
¶
parse(text: str) -> None
Parse and load the rule based on the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
rule as text. |
required |
trigger
¶
trigger(implication: TNorm | None) -> None
Trigger the rule using the implication operator and the previously computed activation degree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
implication |
TNorm | None
|
implication operator. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
when the rule is not loaded |