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) → …
- carrier: 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]): ….
- 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]): ….
- 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]): ….
- 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.integration.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
- class gaia.integration.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.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]): ….
- 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]): ….
- 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]): ….
- 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]): ….
- 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
- 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]): ….
- 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 φ,ψ
- 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
- 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.
- compare_objects(obj1, obj2)[source]
Compare two objects using universal representations
Returns both original and representational distances
- 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].
- 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]): ….
- class gaia.integration.IntegratedFuzzySimplicialSet(name, max_dimension=3)[source]
Bases:
GAIAComponent
Integrated fuzzy simplicial set combining fuzzy and simplicial structures.
- 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]): ….
- evolve(state)
Evolve state using structure map: γ(state).
- class gaia.integration.TConorm(value)[source]
Bases:
Enum
T-conorms for fuzzy set operations.
- 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)
- 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.