Morphisms¶
Base morphism classes, composition operations, and morphism utilities for all categorical structures.
morphisms
¶
Morphism hierarchy: V-enriched relations between finite sets.
A morphism from domain D to codomain C is represented as a tensor of shape (D.shape, C.shape) with entries in the lattice L of a quantale. Composition uses the quantale's operations (join over tensor product).
The hierarchy:
Morphism (abstract)
├── ObservedMorphism — fixed tensor (not learned)
├── LatentMorphism — nn.Parameter with sigmoid constraint
├── ComposedMorphism — f >> g (V-enriched composition)
├── ProductMorphism — f @ g (tensor / parallel product)
├── MarginalizedMorphism — contract codomain dims via join
├── FunctorMorphism — lazy image of a morphism under a functor
└── RepeatMorphism — runtime-variable iterated composition (T^n)
Morphism
¶
Bases: ABC
Abstract base for morphisms between finite sets.
Subclasses must implement tensor (returns the materialized
tensor with values in the quantale's lattice) and module
(returns the nn.Module tree for parameter collection).
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/core/morphisms.py
48 49 50 51 52 53 | |
tensor
abstractmethod
property
¶
tensor: Tensor
Materialize the morphism as a tensor with values in L.
module
abstractmethod
¶
module() -> Module
Return an nn.Module wrapping all learnable parameters.
Source code in src/quivers/core/morphisms.py
81 82 83 84 | |
__rshift__
¶
__rshift__(other: Morphism) -> ComposedMorphism
V-enriched composition: self >> other.
Composes self: A -> B with other: B -> C to yield a morphism A -> C, contracting over B using the quantale.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
Right morphism whose domain must match self's codomain.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComposedMorphism
|
The composed morphism. |
Source code in src/quivers/core/morphisms.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
__matmul__
¶
__matmul__(other: Morphism) -> ProductMorphism
Tensor (parallel) product: self @ other.
Given self: A -> B and other: C -> D, produces a morphism A×C -> B×D whose tensor is the outer product via the quantale's tensor_op.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
Right morphism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ProductMorphism
|
The product morphism. |
Source code in src/quivers/core/morphisms.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
marginalize
¶
marginalize(*sets: SetObject) -> MarginalizedMorphism
Marginalize (join-reduce) over codomain components.
The codomain must be a ProductSet containing the sets to marginalize over. The result has a codomain with those components removed. Uses the quantale's join operation.
| PARAMETER | DESCRIPTION |
|---|---|
*sets
|
Codomain components to marginalize over.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MarginalizedMorphism
|
The marginalized morphism. |
Source code in src/quivers/core/morphisms.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
ObservedMorphism
¶
ObservedMorphism(domain: SetObject, codomain: SetObject, data: Tensor, quantale: Quantale | None = None)
Bases: Morphism
A morphism with a fixed (non-learnable) tensor.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
data
|
Fixed tensor of shape (domain.shape, codomain.shape).
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/core/morphisms.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
LatentMorphism
¶
LatentMorphism(domain: SetObject, codomain: SetObject, init_scale: float = 0.5, quantale: Quantale | None = None)
Bases: Morphism
A learnable morphism backed by an nn.Parameter.
Stores unconstrained real-valued parameters and applies sigmoid to produce [0,1]-valued fuzzy relation entries.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
init_scale
|
Standard deviation of the normal initialization for the unconstrained parameters. Default 0.5 (sigmoid maps this to roughly uniform over [0.3, 0.7]).
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/core/morphisms.py
224 225 226 227 228 229 230 231 232 233 234 235 | |
ComposedMorphism
¶
Bases: Morphism
V-enriched composition of two morphisms.
Given left: A -> B and right: B -> C, produces A -> C by contracting over B using the quantale's compose method.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
Left morphism (applied first).
TYPE:
|
right
|
Right morphism (applied second).
TYPE:
|
Source code in src/quivers/core/morphisms.py
274 275 276 277 278 279 | |
ProductMorphism
¶
Bases: Morphism
Tensor (parallel) product of two morphisms.
Given left: A -> B and right: C -> D, produces A×C -> B×D. The tensor is the outer product of the two component tensors via the quantale's tensor_op.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
Left morphism.
TYPE:
|
right
|
Right morphism.
TYPE:
|
Source code in src/quivers/core/morphisms.py
325 326 327 328 329 330 | |
MarginalizedMorphism
¶
Bases: Morphism
Morphism with codomain dimensions marginalized via the quantale's join.
Given an inner morphism A -> B × C and a set B to marginalize, produces A -> C by join-reduction over B's dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
The morphism to marginalize.
TYPE:
|
sets_to_marginalize
|
Codomain components to marginalize over.
TYPE:
|
Source code in src/quivers/core/morphisms.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
FunctorMorphism
¶
Bases: Morphism
Lazy image of a morphism under a functor.
Recomputes the tensor on each access from the inner morphism, preserving gradient flow through the functor's map_tensor method. No additional parameters beyond those of the inner morphism.
| PARAMETER | DESCRIPTION |
|---|---|
functor
|
The functor that produced this morphism.
TYPE:
|
inner
|
The original morphism being mapped.
TYPE:
|
domain
|
The image of the inner morphism's domain under the functor.
TYPE:
|
codomain
|
The image of the inner morphism's codomain under the functor.
TYPE:
|
Source code in src/quivers/core/morphisms.py
438 439 440 441 442 443 | |
RepeatMorphism
¶
RepeatMorphism(inner: Morphism, n: int = 1)
Bases: Morphism
Runtime-variable iterated composition (matrix power).
Wraps an endomorphism f : X -> X and computes f^n at runtime, where n can be changed between calls. Uses repeated squaring for O(log n) quantale compositions.
For an endomorphism T : S -> S under a quantale, T^n is the
n-fold Kleisli composition. Under the product_fuzzy quantale
with stochastic matrices, this is standard matrix power.
| PARAMETER | DESCRIPTION |
|---|---|
inner
|
An endomorphism (domain must equal codomain).
TYPE:
|
n
|
Initial number of repetitions (default 1). Can be changed
later via the
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the inner morphism is not an endomorphism. |
ValueError
|
If n < 1. |
Examples:
>>> T = morphism(S, S)
>>> rep = RepeatMorphism(T, n=5)
>>> rep.tensor # computes T^5
>>> rep.n_steps = 10
>>> rep.tensor # now computes T^10
Source code in src/quivers/core/morphisms.py
501 502 503 504 505 506 507 508 509 510 511 | |
morphism
¶
morphism(domain: SetObject, codomain: SetObject, init_scale: float = 0.5, quantale: Quantale | None = None) -> LatentMorphism
Create a latent (learnable) morphism.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
init_scale
|
Initialization scale for unconstrained parameters.
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LatentMorphism
|
A learnable morphism. |
Source code in src/quivers/core/morphisms.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
observed
¶
observed(domain: SetObject, codomain: SetObject, data: Tensor, quantale: Quantale | None = None) -> ObservedMorphism
Create an observed (fixed) morphism.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source object.
TYPE:
|
codomain
|
Target object.
TYPE:
|
data
|
Fixed tensor.
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
A fixed morphism. |
Source code in src/quivers/core/morphisms.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
identity
¶
identity(obj: SetObject, quantale: Quantale | None = None) -> ObservedMorphism
Create the identity morphism on an object.
Returns an observed morphism obj -> obj whose tensor is the identity: unit on the diagonal, zero elsewhere.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object to create an identity for.
TYPE:
|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
The identity morphism. |
Source code in src/quivers/core/morphisms.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |