Skip to content

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

AND class-attribute instance-attribute

AND = 'and'

IF class-attribute instance-attribute

IF = 'if'

IS class-attribute instance-attribute

IS = 'is'

OR class-attribute instance-attribute

OR = 'or'

THEN class-attribute instance-attribute

THEN = 'then'

WITH class-attribute instance-attribute

WITH = 'with'

activation_degree instance-attribute

activation_degree = scalar(0.0)

antecedent instance-attribute

antecedent = antecedent or Antecedent()

consequent instance-attribute

consequent = consequent or Consequent()

enabled instance-attribute

enabled = enabled

text property writable

text: str

Get/Set the rule as text.

Getter

Returns:

Type Description
str

rule as text

Setter

Parameters:

Name Type Description Default
text str

rule as text

required

triggered instance-attribute

triggered = array(False)

weight instance-attribute

weight = weight

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

activate_with(conjunction: TNorm | None, disjunction: SNorm | None) -> Scalar

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

create(text: str, engine: Engine | None = None) -> Rule

Create rule from the text.

Parameters:

Name Type Description Default
text str

rule as text

required
engine Engine | None

engine that the rule (partially) controls

None

deactivate

deactivate() -> None

Deactivate the rule.

is_loaded

is_loaded() -> bool

Return whether the rule is loaded.

Returns:

Type Description
bool

rule is loaded.

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

unload

unload() -> None

Unload the rule.