fuzzy_logic

Description

Parse fuzzy logic rules to truth functions in the form of dictionary transformations. This module implements a general framework and DSL to specify and parse (fuzzy) logical rules into a computational tree of Merge operations. Besides the base classes to define rules, logical theories, and parse rules in a logic to/from string, several standard operations are provided.

Logical formulas and theories are modelled using the base classes Merge and Logic as follows:

  • (Logical) merge operations: These are instances of Merge operations, i.e. callables that accept a dictionary (the grounding = a map assigning values to variable names) and return the dictionary with the operation outputs added.

  • Variables and constants: Variables are represented by string keys. They may be grounded (have a value assigned) by adding the key-value pair to the grounding dictionary. Constants are treated like grounded variables.

  • Formula = tree of operations: Merge operations may depend directly on values given by keys (names of variables or constants) in the grounding dictionary, or they may have children operations on the output of which they depend. An example would be the operation AND("a", OR("b", "c"))` depending on the variable ``"a" and the child operation OR("b", "c"). The children operations are applied to the grounding dictionary before the parent operation, adding their outputs. Such a computational tree of operations constitutes a logical formula.

  • Typical logical operations are:

    • (Fuzzy) logical connectives: AND, OR, NOT, IMPLIES; These receive truth values (either Boolean or fuzzy) and return a truth value. Standard ones are those defined by the standard t-norm fuzzy logics.

    • Predicates: e.g. IsPartOfA, GreaterThan; These receive an arbitrary domain value, e.g. a pixel position, and return a truth value.

    • Quantifiers: EXISTS, FORALL; These reduce a domain of values, e.g. a set of image samples, to a single truth value, using a child predicate (the body formula) and a truth value reduction.

  • Logic: A Logic is here defined by a collection of operation types (operation builders) for building formulas. To allow parsing of infix notation, these are associated with an operator precedence (their order in the collection).

  • Parsing: A logic allows parsing of infix notation string representations of formulas using a FormulaParser. Calling str on the resulting formula returns an equivalent parsable string representation of the formula.

Note that naming is adopted from the case of Boolean mask operations on segmentation mask annotations (hence Merge operations accepting annotations dictionaries).

Sub-modules

logic_base

Base classes for defining and operating on logics.

predicates

Implementations of logical predicates as merge operations.

quantifiers

Base classes and simple implementations for standard quantifiers.

tnorm_connectives

Implementations of standard Boolean and t-norm fuzzy logic connectives with base logics.

Functions

logic_by_name(fuzzy_logic_key)

Select a fuzzy logic handle by string identifier.