ex_fuzzy.rules.RuleSimple#

class ex_fuzzy.rules.RuleSimple(antecedents, consequent=0, modifiers=None)[source]#

Bases: object

Simplified Rule Representation for Optimized Computation.

This class represents fuzzy rules in a simplified format optimized for computational efficiency in rule base operations. It uses integer encoding for antecedents and consequents to minimize memory usage and speed up rule evaluation processes.

antecedents#

Integer-encoded antecedents where: - -1: Variable not used in the rule - 0-N: Index of the linguistic variable used for the ith input

Type:

list[int]

consequent#

Integer index of the consequent linguistic variable

Type:

int

modifiers#

Optional modifiers for rule adaptation

Type:

np.array

Example

>>> # Rule: IF x1 is Low AND x2 is High THEN y is Medium
>>> # Assuming Low=0, High=1, Medium=1
>>> rule = RuleSimple([0, 1], consequent=1)
>>> print(rule.antecedents)  # [0, 1]
>>> print(rule.consequent)  # 1

Note

This simplified representation is designed for high-performance rule evaluation in large rule bases where memory and speed are critical.

__init__(antecedents, consequent=0, modifiers=None)[source]#

Creates a rule with the given antecedents and consequent.

Parameters:
  • antecedents (list[int]) – List of integers indicating the linguistic variable used for each input (-1 for unused variables)

  • consequent (int, optional) – Integer indicating the linguistic variable used for the consequent. Defaults to 0.

  • modifiers (np.array, optional) – Array of modifier values for rule adaptation. Defaults to None.

Example

>>> # Create a rule with two antecedents and one consequent
>>> rule = RuleSimple([0, 2, -1], consequent=1)  # x1=0, x2=2, x3=unused, y=1
__getitem__(ix)[source]#

Returns the antecedent value for the given index.

Parameters:

ix (int) – Index of the antecedent to return

Returns:

The antecedent value at the specified index

Return type:

int

Example

>>> rule = RuleSimple([0, 1, 2])
>>> print(rule[1])  # 1
__setitem__(ix, value)[source]#

Sets the antecedent value for the given index.

Parameters:
  • ix (int) – Index of the antecedent to set

  • value (int) – Value to set at the specified index

Example

>>> rule = RuleSimple([0, 1, 2])
>>> rule[1] = 3  # Change second antecedent to 3
__str__()[source]#

Returns a string representation of the rule.

Returns:

Human-readable string representation of the rule

Return type:

str

Example

>>> rule = RuleSimple([0, 1], consequent=2)
>>> print(rule)  # Rule: antecedents: [0, 1] consequent: 2
__len__()[source]#

Returns the number of antecedents in the rule.

Returns:

Number of antecedents in the rule

Return type:

int

Example

>>> rule = RuleSimple([0, 1, 2])
>>> print(len(rule))  # 3
__eq__(other)[source]#

Returns True if the two rules are equal.

Parameters:

other (RuleSimple) – Another rule to compare with

Returns:

True if rules have identical antecedents and consequent

Return type:

bool

Example

>>> rule1 = RuleSimple([0, 1], consequent=2)
>>> rule2 = RuleSimple([0, 1], consequent=2)
>>> print(rule1 == rule2)  # True
__hash__()[source]#

Returns the hash of the rule.