Transforms¶
Transformations of stochastic morphisms.
transforms
¶
Transformations on stochastic morphisms.
Provides operations like conditioning, mixing, factoring, and normalization that wrap existing morphisms into new ones.
ConditionedMorphism
¶
Bases: Morphism
A morphism conditioned on evidence via Bayesian update.
Given a morphism f: A → B and evidence tensor e over B, produces f|e: A → B where:
f|e(a, b) = f(a, b) · e(b) / Σ_{b'} f(a, b') · e(b')
This is pointwise multiplication followed by row-renormalization.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
The unconditioned morphism.
TYPE:
|
evidence
|
Evidence tensor broadcastable to the codomain shape. Values should be non-negative (likelihoods).
TYPE:
|
Source code in src/quivers/stochastic/transforms.py
MixtureMorphism
¶
Bases: Morphism
Convex combination of two morphisms with a learnable weight.
Given morphisms f, g: A → B and a mixing weight p ∈ [0, 1]:
mix(p, f, g)(a, b) = p · f(a, b) + (1 - p) · g(a, b)
The weight p is parameterized via a sigmoid-transformed scalar.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
First component morphism.
TYPE:
|
right
|
Second component morphism (same domain and codomain).
TYPE:
|
learnable
|
If True (default), the mixing weight is a learnable parameter. If False, it is fixed at the initial value.
TYPE:
|
init_logit
|
Initial value for the unconstrained logit of p. Default 0.0 (p = 0.5).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/stochastic/transforms.py
FactoredMorphism
¶
Bases: Morphism
A morphism with pointwise likelihood weighting.
Given a morphism f: A → B and a weight tensor w over B:
factor(f, w)(a, b) = f(a, b) · w(b)
This is unnormalized: the result is not necessarily row-stochastic.
Use normalize afterward if normalization is needed.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
The base morphism.
TYPE:
|
weights
|
Non-negative weight tensor broadcastable to the codomain shape.
TYPE:
|
Source code in src/quivers/stochastic/transforms.py
NormalizedMorphism
¶
NormalizedMorphism(inner: Morphism)
Bases: Morphism
A morphism with row-renormalized tensor.
Divides each codomain fiber by its sum so that rows sum to 1.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
The unnormalized morphism.
TYPE:
|
Source code in src/quivers/stochastic/transforms.py
condition
¶
condition(f: Morphism, evidence: Tensor) -> ConditionedMorphism
Condition a morphism on evidence (Bayesian update).
Computes the posterior: f|e(a, b) ∝ f(a, b) · e(b), renormalized so rows sum to 1.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
The prior morphism A → B.
TYPE:
|
evidence
|
Non-negative evidence tensor over B.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ConditionedMorphism
|
The conditioned morphism. |
Examples:
>>> A = FinSet(name="A", cardinality=2)
>>> B = FinSet(name="B", cardinality=3)
>>> f = StochasticMorphism(A, B)
>>> e = torch.tensor([1.0, 0.0, 1.0]) # observe B != 1
>>> g = condition(f, e)
>>> g.tensor.sum(dim=-1) # still row-stochastic
Source code in src/quivers/stochastic/transforms.py
mix
¶
mix(left: Morphism, right: Morphism, learnable: bool = True, init_logit: float = 0.0) -> MixtureMorphism
Create a convex combination (mixture) of two morphisms.
Produces h: A → B where h(a,b) = p·f(a,b) + (1-p)·g(a,b). The mixing weight p is learnable by default.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
First component.
TYPE:
|
right
|
Second component (same type as left).
TYPE:
|
learnable
|
Whether the mixing weight is trainable.
TYPE:
|
init_logit
|
Initial logit value for the mixing weight.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MixtureMorphism
|
The mixture morphism. |
Source code in src/quivers/stochastic/transforms.py
factor
¶
factor(f: Morphism, weights: Tensor) -> FactoredMorphism
Apply pointwise likelihood weighting to a morphism.
Computes: factor(f, w)(a, b) = f(a, b) · w(b). The result is unnormalized.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
The base morphism.
TYPE:
|
weights
|
Non-negative weight tensor over the codomain.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FactoredMorphism
|
The weighted morphism. |
Source code in src/quivers/stochastic/transforms.py
normalize
¶
normalize(f: Morphism) -> NormalizedMorphism
Renormalize a morphism so codomain fibers sum to 1.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
The unnormalized morphism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NormalizedMorphism
|
The row-normalized morphism. |