Logic
- class hybrid_learning.fuzzy_logic.logic_base.logic.Logic(operators=None, **default_overrides)[source]
Bases:
MutableSequence
Basic definition of a logic. A logic must have operator builders for some basic connectives (by default
AND
,OR
,NOT
, seeDEFAULT_CONNECTIVES
) and holds a default operator builder precedence for parsing. New operator builders (e.g. for predicates or functions) can be added. The logic allows to iterate over itsoperators
(the operator builders) using usual__getitem__
notation. Operator builders must (cf.Merge
sub-classes andMergeBuilder
for examples of valid operator builders):be callable with string variable names, e.g.
OR("a", "b")
, or child operators, e.g.OR(NOT("a"), "b")
, returning an operator,return operators that are callable on dicts matching the variable names to instantiations,
provide a
variadic_
class method that returns a callable which accepts tensors/arrays/floats/Booleans and returns the result of the connective operation upon those inputs,provide a
SYMB
attribute that specifies the (unique) parsing symbol within this logic.
Operator Access
Obtain primitive variadic instances (i.e. callables on logic values) of the operations via
logical_()
. The basic connectives specified inDEFAULT_CONNECTIVES
or (as overrides) during init can be accessed by their given common name, i.e. the used key. All other operations can be accessed by their parsingSYMB
. See alsoop()
for this access.Sub-classing
To provide your own Logic, either create a
Logic
instance and override all mandatory (i.e.None
valued)DEFAULT_CONNECTIVES
values, or define a sub-class that defines its ownDEFAULT_CONNECTIVES
.Public Data Attributes:
Default connectives by common names.
Public Methods:
op
(symb)Get the operator builder for the given symbol.
logical_
(symb)Get a variadic instance of the logical operation specified by
symb
.parser
()Return a default parser for this logic.
is_pure
(op)Whether the formula
op
purely consists of operators built from this logic.insert
(precedence, op_builder)Add an operator builder with precedence
precedence
.Inherited from : py: class:MutableSequence
insert
(precedence, op_builder)Add an operator builder with precedence
precedence
.append
(value)S.append(value) -- append value to the end of the sequence
clear
()reverse
()S.reverse() -- reverse IN PLACE
extend
(values)S.extend(iterable) -- extend sequence by appending elements from the iterable
pop
([index])Raise IndexError if list is empty or index is out of range.
remove
(value)S.remove(value) -- remove first occurrence of value.
Inherited from : py: class:Sequence
index
(value, [start, [stop]])Raises ValueError if the value is not present.
count
(value)Special Methods:
__init__
([operators])Init.
__setitem__
(precedence, op_builder)__getitem__
(i)__delitem__
(i)__len__
()__add__
(other)__radd__
(other)__repr__
()Return repr(self).
Inherited from : py: class:MutableSequence
__setitem__
(precedence, op_builder)__delitem__
(i)__iadd__
(values)Inherited from : py: class:Sequence
__getitem__
(i)__iter__
()__contains__
(value)__reversed__
()Inherited from : py: class:Reversible
__reversed__
()Inherited from : py: class:Sized
__len__
()Inherited from : py: class:Iterable
__iter__
()Inherited from : py: class:Container
__contains__
(value)
- __init__(operators=None, **default_overrides)[source]
Init.
- Parameters
operators (Optional[Iterable[Type[Merge]]]) – the list of operators this logic holds; extended by the
DEFAULT_CONNECTIVES
and thedefault_overrides
; accessible via their symboldefault_overrides (Type[Merge]) – overrides and additions in the form
common_name=op_builder
for theDEFAULT_CONNECTIVES
; added to theoperators
in the order given first byDEFAULT_CONNECTIVES
then by additionally added connectives; later also accessible via their common name; setcommon_name=False
to explicitly discard this standard operator from the logic.
- Raises
:py:class`TypeError` in case not all mandatory basic connectives (such with
None
entries inDEFAULT_CONNECTIVES
) are overridden
- is_pure(op)[source]
Whether the formula
op
purely consists of operators built from this logic. See methodis_pure()
ofFormulaParser
.
- op(symb)[source]
Get the operator builder for the given symbol. The symbol may be the common name, or, in second precedence, the parsing
SYMB
.
- DEFAULT_CONNECTIVES: OrderedDict = {'AND': None, 'IMPLIEDBY': False, 'IMPLIES': False, 'NOT': None, 'OR': None}
Default connectives by common names. Set
None
as default to force users to specify it during init. SetFalse
to just mark the precedence position but not force users to specify an implementation during init. The order also determines the default order of precedence (higher index = higher precedence).