BoolTorchOrNumpyOperation
- class hybrid_learning.fuzzy_logic.tnorm_connectives.boolean.BoolTorchOrNumpyOperation(*in_keys, bool_thresh=None, **kwargs)[source]
Bases:
TorchOrNumpyOperation,ABCBase class for Boolean operations that threshold their inputs before operation.
Public Data Attributes:
Settings to reproduce the instance.
Defaults used for
settings.Inherited from : py: class:Merge
SYMBThe string symbol of this class (override for sub-classes).
ARITYThe arity of the operation.
IS_COMMUTATIVEWhether instances are equivalent to ones with permuted
in_keys.is_variadicWhether the instance is variadic.
Settings to reproduce the instance.
Defaults used for
settings.pretty_op_symbName of the operation symbol suitable for filenames etc.
childrenThe input keys which are child operations.
all_childrenAll children operations in the flattened computational tree, sorted depth first.
constsThe constant string keys in the input keys.
operation_keysThe list of keys used for this parent operation in original order (constants and children output keys).
all_in_keysAll string input keys both of self and of all child operations.
all_out_keysOutput keys of self and all child operations.
Inherited from : py: class:DictTransform
Settings to reproduce the instance.
Inherited from : py: class:Transform
IDENTITY_CLASSThe identity class or classes for composition / addition.
Settings to reproduce the instance.
Public Methods:
numpy_operation(*inputs[, bool_thresh])Threshold the
inputsatbool_threshand apply operation.torch_operation(*inputs[, bool_thresh])AND on pytorch tensors.
Inherited from : py: class:TorchOrNumpyOperation
operation(annotation_vals)Operation on either torch tensors or Booleans, numpy arrays and numbers.
Inherited from : py: class:TorchOperation
operation(annotation_vals)Operation on either torch tensors or Booleans, numpy arrays and numbers.
Inherited from : py: class:Merge
to_infix_notation([sort_key, ...])Return an infix str encoding equal for differently sorted operations.
to_str(**infix_notation_kwargs)Alias for
to_infix_notation().to_pretty_str(**infix_notation_kwargs)Same as
to_str()but using pretty operation names suitable for filenames etc.to_repr([settings, defaults, sort_key, ...])Return str representation which can be used to reproduce and compare the instance.
treerecurse_replace_keys(**replace_map)Return a new formula with all occurences of variables in
replace_mapreplaced and else identical settings.treerecurse(fun)Apply the given function recursively to this and all children instances.
apply_to(annotations[, keep_keys])Apply this operation to the
annotationsdict.variadic_apply_to(annotations)Return the result of operation on the values/items of a mapping or sequence of arbitrary length.
operation(annotation_vals)Operation on either torch tensors or Booleans, numpy arrays and numbers.
Inherited from : py: class:DictTransform
apply_to(annotations[, keep_keys])Apply this operation to the
annotationsdict.Inherited from : py: class:Transform
apply_to(annotations[, keep_keys])Apply this operation to the
annotationsdict.Special Methods:
__init__(*in_keys[, bool_thresh])Init.
Inherited from : py: class:Merge
__init__(*in_keys[, bool_thresh])Init.
__str__()Return str(self).
__repr__()Call
to_repr()without sorting.__eq__(other)Two merge operations are considered equal, if their normalized representations coincide.
__copy__()Return a deep copy of self using settings.
__call__(annotations[, keep_keys])Call method modifying a given dictionary.
Inherited from : py: class:DictTransform
__call__(annotations[, keep_keys])Call method modifying a given dictionary.
Inherited from : py: class:Transform
__repr__()Call
to_repr()without sorting.__eq__(other)Two merge operations are considered equal, if their normalized representations coincide.
__copy__()Return a deep copy of self using settings.
__add__(other)Return a flat composition of
selfwithother.__radd__(other)Return a flat composition of
otherandself.__call__(annotations[, keep_keys])Call method modifying a given dictionary.
- __init__(*in_keys, bool_thresh=None, **kwargs)[source]
Init.
Hand over input keys either as str or as a Merge operation of str.
- Parameters
in_keys – sequence of either
Mergeoperation instances or strings with placeholders for the input keysout_key – key for the output of this operation; used to init
out_keyoverwrite – on call, whether to overwrite the value at
out_keyin the given dict if the key already exists; raise if key exists andoverwriteis true; saved inoverwrite.replace_none – if not
None, the value to replace anyNonevalues with; seereplace_nonesymb – override the
SYMBfor this instancekeep_keys – intermediate output keys to add to call output; see
keep_keyscache_duplicates – whether outputs of children with identical keys should be cached and reused; see
cache_duplicates_variadic – the preferred way to specify this argument is
variadic_(); see there for details
- numpy_operation(*inputs, bool_thresh=None)[source]
Threshold the
inputsatbool_threshand apply operation. Default forbool_threshfirst isbool_thresh(if available), then 0.5.
- bool_thresh: float
Threshold in [0,1] to apply to masks for binarization before operation. Defaults to
0.5.
- cache_duplicates: bool
Whether to cache duplicate child operation outputs with duplicate out_key. If set to false, all children and children children are evaluated and the values of duplicate
out_keysare evaluated several times and overwritten, possibly leading to more computational time while using less memory. Note that the order of children execution is determined by their order inin_keys, depth first for nested operations.
- in_keys: Sequence[Union[str, 'Merge']]
The keys of segmentation masks to unite in given order. Keys are either constant strings or a merge operation.
- keep_keys: Optional[Collection[str]]
The keys of intermediate outputs in
all_out_keyswhich should be added to the return of a call. Default (Noneor empty collection): duplicate children outputs are cached but not returned to save memory.
- out_key: str
The key to use to store the merge output in the annotations dict. Take care to not accidentally overwrite existing keys (cf.
overwrite).
- overwrite: Union[bool, Literal['noop']]
Whether to overwrite a value in the input dictionary when applying this operation. The operation is defined in
operation(). The key that may be overwritten is stored inout_key. An exception is raised if this isFalseand the key exists. If set to'noop'andout_keyis in the given annotations dict, it is returned unchanged.
- replace_none: Optional[Any]
If not
None, any receivedNonevalue is replaced by the given value. This is done only for computation, theNonevalue in the received dict is left unchanged. Key-value pairs withNonevalue may come from the input or from child operations.