Section for working with fuzzy logic

class fuzzyops.fuzzy_logic.base_rules.BaseRule(antecedents: List[Tuple[str]], consequent: Tuple[str])[source]

Bases: object

A base class for representing a rule in the knowledge base of a fuzzy logic system

antecedents

Antecedents of the rule, representing the conditions

Type:

List[Tuple[str]]

consequent

The rule’s consequence, which is the conclusion

Type:

Any

antecedents: List[Tuple[str]]
consequent: Tuple[str]
class fuzzyops.fuzzy_logic.base_rules.FuzzyInference(domains: Dict[str, Domain], rules: List[BaseRule])[source]

Bases: object

A class for implementing fuzzy logical inference using the Mamdani algorithm

domains

Dictionary of domains for fuzzy numbers

Type:

Dict[str, Domain]

rules

List of rules in the rule database

Type:

List[BaseRule]

Parameters:
  • domains (Dict[str, Domain]) – Dictionary of domains for fuzzy numbers

  • rules (List[BaseRule]) – List of rules in the rule database

Raises:

AttributeError – If the transmitted domain name is not present in the rule database

compute(input_data: Dict[str, int | float | FuzzyNumber]) Dict[str, float][source]

A method that calculates the values of the coefficients in the rule base using the Mamdani algorithm

Parameters:
  • input_data (Dict[str, Union[int, float, FuzzyNumber])

  • set (A dictionary with domain names from the rule base and values from the universal)

  • consequences (for which it is necessary to find the values of the)

Returns:

Dictionary, the key is the name of the consequence, the value is the defazzified result

Return type:

Dict[str, float]

Raises:

AssertionError – If membership is not a string or does not match the required number of arguments

class fuzzyops.fuzzy_logic.base_rules.SingletonInference(domains: Dict[str, Domain], rules: List[BaseRule])[source]

Bases: object

A class for implementing fuzzy logical inference using the Singleton algorithm

domains

A dictionary of domains for fuzzy numbers

Type:

Dict[str, Domain]

rules

The list of rules in the rule database

Type:

List[BaseRule]

Parameters:
  • domains (Dict[str, Domain]) – A dictionary of domains for fuzzy numbers

  • rules (List[BaseRule]) – The list of rules in the rule database

compute(input_data: Dict[str, int | float | FuzzyNumber]) float[source]

A method that calculates the values of the consetquents in the rule base using the Singleton algorithm

Parameters:
  • input_data (Dict[str, Union[int, float, FuzzyNumber])

  • set (A dictionary with domain names from the rule base and values from the universal)

  • consequences (for which it is necessary to find the values of the)

Returns:

The numerical value of the consequence

Return type:

Dict[str, float]