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.

apply_to_object(obj)[source]

Apply endofunctor to object.

apply_to_morphism(morphism)[source]

Apply endofunctor to morphism.

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.

__init__(activation_dim, gradient_dim, name='F_B')[source]
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’>]

apply_to_morphism(f)[source]

Apply endofunctor to morphism.

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.

__init__(activation_dim, gradient_dim, distribution_type='gaussian', name='F_SGD')[source]
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’>]

apply_to_morphism(f)[source]

Apply endofunctor to morphism.

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
structure_map: Callable[[X], Any]
endofunctor: EndofunctorProtocol
name: str = ''
id: UUID
evolve(state)[source]

Evolve state using structure map: γ(state).

This defines how states evolve in the generative system.

iterate(initial_state, steps)[source]

Iterate the coalgebra dynamics for multiple steps.

Parameters:
  • initial_state (X) – Starting state

  • steps (int) – Number of evolution steps

Returns:

List of states through evolution

Return type:

List[Any]

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

__init__(source, target, morphism, name='')[source]
apply(state)[source]

Apply morphism to state.

__call__(state)[source]

Make morphism callable.

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).

__init__(coalgebra1, coalgebra2, relation, name='')[source]
are_bisimilar(state1, state2)[source]

Check if two states are bisimilar.

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).

__init__(endofunctor, name='final')[source]
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,δ)

__init__(endofunctor, name='Coalg(F)')[source]
add_object(coalgebra)[source]

Add F-coalgebra as object.

add_morphism(morphism)[source]

Add coalgebra morphism.

compose(f_id, g_id)[source]

Compose coalgebra morphisms g ∘ f.

identity(obj_id)[source]

Get identity morphism for coalgebra.

get_final_coalgebra()[source]

Get or construct final coalgebra.

all_morphisms_to_final()[source]

Get unique morphisms from all objects to final coalgebra.

gaia.core.coalgebras.create_parameter_coalgebra(params, learning_rate=0.01, name='param_coalgebra')[source]

Create coalgebra for parameter evolution during training.

Parameters:
  • params (<MockTorch name='mock.Tensor' id='4349657872'>) – Initial parameters

  • learning_rate (float) – Learning rate for updates

  • name (str) – Name of coalgebra

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:
  • params (<MockTorch name='mock.Tensor' id='4349657872'>) – Initial parameters

  • learning_rate (float) – Learning rate

  • noise_level (float) – Noise level for stochastic updates

  • name (str) – Name of coalgebra

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:

BisimulationRelation

class gaia.core.coalgebras.SimplicialCoalgebra(simplicial_object, endofunctor, name='')[source]

Bases: object

Coalgebra structure over simplicial objects.

This connects the coalgebraic approach with the simplicial structure of GAIA, enabling hierarchical generative dynamics.

__init__(simplicial_object, endofunctor, name='')[source]
evolve_simplicial_dynamics(steps)[source]

Evolve simplicial coalgebra dynamics.