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.

StochasticMorphism

StochasticMorphism(domain: SetObject, codomain: SetObject, temperature: float = 1.0)

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: SetObject

codomain

Target object.

TYPE: SetObject

temperature

Softmax temperature. Lower values → sharper distributions. Default 1.0.

TYPE: float DEFAULT: 1.0

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
48
49
50
51
52
53
54
55
56
57
58
59
60
def __init__(
    self,
    domain: SetObject,
    codomain: SetObject,
    temperature: float = 1.0,
) -> None:
    super().__init__(domain, codomain, quantale=MARKOV)
    self._temperature = temperature

    shape = self.tensor_shape
    self._module = _MorphismModule()
    logits = nn.Parameter(torch.randn(shape) * 0.1)
    self._module.register_parameter("logits", logits)

logits property

logits: Parameter

Unconstrained logit parameters.

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: SetObject

codomain

Target object.

TYPE: SetObject

temperature

Softmax temperature.

TYPE: float DEFAULT: 1.0

RETURNS DESCRIPTION
StochasticMorphism

A learnable row-stochastic morphism.

Source code in src/quivers/stochastic/morphisms.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def stochastic(
    domain: SetObject,
    codomain: SetObject,
    temperature: float = 1.0,
) -> StochasticMorphism:
    """Create a learnable stochastic morphism (Markov kernel).

    Parameters
    ----------
    domain : SetObject
        Source object.
    codomain : SetObject
        Target object.
    temperature : float
        Softmax temperature.

    Returns
    -------
    StochasticMorphism
        A learnable row-stochastic morphism.
    """
    return StochasticMorphism(domain, codomain, temperature=temperature)