gaia.core.kan_extensions module

Kan Extensions for GAIA Framework - Foundation Model Construction

Implements Section 6.6 from GAIA paper: “Kan Extension” INTEGRATES with existing kan_verification.py for complete Kan extension system

THEORETICAL FOUNDATIONS: - Definition 48: Left Kan extension Lan_K F: D → E with universal property - Right Kan extension Ran_K F: D → E as right adjoint - Migration functors Δ_F, Σ_F, Π_F for generative AI model modifications - Foundation model construction via functor extension - Universal property: “every concept in category theory is a special case of Kan extension”

This enables GAIA to construct foundation models by extending functors over categories, rather than interpolating functions on sets - the core innovation of GAIA.

class gaia.core.kan_extensions.Category(name)[source]

Bases: ABC

Abstract base class for categories

A category consists of objects and morphisms with composition and identity

__init__(name)[source]
abstractmethod add_object(obj)[source]

Add object to category

abstractmethod add_morphism(source, target, morphism)[source]

Add morphism to category

abstractmethod compose(f, g)[source]

Compose morphisms f: A → B and g: B → C to get g∘f: A → C

has_morphism(source, target)[source]

Check if morphism exists between objects

get_morphism(source, target)[source]

Get morphism between objects

class gaia.core.kan_extensions.SetCategory[source]

Bases: Category

Category of sets and functions

Objects are sets, morphisms are functions between sets

__init__()[source]
add_object(obj)[source]

Add set as object

add_morphism(source, target, morphism)[source]

Add function as morphism

compose(f, g)[source]

Compose functions: (g∘f)(x) = g(f(x))

get_morphism(source, target)

Get morphism between objects

has_morphism(source, target)

Check if morphism exists between objects

class gaia.core.kan_extensions.GenerativeAICategory(name='GenerativeAI')[source]

Bases: Category

Category for generative AI models

Objects are model components, morphisms are transformations between them

__init__(name='GenerativeAI')[source]
add_object(obj, component=None)[source]

Add model component as object

add_morphism(source, target, morphism)[source]

Add transformation as morphism

compose(f, g)[source]

Compose transformations

get_morphism(source, target)

Get morphism between objects

has_morphism(source, target)

Check if morphism exists between objects

class gaia.core.kan_extensions.Functor(source_category, target_category, name)[source]

Bases: ABC, Generic[C, D]

Abstract base class for functors F: C → D

Maps objects and morphisms while preserving categorical structure

__init__(source_category, target_category, name)[source]
abstractmethod map_object(obj)[source]

Map object from source to target category

abstractmethod map_morphism(morphism, source_obj, target_obj)[source]

Map morphism from source to target category

verify_functoriality()[source]

Verify functor laws: F(id) = id and F(g∘f) = F(g)∘F(f)

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.kan_extensions.NeuralFunctor(source_category, target_category)[source]

Bases: Functor

Functor for neural network transformations

Maps between categories of neural network components

__init__(source_category, target_category)[source]
map_object(obj)[source]

Map neural component to transformed component

map_morphism(morphism, source_obj, target_obj)[source]

Map transformation to neural transformation

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

verify_functoriality()

Verify functor laws: F(id) = id and F(g∘f) = F(g)∘F(f)

class gaia.core.kan_extensions.NaturalTransformation(source_functor, target_functor, name)[source]

Bases: object

Natural transformation between functors

Provides component-wise transformation that commutes with functor morphisms

__init__(source_functor, target_functor, name)[source]
add_component(obj, component)[source]

Add component of natural transformation at object

get_component(obj)[source]

Get component at object

verify_naturality()[source]

Verify naturality condition: η_B ∘ F(f) = G(f) ∘ η_A

For morphism f: A → B, the diagram must commute

class gaia.core.kan_extensions.LeftKanExtension(F, K, name='LeftKanExtension')[source]

Bases: object

Left Kan extension Lan_K F: D → E

From (MAHADEVAN,2024) Definition 48: Universal property for extending functors

__init__(F, K, name='LeftKanExtension')[source]
verify_universal_property(G, gamma)[source]

Verify universal property: for any G: D → E and γ: F → G∘K, there exists unique α: Lan_K F → G such that γ = α * η

class gaia.core.kan_extensions.RightKanExtension(F, K, name='RightKanExtension')[source]

Bases: object

Right Kan extension Ran_K F: D → E

Dual to left Kan extension, constructed via limits instead of colimits

__init__(F, K, name='RightKanExtension')[source]
class gaia.core.kan_extensions.MigrationFunctor(F, name='MigrationFunctor')[source]

Bases: object

Migration functors for generative AI model modifications

From GAIA paper: Δ_F (pullback), Σ_F (left pushforward), Π_F (right pushforward)

__init__(F, name='MigrationFunctor')[source]
pullback_functor(epsilon_functor)[source]

Δ_F: ε → δ

Pullback functor that maps modified model back to original

left_pushforward_functor(delta_functor)[source]

Σ_F: δ → ε

Left pushforward as left Kan extension (left adjoint to pullback)

right_pushforward_functor(delta_functor)[source]

Π_F: δ → ε

Right pushforward as right Kan extension (right adjoint to pullback)

class gaia.core.kan_extensions.FoundationModelBuilder(name='FoundationModelBuilder')[source]

Bases: object

Foundation model builder using Kan extensions

Core innovation of GAIA: build foundation models by extending functors over categories rather than interpolating functions on sets

__init__(name='FoundationModelBuilder')[source]
add_base_category(name, category)[source]

Add base category for foundation model

add_base_functor(name, functor)[source]

Add base functor for foundation model

build_foundation_model_via_left_kan(base_functor_name, extension_functor_name, model_name)[source]

Build foundation model via left Kan extension

This extends the base functor along the extension direction

build_foundation_model_via_right_kan(base_functor_name, extension_functor_name, model_name)[source]

Build foundation model via right Kan extension

apply_model_modification(original_model_name, modification_functor, modified_model_name)[source]

Apply modification to foundation model using migration functors

This implements the model modification framework from GAIA paper

get_foundation_model(name)[source]

Get foundation model by name

list_models()[source]

List all foundation models

gaia.core.kan_extensions.create_llm_foundation_model(vocab_size, hidden_dim)[source]

Create foundation model for Large Language Models

Uses Kan extensions to build LLM from categorical components

gaia.core.kan_extensions.create_diffusion_foundation_model(image_size, noise_steps)[source]

Create foundation model for Diffusion Models

Uses Kan extensions for noise-to-image generation

gaia.core.kan_extensions.create_multimodal_foundation_model()[source]

Create multimodal foundation model

Combines text, image, and audio modalities via Kan extensions