gaia.core.metric_yoneda module
Metric Yoneda Lemma for GAIA Framework
Implements Section 6.7 from GAIA paper: “The Metric Yoneda Lemma”
THEORETICAL FOUNDATIONS: - Generalized metric spaces (X, d) with non-symmetric distances - [0,∞]-enriched categories for distance computations - Yoneda embedding y: X → X̂ as universal representer - Isometric property: X(x,x’) = X̂(y(x), y(x’)) - Applications to LLMs, image processing, probability distributions
This enables GAIA to work with non-symmetric distances and build universal representers for any objects in generalized metric spaces.
- class gaia.core.metric_yoneda.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.core.metric_yoneda.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.core.metric_yoneda.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
- 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 φ,ψ
- 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
- universal_property(x, phi)[source]
Universal property: X̂(X(-,x), φ) = φ(x)
This is the metric Yoneda lemma from GAIA paper
- 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.metric_yoneda.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_text_metric_space(documents)[source]
Create metric space for text documents using edit distance
Example From (MAHADEVAN,2024) Section 6.7 for string comparison
- static create_image_metric_space(images)[source]
Create metric space for images using perceptual distance
Non-symmetric distance for image comparison
- class gaia.core.metric_yoneda.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.
- represent(obj)[source]
Create universal representation of object
Returns Yoneda embedding as universal representer