Languages (FML and FCL)

generate_system

pyit2fls.generate_system(variables, rules)

Builds a Type 1 Fuzzy Logic System (Mamdani or TSK) out of the shared intermediate representation produced by FML.parse_fml() and pyit2fls.FCL.parse_fcl().

Parameters

variables : dict

A dictionary with keys "input" and "output", each mapping variable names to a dict with keys "domainleft", "domainright", and "terms". "terms" maps term names to a dict with keys "set" (a key of MF_MAP), "params" (a list of floats), and "complement" (the string "true" or "false").

rules : dict

A dictionary with keys "type" ("mamdani" or "takagi-sugeno"), "andMethod", "orMethod", "activationMethod", and "rules". "rules" maps rule names to a dict with keys "antecedent" and "consequent" (each a list of (variable name, term name) tuples), "connector" ("and" or "or"), and "weight".

Returns

output : T1Mamdani or T1TSK

The fuzzy logic system built from the given variables and rules.

Notes

The underlying pyit2fls.T1Mamdani and pyit2fls.T1TSK engines only support antecedents whose clauses are implicitly AND-ed together (there is no seam for OR-combined clauses within a single rule), so a ValueError is raised for any rule whose "connector" is "or" and which has more than one antecedent clause.

Rule "weight" values are carried through by parse_fml() and pyit2fls.FCL.parse_fcl() but are not applied while evaluating the generated system: doing so would require changes to the firing-strength arithmetic in every T1Mamdani/T1TSK evaluate method, which is out of the scope of this module.

FML

class pyit2fls.FML

Parser and generator for the IEEE 1855 Fuzzy Markup Language (FML).

Functions

parse_fml:

Parses an FML XML string into the shared (name, variables, rules) intermediate representation.

generate:

Builds a runnable pyit2fls.T1Mamdani/pyit2fls.T1TSK system out of that representation (a thin wrapper of generate_system()).

Examples

>>> myFML = FML()
>>> name, variables, rules = myFML.parse_fml(fml_xml_string)
>>> system = myFML.generate(variables, rules)
>>> system.evaluate({"temp": 25})

FCL

class pyit2fls.FCL

Parser and generator for the core Mamdani subset of the IEC 61131-7 Fuzzy Control Language (FCL).

Functions

parse_fcl:

Parses an FCL text document into the shared (name, variables, rules) intermediate representation (the same one produced by pyit2fls.FML.FML.parse_fml()).

generate:

Builds a runnable pyit2fls.T1Mamdani system out of that representation (a thin wrapper of pyit2fls.FML.generate_system()).

export_fcl:

Serializes a (name, variables, rules) triple back into FCL text.

Examples

>>> myFCL = FCL()
>>> name, variables, rules = myFCL.parse_fcl(fcl_text)
>>> system = myFCL.generate(variables, rules)
>>> system.evaluate({"temp": 25})