gaia.core.universal_coalgebras module
Universal Coalgebras for GAIA Framework
Implements Section 3 from GAIA paper: “Backpropagation as an Endofunctor: Generative AI using Universal Coalgebras”
THEORETICAL FOUNDATIONS: - Definition 7: F-coalgebra (A, α) with structure map α: A → F(A) - Definition 9: Coalgebra homomorphisms with commutative diagrams - Definition 10: Bisimulations between coalgebras - Lambek’s Theorem: Final coalgebras as fixed points - Applications to generative AI, LLMs, diffusion models
This module provides the categorical foundation for all generative AI in GAIA.
- class gaia.core.universal_coalgebras.Endofunctor[source]
-
Abstract base class for endofunctors F: C → C
From (MAHADEVAN,2024) Definition 7: Endofunctor required for F-coalgebras
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.universal_coalgebras.PowersetFunctor[source]
Bases:
Endofunctor
[set
]Powerset functor F: S ⇒ P(S) From (MAHADEVAN,2024) Section 3.1
Models context-free grammars, finite state machines, and basic generative models.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.universal_coalgebras.StreamFunctor[source]
Bases:
Endofunctor
[List
]Stream functor Str: Set → Set, Str(X) = ℕ × X from GAIA paper
Models infinite data streams for generative AI (LLMs, sequence models).
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.universal_coalgebras.NeuralFunctor(activation_dim, bias_dim)[source]
Bases:
Endofunctor
[<MockTorch name=’mock.Tensor’ id=’4349657872’>]Neural network endofunctor for backpropagation coalgebras
Models F_B(X) = A × B × X From (MAHADEVAN,2024) Definition 11 where A = activations, B = biases, X = parameters
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.universal_coalgebras.FCoalgebra(carrier, structure_map, endofunctor, name=None)[source]
Bases:
Generic
[A
]F-coalgebra (A, α) From (MAHADEVAN,2024) Definition 7
Consists of: - carrier: Object A in category C - structure_map: Arrow α: A → F(A) defining dynamics
- carrier: A
- endofunctor: Endofunctor[A]
- evolve(state)[source]
Evolve state using structure map α: A → F(A)
This is the core dynamics of the coalgebra - how states transition.
- iterate(initial_state, steps)[source]
Iterate coalgebra dynamics for multiple steps
Generates trajectory: state → α(state) → α²(state) → …
- is_fixed_point(state, tolerance=1e-6)[source]
Check if state is a fixed point: α(state) = state
Related to Lambek’s theorem for final coalgebras.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- __init__(carrier, structure_map, endofunctor, name=None)
- class gaia.core.universal_coalgebras.CoalgebraHomomorphism(source, target, morphism)[source]
Bases:
Generic
[A
,B
]Homomorphism between F-coalgebras From (MAHADEVAN,2024) Definition 9
Arrow f: A → B such that the diagram commutes: A –α–> F(A) | | f F(f) | | v v B –β–> F(B)
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.universal_coalgebras.Bisimulation(coalgebra1, coalgebra2, relation)[source]
Bases:
Generic
[A
,B
]Bisimulation between coalgebras From (MAHADEVAN,2024) Definition 10
Relation R ⊆ S × T with structure map α_R: R → F(R) such that projections π₁, π₂ are homomorphisms.
Critical for comparing generative AI models (e.g., two LLMs).
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- class gaia.core.universal_coalgebras.GenerativeCoalgebra(model, optimizer, loss_fn)[source]
Bases:
FCoalgebra
[<MockTorch name=’mock.Tensor’ id=’4349657872’>]Specialized coalgebra for generative AI models
Implements backpropagation as F-coalgebra From (MAHADEVAN,2024) Section 3.2
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- evolve(state)
Evolve state using structure map α: A → F(A)
This is the core dynamics of the coalgebra - how states transition.
- is_fixed_point(state, tolerance=1e-6)
Check if state is a fixed point: α(state) = state
Related to Lambek’s theorem for final coalgebras.
- iterate(initial_state, steps)
Iterate coalgebra dynamics for multiple steps
Generates trajectory: state → α(state) → α²(state) → …
- carrier: A
- endofunctor: Endofunctor[A]
- class gaia.core.universal_coalgebras.CoalgebraCategory[source]
Bases:
object
Category of F-coalgebras with homomorphisms as morphisms
Provides categorical structure for organizing generative AI models.
- add_homomorphism(source_name, target_name, morphism)[source]
Add homomorphism as morphism in category
- gaia.core.universal_coalgebras.create_llm_coalgebra(model, optimizer, loss_fn)[source]
Create coalgebra for Large Language Model