gaia.integration package

GAIA Integration Layer - Resolves Circular Imports

This module provides a clean integration layer that resolves circular import issues and provides a unified interface to all GAIA components.

class gaia.integration.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

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)
evolve(state)[source]

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)[source]

Check if state is a fixed point: α(state) = state

Related to Lambek’s theorem for final coalgebras.

iterate(initial_state, steps)[source]

Iterate coalgebra dynamics for multiple steps

Generates trajectory: state → α(state) → α²(state) → …

name: str | None = None
carrier: A
structure_map: Callable[[A], A]
endofunctor: Endofunctor[A]
class gaia.integration.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]): ….

__init__(source, target, morphism)[source]
apply(state)[source]

Apply homomorphism to state

class gaia.integration.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]): ….

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

Check if two states are bisimilar

class gaia.integration.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]): ….

__init__(model, optimizer, loss_fn)[source]
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) → …

name: str | None = None
carrier: A
structure_map: Callable[[A], A]
endofunctor: Endofunctor[A]
class gaia.integration.CoalgebraCategory[source]

Bases: object

Category of F-coalgebras with homomorphisms as morphisms

Provides categorical structure for organizing generative AI models.

__init__()[source]
add_coalgebra(name, coalgebra)[source]

Add coalgebra as object in category

add_homomorphism(source_name, target_name, morphism)[source]

Add homomorphism as morphism in category

compose_morphisms(first, second)[source]

Compose two homomorphisms if composable

Implements categorical composition in coalgebra category.

find_bisimulations()[source]

Find bisimulations between coalgebras in category

Critical for comparing different generative AI models.

class gaia.integration.Endofunctor[source]

Bases: ABC, Generic[A]

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]): ….

abstractmethod apply(obj)[source]

Apply functor to object: F(A) → F(A)

abstractmethod fmap(morphism)[source]

Apply functor to morphism: F(f: A → B) → F(A) → F(B)

class gaia.integration.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]): ….

apply(obj)[source]

Return powerset P(S) = {A | A ⊆ S}

fmap(morphism)[source]

Apply morphism to each element of powerset

class gaia.integration.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]): ….

apply(obj)[source]

Return (index, stream) pair

fmap(morphism)[source]

Apply morphism to stream component

class gaia.integration.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]): ….

__init__(activation_dim, bias_dim)[source]
apply(params)[source]

Return (activations, biases, parameters) triple

fmap(morphism)[source]

Apply morphism to parameter component

gaia.integration.create_llm_coalgebra(model, optimizer, loss_fn)[source]

Create coalgebra for Large Language Model

gaia.integration.create_diffusion_coalgebra(model, noise_schedule)[source]

Create coalgebra for diffusion model

Models probabilistic coalgebra over ODEs from GAIA paper

gaia.integration.create_transformer_coalgebra(attention_heads, hidden_dim)[source]

Create coalgebra for Transformer model

Will be extended with categorical transformer structure in later tasks.

class gaia.integration.GeneralizedMetricSpace(objects, distance_function, name=None)[source]

Bases: Generic[X]

Generalized metric space (X, d) From (MAHADEVAN,2024) Section 6.7

Properties: 1. d(x,x) = 0 (reflexivity) 2. d(x,z) ≤ d(x,y) + d(y,z) (triangle inequality)

NOT required: - Symmetry: d(x,y) = d(y,x) - Identity: d(x,y) = 0 ⟹ x = y - Finiteness: d(x,y) < ∞

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__(objects, distance_function, name=None)[source]
distance(x, y)[source]

Compute distance d(x,y) in generalized metric space

class gaia.integration.EnrichedCategory[source]

Bases: object

[0,∞]-enriched category from GAIA paper

Objects are non-negative real numbers including ∞ Morphisms exist r → s iff r ≤ s Monoidal structure via addition: r ⊗ s = r + s

__init__()[source]
add_object(r)[source]

Add object r ∈ [0,∞] to category

categorical_coproduct(r, s)[source]

Categorical coproduct: r ⊔ s = min{r,s}

categorical_product(r, s)[source]

Categorical product: r ⊓ s = max{r,s}

has_morphism(r, s)[source]

Check if morphism r → s exists (i.e., r ≤ s)

internal_hom(r, s)[source]

Internal hom [0,∞](r,s) for compact closed structure

tensor_product(r, s)[source]

Monoidal structure: r ⊗ s = r + s

class gaia.integration.YonedaEmbedding(metric_space)[source]

Bases: Generic[X]

Yoneda embedding y: X → X̂ for generalized metric spaces

From (MAHADEVAN,2024) Theorem 8: y(x) = X(-,x): X^op → [0,∞]

Key properties: 1. Isometric: X(x,x’) = X̂(y(x), y(x’)) 2. Universal representer: objects determined by interactions 3. Non-expansive function into presheaf category

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__(metric_space)[source]
embed(x)[source]

Yoneda embedding: x ↦ X(-,x)

Returns presheaf representing x by its interactions with all objects

presheaf_distance(presheaf1, presheaf2)[source]

Compute distance in presheaf category X̂

X̂(φ,ψ) = sup_y |φ(y) - ψ(y)| for presheaves φ,ψ

universal_property(x, phi)[source]

Universal property: X̂(X(-,x), φ) = φ(x)

This is the metric Yoneda lemma from GAIA paper

verify_isometry(x, x_prime, tolerance=1e-6)[source]

Verify isometric property: X(x,x’) = X̂(y(x), y(x’))

This is Theorem 9 from GAIA paper

class gaia.integration.MetricYonedaApplications[source]

Bases: object

