Stochastic Quantale¶
The [0,1] quantale for probabilistic morphisms.
quantale
¶
Sum-product composition quantale for stochastic matrices.
Implements the MarkovQuantale which governs composition of finite stochastic matrices via sum-product (matrix multiplication).
MarkovQuantale
¶
Bases: Quantale
Sum-product composition for stochastic matrices.
Implements the composition rule of FinStoch:
(g ∘ f)(a, c) = Σ_b f(a, b) · g(b, c)
This is standard matrix multiplication. Formally:
⊗ = product: a ⊗ b = a · b
⋁ = sum: ⋁_i x_i = Σ_i x_i
⋀ = product: ⋀_i x_i = Π_i x_i
¬ = complement: ¬a = 1 - a
I = 1.0
⊥ = 0.0
Note
This is not a true quantale in the lattice-theoretic sense because Σ is not idempotent (a ⋁ a = 2a ≠ a). It is a commutative semiring ([0,∞), +, ×, 0, 1) whose composition formula matches the quantale interface. The important property is that composition of row-stochastic matrices yields row-stochastic matrices.
tensor_op
¶
tensor_op(a: Tensor, b: Tensor) -> Tensor
Pointwise product.
Source code in src/quivers/stochastic/quantale.py
44 45 46 | |
join
¶
join(t: Tensor, dim: int | tuple[int, ...]) -> Tensor
Summation (marginalization in probability).
Source code in src/quivers/stochastic/quantale.py
48 49 50 51 52 53 | |
meet
¶
meet(t: Tensor, dim: int | tuple[int, ...]) -> Tensor
Product (joint probability under independence).
Source code in src/quivers/stochastic/quantale.py
55 56 57 58 59 60 61 62 63 64 65 | |
negate
¶
negate(t: Tensor) -> Tensor
Complement: ¬p = 1 - p.
Source code in src/quivers/stochastic/quantale.py
67 68 69 | |
compose
¶
compose(m: Tensor, n: Tensor, n_contract: int) -> Tensor
Sum-product composition (matrix multiplication).
Computes: result[d..., c...] = Σ_{s...} m[d..., s...] · n[s..., c...]
Uses the default quantale compose, which expands + tensor_op + join. For 2D tensors this is equivalent to torch.mm.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
Left stochastic matrix of shape (domain, shared).
TYPE:
|
n
|
Right stochastic matrix of shape (shared, codomain).
TYPE:
|
n_contract
|
Number of shared dimensions.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Composed matrix of shape (domain, codomain). |
Source code in src/quivers/stochastic/quantale.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |