gaia.core.coalgebras module
Module: coalgebras Implements universal coalgebras for the GAIA framework.
Following Section 4.2 of the theoretical framework and Mahadevan (2024), this implements: 1. F-coalgebras (X,γ) with structure map γ: X → F(X) 2. Coalgebra morphisms h: (X,γ) → (Y,δ) satisfying F(h) ∘ γ = δ ∘ h 3. Bisimulations between coalgebras 4. Final coalgebras and Lambek’s theorem 5. Generative dynamics for state evolution
This is critical for modeling backpropagation as an endofunctor and implementing the coalgebraic approach to generative AI.
- class gaia.core.coalgebras.EndofunctorProtocol(*args, **kwargs)[source]
Bases:
Protocol
[X
]Protocol for endofunctors F: C → C.
- 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__(*args, **kwargs)
- class gaia.core.coalgebras.BackpropagationEndofunctor(activation_dim, gradient_dim, name='F_B')[source]
Bases:
object
Backpropagation endofunctor F_B: Param → Param.
Following Definition 11 from the paper: F_B(X) = A × B × X for backpropagation endofunctor where A represents activations, B represents gradients.
- apply_to_object(params)[source]
Apply F_B to parameter object: X → A × B × X.
- Parameters:
params (<MockTorch name='mock.Tensor' id='4349657872'>) – Parameter tensor
- Returns:
Tuple (activations, gradients, parameters)
- Return type:
Tuple[<MockTorch name=’mock.Tensor’ id=’4349657872’>, <MockTorch name=’mock.Tensor’ id=’4349657872’>, <MockTorch name=’mock.Tensor’ id=’4349657872’>]
- class gaia.core.coalgebras.SGDEndofunctor(activation_dim, gradient_dim, distribution_type='gaussian', name='F_SGD')[source]
Bases:
object
Stochastic gradient descent endofunctor F_SGD: Param → Param.
Following Definition 12 from the paper: F_SGD(X) = A × B × D(X) for stochastic backpropagation coalgebra where D is the distribution functor.
- apply_to_object(params)[source]
Apply F_SGD to parameter object: X → A × B × D(X).
- Parameters:
params (<MockTorch name='mock.Tensor' id='4349657872'>) – Parameter tensor
- Returns:
Tuple (activations, gradients, parameter_distribution)
- Return type:
Tuple[<MockTorch name=’mock.Tensor’ id=’4349657872’>, <MockTorch name=’mock.Tensor’ id=’4349657872’>, <MockTorch name=’mock.distributions.Distribution’ id=’4352708816’>]
- class gaia.core.coalgebras.FCoalgebra(state_space, structure_map, endofunctor, name='')[source]
Bases:
Generic
[X
]F-coalgebra (X,γ) with structure map γ: X → F(X).
This is the fundamental structure for modeling generative dynamics in the GAIA framework.
- state_space: X
- endofunctor: EndofunctorProtocol
- evolve(state)[source]
Evolve state using structure map: γ(state).
This defines how states evolve in the generative system.
- is_fixed_point(state, tolerance=1e-6)[source]
Check if state is a fixed point: γ(x) ≈ x.
This is relevant for final coalgebras and Lambek’s theorem.
- 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__(state_space, structure_map, endofunctor, name='')
- class gaia.core.coalgebras.CoalgebraMorphism(source, target, morphism, name='')[source]
Bases:
Generic
[X
,Y
]Morphism between F-coalgebras h: (X,γ) → (Y,δ).
Must satisfy the commutative diagram: F(h) ∘ γ = δ ∘ h
- 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.coalgebras.BisimulationRelation(coalgebra1, coalgebra2, relation, name='')[source]
Bases:
Generic
[X
]Bisimulation relation between coalgebras.
A relation R ⊆ S × T between coalgebras (S,γ) and (T,δ) such that if (s,t) ∈ R, then (γ(s), δ(t)) ∈ F(R).
- verify_bisimulation_property(state1, state2)[source]
Verify bisimulation property for given states.
If (s,t) ∈ R, then (γ(s), δ(t)) should be related by F(R).
- 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.coalgebras.FinalCoalgebra(endofunctor, name='final')[source]
Bases:
Generic
[X
]Final coalgebra - terminal object in category of F-coalgebras.
By Lambek’s theorem, final F-coalgebra is isomorphic to F(final).
- unique_morphism_from(source)[source]
Get unique morphism from any coalgebra to final coalgebra.
By definition of final object, there exists a unique morphism from any coalgebra to the final coalgebra.
- verify_lambek_property()[source]
Verify Lambek’s theorem: final coalgebra ≅ F(final coalgebra).
This checks that the structure map is an isomorphism.
- 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.coalgebras.CoalgebraCategory(endofunctor, name='Coalg(F)')[source]
Bases:
object
Category of F-coalgebras for a given endofunctor F.
Objects: F-coalgebras (X,γ) Morphisms: Coalgebra morphisms h: (X,γ) → (Y,δ)
- gaia.core.coalgebras.create_parameter_coalgebra(params, learning_rate=0.01, name='param_coalgebra')[source]
Create coalgebra for parameter evolution during training.
- Parameters:
- Returns:
F-coalgebra modeling parameter dynamics
- Return type:
FCoalgebra[<MockTorch name=’mock.Tensor’ id=’4349657872’>]
- gaia.core.coalgebras.create_stochastic_coalgebra(params, learning_rate=0.01, noise_level=0.01, name='stochastic_coalgebra')[source]
Create stochastic coalgebra for noisy parameter evolution.
- Parameters:
- Returns:
Stochastic F-coalgebra
- Return type:
FCoalgebra[<MockTorch name=’mock.Tensor’ id=’4349657872’>]
- gaia.core.coalgebras.create_bisimulation_between_coalgebras(coalgebra1, coalgebra2, tolerance=1e-3, name='')[source]
Create bisimulation relation between two coalgebras.
- Parameters:
coalgebra1 (FCoalgebra) – First coalgebra
coalgebra2 (FCoalgebra) – Second coalgebra
tolerance (float) – Tolerance for state comparison
name (str) – Name of bisimulation
- Returns:
Bisimulation relation
- Return type: