Tensor Operations¶
Noisy-OR contraction and reduction, noisy-AND reduction, and componentwise tensor lifting.
tensor_ops
¶
Noisy-OR tensor contraction and marginalization.
The noisy-OR of probabilities p_1, ..., p_n is defined as:
noisy_or(p_1, ..., p_n) = 1 - prod_i (1 - p_i)
This module implements tensor contraction (analogous to matrix multiplication) where the summation is replaced by noisy-OR and the product is standard multiplication. Given tensors M of shape (D, S) and N of shape (S, C), the contraction over the shared dimensions S produces a tensor of shape (D, C) with entries:
result[d..., c...] = 1 - prod_{s...} (1 - M[d..., s...] * N[s..., c...])
All operations use log-space for numerical stability.
noisy_or_contract
¶
Contract two tensors via noisy-OR over shared dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
Left tensor of shape (domain, shared).
TYPE:
|
n
|
Right tensor of shape (shared, codomain).
TYPE:
|
n_contract
|
Number of trailing dimensions of m (= leading dimensions of n) to contract over.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Result of shape (domain, codomain). |
Examples:
>>> M = torch.tensor([[0.5, 0.3], [0.8, 0.1]])
>>> N = torch.tensor([[0.4, 0.6], [0.7, 0.2]])
>>> result = noisy_or_contract(M, N, n_contract=1)
>>> result.shape
torch.Size([2, 2])
Source code in src/quivers/core/tensor_ops.py
noisy_or_reduce
¶
Marginalize (reduce) a tensor over dimensions using noisy-OR.
Computes 1 - prod_i (1 - t_i) along the specified dimension(s). This is the fuzzy analogue of existential quantification (∃).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Input tensor with values in [0, 1].
TYPE:
|
dim
|
Dimension(s) to reduce over.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Reduced tensor with the specified dimensions removed. |
Source code in src/quivers/core/tensor_ops.py
noisy_and_reduce
¶
Reduce a tensor over dimensions using product (fuzzy AND).
Computes prod_i t_i along the specified dimension(s). This is the fuzzy analogue of universal quantification (∀).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Input tensor with values in [0, 1].
TYPE:
|
dim
|
Dimension(s) to reduce over.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Reduced tensor with the specified dimensions removed. |
Source code in src/quivers/core/tensor_ops.py
componentwise_lift
¶
Lift a morphism tensor to the k-fold componentwise product.
This is the functorial action of the free monoid functor on morphisms. Given f of shape (|A|, |B|), produces f^k of shape (|A|,)k + (|B|,)k where:
f^k[a1, ..., ak, b1, ..., bk] = ⊗_i f[ai, bi]
The tensor product ⊗ is determined by the algebra (defaults to ProductFuzzyAlgebra, where ⊗ = ordinary multiplication).
Categorically, this is the monoidal functor action: the free monoid on objects sends A to A = 1 + A + A×A + ..., and on morphisms sends f: A → B to f: A → B acting componentwise on each length stratum.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Morphism tensor of shape (|A|, |B|) — a 2D fuzzy relation.
TYPE:
|
k
|
String length (number of components). Must be >= 0.
TYPE:
|
algebra
|
The algebra whose tensor_op is used for the componentwise product. If None, defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Lifted tensor of shape (|A|,)k + (|B|,)k. For k=0, returns a tensor of shape (1, 1) filled with the algebra's unit value. For k=1, returns f unchanged. |