Framework for Fuzzy Logic Rule Definition

The module hybrid_learning.fuzzy_logic defines a framework to

  • define (logical) operations as functions that accept a grounding and provide the rule truth value

  • define (fuzzy) logic rules as computational trees of operations

  • parse rules to and from string representation

  • define logics as collections of operation builders

For details have a look at the API Reference and the user guide.

Base Classes

Merge

Base class for operations and operation trees on dictionary inputs.

TorchOrNumpyOperation

Generic merge operation allowing to define both a torch and a numpy operation.

Logic

Basic definition of a logic.

FormulaParser

Base class to parse string formula specifiers in infix notation to merge operations.

Standard Fuzzy Logics

The following (fuzzy) logics with standard connectives from Boolean or t-norms fuzzy logic are defined in hybrid_learning.fuzzy_logic.tnorm_connectives. Select one of them by key using hybrid_learning.fuzzy_logic.logic_by_name().

boolean.BooleanLogic

Boolean logic and parser.

product.ProductLogic

Product fuzzy logic parser.

lukasiewicz.LukasiewiczLogic

Lukasiewicz logic parser.

goedel.GoedelLogic

Goedel fuzzy logic parser.

Standard Connectives

fuzzy_common.NOT

Fuzzy logic NOT.

boolean.AND

Intersection/AND operation on binary masks and scalars.

boolean.OR

Union/OR operation on binary masks and scalars.

boolean.IMPLIES

Pixel-wise implication logical connective on binary masks and scalars.

boolean.IMPLIEDBY

Goedel inverted logic IMPLIES connective.

product.AND

Product AND operation.

product.OR

Product OR operation.

product.IMPLIES

Product logic IMPLIES connective.

product.IMPLIEDBY

Goedel inverted logic IMPLIES connective.

lukasiewicz.AND

Lukasiewicz AND operation.

lukasiewicz.OR

Lukasiewicz OR operation.

lukasiewicz.IMPLIES

Lukasiewicz logic IMPLIES connective.

lukasiewicz.IMPLIEDBY

Goedel inverted logic IMPLIES connective.

goedel.AND

Goedel or Minimum AND operation.

goedel.OR

Goedel or Maximum OR operation.

goedel.IMPLIES

Goedel logic IMPLIES connective.

goedel.IMPLIEDBY

Goedel inverted logic IMPLIES connective.

Standard Quantifiers

ALL

Reduce a single tensor along given dimensions using logical AND.

ANY

Reduce a single tensor along given dimensions using logical OR.

WHERE

Filter the dimensions in tensor a by the boolean values given in cond.

Predicates

Arithmetic Predicates

Equals

Predicate of arity 2 that checks element-wise equality between two arrays.

GreaterEqualsThan

Predicate of arity 2 that thresholds number values at a given threshold.

GreaterThan

Predicate of arity 2 that thresholds number values at a given threshold.

LowerEqualsThan

Predicate of arity 2 that checks whether an input is below or equals a threshold.

LowerThan

Predicate of arity 2 that checks whether an input is below a threshold.

Custom Operations

AllNeighbors

Given a mask of truth values representing the output of a formula apply average pooling.

BestIoUWith

Given two stacked sets of masks masks_a and masks_b, calculate for each mask in masks_a the best IoU with any mask in masks_b.

CoveredBy

Calculate the proportion of one mask covered by another.

IoUWith

Calculate the intersection over union between two masks.

IsPartOfA

Unary predicate that calculates for each pixel location whether it is part of an object segmentation.

LambdaOp

Provide a custom transformation on the sequence of values extracted from the annotations dict.