Rule
Antecedent
¶
Expression tree that represents and evaluates the antecedent of a rule.
structure
The structure of a rule is:
if (antecedent) then (consequent)
The structure of the antecedent of a rule is:
if variable is [hedge]* term [(and|or) variable is [hedge]* term]*
*-marked elements may appear zero or more times,
elements in brackets are optional, and
elements in parentheses are compulsory.
Attributes¶
Functions¶
__repr__
¶
__repr__() -> str
Return the code to construct the antecedent in Python.
Returns:
| Type | Description |
|---|---|
str
|
code to construct the antecedent in Python. |
activation_degree
¶
activation_degree(
conjunction: TNorm | None = None, disjunction: SNorm | None = None, node: Expression | None = None
) -> Scalar
Compute the activation degree of the antecedent on the expression tree from the given node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conjunction
|
TNorm | None
|
conjunction operator from the rule block |
None
|
disjunction
|
SNorm | None
|
disjunction operator from the rule block |
None
|
node
|
Expression | None
|
node in the expression tree of the antecedent |
None
|
Returns:
| Type | Description |
|---|---|
Scalar
|
activation degree of the antecedent. |
infix
¶
infix(node: Expression | None = None) -> str
Return the infix notation of the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Expression | None
|
node in the expression tree of the antecedent |
None
|
Returns:
| Type | Description |
|---|---|
str
|
infix notation of the node. |
load
¶
load(engine: Engine) -> None
Load the antecedent using the engine to identify and get references to the input and output variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
engine to get references in the antecedent. |
required |
postfix
¶
postfix(node: Expression | None = None) -> str
Return the postfix notation of the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Expression | None
|
node in the expression tree of the antecedent |
None
|
Returns:
| Type | Description |
|---|---|
str
|
postfix notation of the node. |
prefix
¶
prefix(node: Expression | None = None) -> str
Return the prefix notation of the node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Expression | None
|
node in the expression tree of the antecedent |
None
|
Returns:
| Type | Description |
|---|---|
str
|
prefix notation of the node. |
Consequent
¶
Proposition set that represents and evaluates the consequent of a rule.
structure
The structure of a rule is:
if (antecedent) then (consequent)
The structure of the consequent of a rule is:
then variable is [hedge]* term [and variable is [hedge]* term]* [with w]?
*-marked elements may appear zero or more times,
elements in brackets are optional,
elements in parentheses are compulsory, and
?-marked elements may appear once or not at all.
Attributes¶
Functions¶
__repr__
¶
__repr__() -> str
Return the code to construct the consequent in Python.
Returns:
| Type | Description |
|---|---|
str
|
code to construct the consequent in Python. |
load
¶
load(engine: Engine) -> None
Load the consequent using the engine to identify and get references to the input and output variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
engine to get references in the consequent. |
required |
modify
¶
Operator
¶
Bases: Expression
Expression that represents a non-terminal node in the expression tree as a binary operator (i.e., and or or) on two Expression nodes.
Attributes¶
Functions¶
__init__
¶
__init__(name: str = '', right: Expression | None = None, left: Expression | None = None) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the operator |
''
|
left
|
Expression | None
|
left expression in the binary tree |
None
|
right
|
Expression | None
|
right expression in the binary tree. |
None
|
Proposition
¶
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 |
RuleBlock
¶
Block of rules and fuzzy logic operators required to control an engine.
related
Attributes¶
Functions¶
__getitem__
¶
__init__
¶
__init__(
name: str = "",
description: str = "",
enabled: bool = True,
conjunction: TNorm | None = None,
disjunction: SNorm | None = None,
implication: TNorm | None = None,
activation: Activation | None = None,
rules: Iterable[Rule] | None = None,
) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the rule block |
''
|
description
|
str
|
description of the rule block |
''
|
enabled
|
bool
|
enable the rule block |
True
|
conjunction
|
TNorm | None
|
conjunction operator |
None
|
disjunction
|
SNorm | None
|
disjunction operator |
None
|
implication
|
TNorm | None
|
implication operator |
None
|
activation
|
Activation | None
|
activation method |
None
|
rules
|
Iterable[Rule] | None
|
list of rules. |
None
|
__iter__
¶
__repr__
¶
__repr__() -> str
Return the code to construct the rule block in Python.
Returns:
| Type | Description |
|---|---|
str
|
code to construct the rule block in Python. |
__str__
¶
__str__() -> str
Return the code to construct the rule block in the FuzzyLite Language.
Returns:
| Type | Description |
|---|---|
str
|
code to construct the rule block in the FuzzyLite Language. |
load_rules
¶
load_rules(engine: Engine) -> None
Load all the rules in the rule block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
engine where this rule block is registered. |
required |
reload_rules
¶
reload_rules(engine: Engine) -> None
Reload all the rules in the rule block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
engine where this rule block is registered. |
required |