Applications of Metric Yoneda Lemma to AI/ML problems

From GAIA paper: “discriminate two objects (probability distributions, images, text documents) by comparing them in suitable metric space”

static create_image_metric_space(images)[source]

Create metric space for images using perceptual distance

Non-symmetric distance for image comparison

static create_neural_embedding_space(embeddings)[source]

Create metric space for neural embeddings (e.g., from LLMs)

Non-symmetric distance based on attention-like mechanism

static create_probability_metric_space(distributions)[source]

Create metric space for probability distributions

Using Wasserstein-like distance (non-symmetric)

static create_text_metric_space(documents)[source]

Create metric space for text documents using edit distance

Example From (MAHADEVAN,2024) Section 6.7 for string comparison

class gaia.integration.UniversalRepresenter(metric_space)[source]

Bases: object

Universal representer using Metric Yoneda Lemma

Enables representing any object by its interactions with other objects, crucial for foundation models and generative AI.

__init__(metric_space)[source]
compare_objects(obj1, obj2)[source]

Compare two objects using universal representations

Returns both original and representational distances

find_nearest_neighbors(query_obj, k=5)[source]

Find k nearest neighbors using universal representation

Useful for retrieval in foundation models

represent(obj)[source]

Create universal representation of object

Returns Yoneda embedding as universal representer

gaia.integration.create_llm_metric_space(token_sequences)[source]

Create metric space for LLM token sequences

gaia.integration.create_causal_metric_space(causal_graphs)[source]

Create metric space for causal graphs (DAGs)

class gaia.integration.IntegratedFuzzySet(elements, membership_fn, name='fuzzy_set')[source]

Bases: GAIAComponent

Integrated fuzzy set implementing sheaf structure on [0,1].

__init__(elements, membership_fn, name='fuzzy_set')[source]
alpha_cut(alpha)[source]

Return α-cut {x | μ(x) ≥ α}.

get_membership(element)[source]

Get membership degree for element.

initialize()[source]

Initialize fuzzy set by computing membership for all elements.

merge_with(other, t_conorm=TConorm.MAXIMUM)[source]

Merge with another fuzzy set using t-conorm.

support()[source]

Return support set {x | μ(x) > 0}.

update(state)[source]

Update fuzzy set based on training state.

validate()[source]

Validate fuzzy set properties.

class gaia.integration.IntegratedSimplex(dimension, name, components=None, membership=1.0, payload=None)[source]

Bases: SimplicialStructure

Integrated simplex with fuzzy membership and categorical structure.

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__(dimension, name, components=None, membership=1.0, payload=None)[source]
degeneracy_map(i)[source]

Apply i-th degeneracy map σᵢ preserving membership.

property dimension: int

Dimension of the simplex.

face_map(i)[source]

Apply i-th face map δᵢ with membership coherence.

verify_simplicial_identities()[source]

Verify simplicial identities hold.

class gaia.integration.IntegratedFuzzySimplicialSet(name, max_dimension=3)[source]

Bases: GAIAComponent

Integrated fuzzy simplicial set combining fuzzy and simplicial structures.

__init__(name, max_dimension=3)[source]
add_simplex(dimension, simplex_data, membership=1.0)[source]

Add a simplex with given membership.

get_membership(dimension, simplex_data)[source]

Get membership degree for a simplex.

initialize()[source]

Initialize all fuzzy sets.

merge_with(other, t_conorm=TConorm.MAXIMUM)[source]

Merge with another fuzzy simplicial set.

update(state)[source]

Update fuzzy simplicial set based on training state.

validate()[source]

Validate fuzzy simplicial set properties.

class gaia.integration.IntegratedCoalgebra(initial_state, endofunctor, name='coalgebra')[source]

Bases: Coalgebra[<MockTorch name=’mock.Tensor’ id=’4349657872’>], GAIAComponent

Integrated coalgebra for GAIA training dynamics.

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__(initial_state, endofunctor, name='coalgebra')[source]
evolve(state)

Evolve state using structure map: γ(state).

initialize()[source]

Initialize coalgebra.

is_bisimilar(other, relation)[source]

Check bisimilarity with another coalgebra.

iterate_dynamics(steps)[source]

Iterate coalgebra dynamics for multiple steps.

update(state)[source]

Update coalgebra with new training state.

validate()[source]

Validate coalgebra properties.

class gaia.integration.TConorm(value)[source]

Bases: Enum

T-conorms for fuzzy set operations.

apply(a, b)[source]

Apply the t-conorm operation.

MAXIMUM = 'maximum'
PROBABILISTIC = 'probabilistic'
LUKASIEWICZ = 'lukasiewicz'
classmethod __contains__(member)

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

classmethod __getitem__(name)

Return the member matching name.

classmethod __iter__()

Return members in definition order.

classmethod __len__()

Return the number of members (no aliases)

class gaia.integration.FuzzyElement(element, membership)[source]

Bases: object

Element with fuzzy membership degree.

__init__(element, membership)
element: Any
membership: float
gaia.integration.create_fuzzy_simplex(dimension, name, membership=1.0)[source]

Create a fuzzy simplex with given properties.

gaia.integration.create_fuzzy_simplicial_set_from_data(data, k=5, name='data_fss')[source]

Create fuzzy simplicial set from point cloud data using k-NN.

gaia.integration.merge_fuzzy_simplicial_sets(*fss_list, t_conorm=TConorm.MAXIMUM)[source]

Merge multiple fuzzy simplicial sets.

gaia.integration.get_training_components()[source]

Get training components without circular imports

gaia.integration.get_verification_components()[source]

Get verification components without circular imports