Stochastic Morphisms¶
Stochastic relations, kernels, and morphisms for probabilistic computation.
morphisms
¶
Stochastic morphisms: learnable Markov kernels via softmax.
Provides StochasticMorphism for row-stochastic linear maps and the stochastic() factory function.
CategoricalMorphism
module-attribute
¶
CategoricalMorphism = StochasticMorphism
An alias of StochasticMorphism named for its categorical rows.
StochasticMorphism
¶
Bases: Morphism
A learnable Markov kernel backed by softmax-normalized parameters.
Stores unconstrained real-valued logits and applies softmax along the codomain dimensions to produce a row-stochastic tensor (each fiber over a domain element sums to 1).
This is a morphism in FinStoch: a stochastic map A → B.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
temperature
|
Softmax temperature. Lower values → sharper distributions. Default 1.0.
TYPE:
|
Examples:
>>> A = FinSet(name="A", cardinality=3)
>>> B = FinSet(name="B", cardinality=4)
>>> f = StochasticMorphism(A, B)
>>> t = f.tensor # shape (3, 4), rows sum to 1
>>> t.sum(dim=-1) # tensor([1., 1., 1.])
Source code in src/quivers/stochastic/morphisms.py
tensor
property
¶
tensor: Tensor
Row-stochastic tensor via softmax over codomain dimensions.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Tensor of shape (domain.shape, codomain.shape) where each codomain fiber sums to 1. |
stochastic
¶
stochastic(domain: SetObject, codomain: SetObject, temperature: float = 1.0) -> StochasticMorphism
Create a learnable stochastic morphism (Markov kernel).
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
temperature
|
Softmax temperature.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StochasticMorphism
|
A learnable row-stochastic morphism. |
Source code in src/quivers/stochastic/morphisms.py
The Markov algebra¶
quivers.stochastic re-exports MarkovAlgebra and its singleton MARKOV, the algebra
stochastic morphisms compose under, from quivers.core.algebras.
Stochastic morphisms: Markov kernels over finite sets.
This module provides the probabilistic layer for quivers, implementing the category FinStoch of finite sets and stochastic maps (Markov kernels). This is the Kleisli category of the Giry monad restricted to finite sets, where:
- Objects are finite sets (same as the base category).
- Morphisms A -> B are stochastic matrices: tensors of shape (|A|, |B|) whose rows sum to 1.
- Composition is standard matrix multiplication.
- Identity is the Kronecker delta.
The package also re-exports MarkovAlgebra and its singleton
MARKOV from quivers.core.algebras, the algebra these morphisms
compose under.
Submodules
morphisms : StochasticMorphism, CategoricalMorphism families : Discretized distribution families transforms : condition, mix, factor, normalize queries : prob, marginal_prob, expectation giry : GiryMonad, FinStoch categories : Category types including atoms, slashes, products, unit, modals semiring : Chart semiring abstractions (LogProb, Viterbi, Boolean, Counting) schema : Composable rule schemas (functors CategorySystem -> RuleSystem) rules : Rule systems and the CCG / Lambek presets span : Span-based CKY components (LexicalAxiom, BinarySpanDeduction, etc.) parsers, ccg, lambek : Chart parsers inside : The inside algorithm over a rule system agenda : The agenda-driven weighted-deduction engine effect_lifts : Effect-lifted rule schemas for deduction systems deduction : Abstract weighted deductive system framework and its operations stdlib : Pre-registered deduction systems
MARKOV
module-attribute
¶
MARKOV = MarkovAlgebra()
The MarkovAlgebra singleton, composing stochastic matrices.