kaft 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kaft-0.1.0/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Crucible Science
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
kaft-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: kaft
3
+ Version: 0.1.0
4
+ Summary: Information geometry engine — Fisher-Rao manifolds, Jordan boundaries, K-density navigation
5
+ Author-email: Crucible Science <hello@cruciblescience.com>
6
+ License: MIT
7
+ Keywords: information-geometry,fisher-rao,manifold,kaft,knowledge-dynamics
8
+ Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE.txt
19
+ Requires-Dist: numpy>=1.24
20
+ Requires-Dist: scikit-learn>=1.3
21
+ Requires-Dist: sentence-transformers>=2.7
22
+ Requires-Dist: umap-learn>=0.5
23
+ Requires-Dist: scipy>=1.11
24
+ Requires-Dist: geomstats>=0.7
25
+ Requires-Dist: arxiv>=2.1
26
+ Provides-Extra: molecular
27
+ Requires-Dist: rdkit>=2023.3; extra == "molecular"
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: black; extra == "dev"
31
+ Requires-Dist: build; extra == "dev"
32
+ Requires-Dist: twine; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+
36
+ # kaft
37
+
38
+ **Geometric dynamics on information manifolds.**
39
+
40
+ [![PyPI version](https://badge.fury.io/py/kaft.svg)](https://badge.fury.io/py/kaft)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
42
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://python.org)
43
+
44
+ ```bash
45
+ pip install kaft
46
+ ```
47
+
48
+ ---
49
+
50
+ ## What kaft does
51
+
52
+ `kaft` implements geometric dynamics on Riemannian information manifolds.
53
+
54
+ Standard approaches treat knowledge as accumulation in flat Euclidean space like
55
+ dot product similarity, cosine distance, softmax attention.
56
+ Čencov's uniqueness theorem (1981) proves this is mathematically forced to be wrong:
57
+ Fisher-Rao is the **only** Riemannian metric invariant under sufficient-statistic
58
+ transformations on probability manifolds.
59
+
60
+ `kaft` builds on that foundation:
61
+
62
+ - Embeds any corpus into a unified Fisher-Rao metric space
63
+ - Computes K-density fields via inverse square law interaction dynamics
64
+ - Detects Jordan-Brouwer domain boundaries as emergent geometry, not imposed constraints
65
+ - Evolves knowledge state via the master field equation across timesteps
66
+ - Traces geodesic paths between concepts on the curved manifold
67
+ - Persists and reloads manifold state for session continuity
68
+
69
+ ---
70
+
71
+ ## Core concepts
72
+
73
+ **Fisher-Rao metric**
74
+ The unique invariant Riemannian metric on statistical manifolds (Čencov 1981).
75
+ Geodesic distance = arccos of cosine similarity on the hypersphere S^383.
76
+ Validated against geomstats to 4 decimal places.
77
+
78
+ **K-density field**
79
+ Inverse square law interaction: `K ∝ I₁·I₂ / d²`
80
+ where d is geodesic distance on the Fisher-Rao manifold, not Euclidean distance.
81
+ High K = dense semantic cluster. Low K = open conceptual space.
82
+
83
+ **Jordan boundaries**
84
+ Emergent domain separators — NOT configurable parameters.
85
+ They crystallise as level sets of K-density gradients from the geometry itself.
86
+ Hallucination prevention: crossing a boundary requires discrete energy accumulation,
87
+ not smooth interpolation.
88
+
89
+ **Knowledge evolution**
90
+ Master field equation:
91
+ `∂K/∂t = c·v²_cog·K² + P(V)·∇^FR(K) + ξ_J(t)`
92
+ K² term: self-amplifying dynamics — understanding compounds.
93
+ Fisher-Rao gradient: geodesic flow along information-theoretically optimal paths.
94
+ Jordan noise: topologically constrained stochastic exploration within domains.
95
+
96
+ ---
97
+
98
+ ## Quickstart
99
+
100
+ ### Build a manifold
101
+
102
+ ```python
103
+ from kaft.core.manifold import build_manifold
104
+
105
+ corpus = [
106
+ {"text": "Fisher-Rao information geometry manifold"},
107
+ {"text": "Riemannian curvature tensor geodesic"},
108
+ {"text": "CRISPR-Cas9 gene editing mechanism"},
109
+ {"text": "mRNA vaccine immunological response"},
110
+ {"text": "statistical mechanics entropy thermodynamics"},
111
+ ]
112
+
113
+ state = build_manifold(corpus)
114
+ print(state.embeddings.shape) # (5, 384)
115
+ ```
116
+
117
+ ### Compute Fisher-Rao geometry
118
+
119
+ ```python
120
+ from kaft.core.metric import FisherRaoMetric
121
+ from kaft.core.topology import KDensity, JordanBoundary
122
+
123
+ metric = FisherRaoMetric(state)
124
+ metric.compute()
125
+
126
+ kdensity = KDensity(state, metric)
127
+ K = kdensity.compute()
128
+ # K[i] ∈ — normalised interaction density at each point [actualisedaily](https://actualisedaily.com/transformation/transformative-crucibles-and-the-adventure-of-life/)
129
+
130
+ boundaries = JordanBoundary(state, kdensity).detect()
131
+ # Boundaries emerge from K-density gradients — not imposed
132
+ for b in boundaries:
133
+ print(f"Boundary at: {b['text']} | energy barrier: {b['energy_barrier']:.4f}")
134
+ ```
135
+
136
+ ### Evolve knowledge dynamics
137
+
138
+ ```python
139
+ from kaft.simulate.kaft import KAFTSimulator
140
+ from kaft.simulate.softmax import SoftmaxSimulator
141
+ from kaft.simulate.compare import compare
142
+
143
+ result = compare(KAFTSimulator(), SoftmaxSimulator(), state, n_steps=50)
144
+ print(f"Divergence: {result['divergence']:.4f}")
145
+ # KAFT sees domain structure — varied K across clusters
146
+ # Softmax sees uniform K=1.000 across all points
147
+ ```
148
+
149
+ ### Navigate geodesics
150
+
151
+ ```python
152
+ from kaft.navigate.geodesic import GeodesicNavigator
153
+
154
+ navigator = GeodesicNavigator(state, metric, n_steps=15)
155
+ path = navigator.trace(source_idx=0, target_idx=2)
156
+
157
+ print(f"Fisher-Rao path length: {path.total_fr_length:.4f}")
158
+ for wp in path.waypoints:
159
+ print(f"t={wp.t:.2f} K={wp.k_density:.4f} {wp.nearest_text[:40]}")
160
+
161
+ # Jordan boundary crossings detected automatically
162
+ for t_val, label in path.boundary_crossings:
163
+ print(f"t={t_val:.2f} — {label}")
164
+ ```
165
+
166
+ ### Real corpus via arXiv
167
+
168
+ ```python
169
+ from kaft.ingest.router import ArxivRouter
170
+
171
+ router = ArxivRouter()
172
+ records = router.fetch("Fisher information geometry", max_results=10)
173
+ state = build_manifold(records)
174
+ ```
175
+
176
+ ### Persist manifold state
177
+
178
+ ```python
179
+ from kaft.navigate.seeder import DomainSeeder
180
+
181
+ DomainSeeder.save(state, "domain.json") # compute once
182
+ state = DomainSeeder.load("domain.json") # reload instantly
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Validation
188
+
189
+ | Experiment | Result |
190
+ |---|---|
191
+ | Fisher-Rao vs geomstats | Exact match to 4 decimal places |
192
+ | Jordan boundaries | Emerge on real 24-paper arXiv corpus (4 domains) |
193
+ | K² soliton | Topology locks at step 10, stable through step 50 |
194
+ | Geometric vs flat dynamics | Divergence D=0.2230 on real corpus |
195
+ | 3-SAT phase transition α=5.0 | 95.73% ±1.03% satisfaction, O(N^1.17) scaling |
196
+
197
+ ---
198
+
199
+ ## Installation
200
+
201
+ ```bash
202
+ pip install kaft
203
+ ```
204
+
205
+ **Development:**
206
+ ```bash
207
+ git clone https://github.com/crucible-science/kaft
208
+ cd kaft
209
+ pip install -e ".[dev]"
210
+ pytest tests/ -v
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Background
216
+
217
+ `kaft` is the reference implementation of
218
+ **Knowledge Attention Field Theory** —
219
+ a geometric framework for knowledge dynamics on Riemannian information manifolds.
220
+
221
+ Built at [Crucible Science](https://cruciblescience.com).
222
+ arXiv paper: *forthcoming — endorsements in progress*
223
+
224
+ ---
225
+
226
+ ## License
227
+
228
+ MIT — see [LICENSE](LICENSE)
kaft-0.1.0/README.md ADDED
@@ -0,0 +1,194 @@
1
+
2
+ # kaft
3
+
4
+ **Geometric dynamics on information manifolds.**
5
+
6
+ [![PyPI version](https://badge.fury.io/py/kaft.svg)](https://badge.fury.io/py/kaft)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://python.org)
9
+
10
+ ```bash
11
+ pip install kaft
12
+ ```
13
+
14
+ ---
15
+
16
+ ## What kaft does
17
+
18
+ `kaft` implements geometric dynamics on Riemannian information manifolds.
19
+
20
+ Standard approaches treat knowledge as accumulation in flat Euclidean space like
21
+ dot product similarity, cosine distance, softmax attention.
22
+ Čencov's uniqueness theorem (1981) proves this is mathematically forced to be wrong:
23
+ Fisher-Rao is the **only** Riemannian metric invariant under sufficient-statistic
24
+ transformations on probability manifolds.
25
+
26
+ `kaft` builds on that foundation:
27
+
28
+ - Embeds any corpus into a unified Fisher-Rao metric space
29
+ - Computes K-density fields via inverse square law interaction dynamics
30
+ - Detects Jordan-Brouwer domain boundaries as emergent geometry, not imposed constraints
31
+ - Evolves knowledge state via the master field equation across timesteps
32
+ - Traces geodesic paths between concepts on the curved manifold
33
+ - Persists and reloads manifold state for session continuity
34
+
35
+ ---
36
+
37
+ ## Core concepts
38
+
39
+ **Fisher-Rao metric**
40
+ The unique invariant Riemannian metric on statistical manifolds (Čencov 1981).
41
+ Geodesic distance = arccos of cosine similarity on the hypersphere S^383.
42
+ Validated against geomstats to 4 decimal places.
43
+
44
+ **K-density field**
45
+ Inverse square law interaction: `K ∝ I₁·I₂ / d²`
46
+ where d is geodesic distance on the Fisher-Rao manifold, not Euclidean distance.
47
+ High K = dense semantic cluster. Low K = open conceptual space.
48
+
49
+ **Jordan boundaries**
50
+ Emergent domain separators — NOT configurable parameters.
51
+ They crystallise as level sets of K-density gradients from the geometry itself.
52
+ Hallucination prevention: crossing a boundary requires discrete energy accumulation,
53
+ not smooth interpolation.
54
+
55
+ **Knowledge evolution**
56
+ Master field equation:
57
+ `∂K/∂t = c·v²_cog·K² + P(V)·∇^FR(K) + ξ_J(t)`
58
+ K² term: self-amplifying dynamics — understanding compounds.
59
+ Fisher-Rao gradient: geodesic flow along information-theoretically optimal paths.
60
+ Jordan noise: topologically constrained stochastic exploration within domains.
61
+
62
+ ---
63
+
64
+ ## Quickstart
65
+
66
+ ### Build a manifold
67
+
68
+ ```python
69
+ from kaft.core.manifold import build_manifold
70
+
71
+ corpus = [
72
+ {"text": "Fisher-Rao information geometry manifold"},
73
+ {"text": "Riemannian curvature tensor geodesic"},
74
+ {"text": "CRISPR-Cas9 gene editing mechanism"},
75
+ {"text": "mRNA vaccine immunological response"},
76
+ {"text": "statistical mechanics entropy thermodynamics"},
77
+ ]
78
+
79
+ state = build_manifold(corpus)
80
+ print(state.embeddings.shape) # (5, 384)
81
+ ```
82
+
83
+ ### Compute Fisher-Rao geometry
84
+
85
+ ```python
86
+ from kaft.core.metric import FisherRaoMetric
87
+ from kaft.core.topology import KDensity, JordanBoundary
88
+
89
+ metric = FisherRaoMetric(state)
90
+ metric.compute()
91
+
92
+ kdensity = KDensity(state, metric)
93
+ K = kdensity.compute()
94
+ # K[i] ∈ — normalised interaction density at each point [actualisedaily](https://actualisedaily.com/transformation/transformative-crucibles-and-the-adventure-of-life/)
95
+
96
+ boundaries = JordanBoundary(state, kdensity).detect()
97
+ # Boundaries emerge from K-density gradients — not imposed
98
+ for b in boundaries:
99
+ print(f"Boundary at: {b['text']} | energy barrier: {b['energy_barrier']:.4f}")
100
+ ```
101
+
102
+ ### Evolve knowledge dynamics
103
+
104
+ ```python
105
+ from kaft.simulate.kaft import KAFTSimulator
106
+ from kaft.simulate.softmax import SoftmaxSimulator
107
+ from kaft.simulate.compare import compare
108
+
109
+ result = compare(KAFTSimulator(), SoftmaxSimulator(), state, n_steps=50)
110
+ print(f"Divergence: {result['divergence']:.4f}")
111
+ # KAFT sees domain structure — varied K across clusters
112
+ # Softmax sees uniform K=1.000 across all points
113
+ ```
114
+
115
+ ### Navigate geodesics
116
+
117
+ ```python
118
+ from kaft.navigate.geodesic import GeodesicNavigator
119
+
120
+ navigator = GeodesicNavigator(state, metric, n_steps=15)
121
+ path = navigator.trace(source_idx=0, target_idx=2)
122
+
123
+ print(f"Fisher-Rao path length: {path.total_fr_length:.4f}")
124
+ for wp in path.waypoints:
125
+ print(f"t={wp.t:.2f} K={wp.k_density:.4f} {wp.nearest_text[:40]}")
126
+
127
+ # Jordan boundary crossings detected automatically
128
+ for t_val, label in path.boundary_crossings:
129
+ print(f"t={t_val:.2f} — {label}")
130
+ ```
131
+
132
+ ### Real corpus via arXiv
133
+
134
+ ```python
135
+ from kaft.ingest.router import ArxivRouter
136
+
137
+ router = ArxivRouter()
138
+ records = router.fetch("Fisher information geometry", max_results=10)
139
+ state = build_manifold(records)
140
+ ```
141
+
142
+ ### Persist manifold state
143
+
144
+ ```python
145
+ from kaft.navigate.seeder import DomainSeeder
146
+
147
+ DomainSeeder.save(state, "domain.json") # compute once
148
+ state = DomainSeeder.load("domain.json") # reload instantly
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Validation
154
+
155
+ | Experiment | Result |
156
+ |---|---|
157
+ | Fisher-Rao vs geomstats | Exact match to 4 decimal places |
158
+ | Jordan boundaries | Emerge on real 24-paper arXiv corpus (4 domains) |
159
+ | K² soliton | Topology locks at step 10, stable through step 50 |
160
+ | Geometric vs flat dynamics | Divergence D=0.2230 on real corpus |
161
+ | 3-SAT phase transition α=5.0 | 95.73% ±1.03% satisfaction, O(N^1.17) scaling |
162
+
163
+ ---
164
+
165
+ ## Installation
166
+
167
+ ```bash
168
+ pip install kaft
169
+ ```
170
+
171
+ **Development:**
172
+ ```bash
173
+ git clone https://github.com/crucible-science/kaft
174
+ cd kaft
175
+ pip install -e ".[dev]"
176
+ pytest tests/ -v
177
+ ```
178
+
179
+ ---
180
+
181
+ ## Background
182
+
183
+ `kaft` is the reference implementation of
184
+ **Knowledge Attention Field Theory** —
185
+ a geometric framework for knowledge dynamics on Riemannian information manifolds.
186
+
187
+ Built at [Crucible Science](https://cruciblescience.com).
188
+ arXiv paper: *forthcoming — endorsements in progress*
189
+
190
+ ---
191
+
192
+ ## License
193
+
194
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,31 @@
1
+ """
2
+ kaft — Information geometry engine.
3
+
4
+ Dense knowledge curves information space;
5
+ curved space tells knowledge where to navigate.
6
+ """
7
+
8
+ from kaft.core.manifold import build_manifold, Manifold
9
+ from kaft.core.metric import FisherRaoMetric
10
+ from kaft.core.topology import KDensity, JordanBoundary
11
+ from kaft.core.resonance import ResonanceField
12
+ from kaft.simulate.compare import compare
13
+ from kaft.simulate.kaft import KAFTSimulator
14
+ from kaft.simulate.softmax import SoftmaxSimulator
15
+ from kaft.simulate.base import AbstractSimulator
16
+ from kaft.ingest.router import ArxivRouter
17
+
18
+ __version__ = "0.1.0"
19
+ __author__ = "Crucible Science"
20
+
21
+ __all__ = [
22
+ # Core geometry
23
+ "build_manifold", "Manifold",
24
+ "FisherRaoMetric",
25
+ "KDensity", "JordanBoundary",
26
+ "ResonanceField",
27
+ # Simulation
28
+ "KAFTSimulator", "SoftmaxSimulator",
29
+ "AbstractSimulator",
30
+ "compare",
31
+ ]
@@ -0,0 +1 @@
1
+ # kaft.compress — KTP crystal generation (Wonder integration, optional)
@@ -0,0 +1,5 @@
1
+ from kaft.core.manifold import build_manifold, Manifold
2
+ from kaft.core.metric import FisherRaoMetric
3
+ from kaft.core.topology import KDensity, JordanBoundary
4
+
5
+ __all__ = ["build_manifold", "Manifold", "FisherRaoMetric", "KDensity", "JordanBoundary"]
@@ -0,0 +1,71 @@
1
+ """
2
+ Manifold — the base geometric object.
3
+
4
+ A Manifold wraps a corpus of records into an embedded point cloud
5
+ with a computed Fisher-Rao metric and K-density field.
6
+ Everything else in kaft navigates or simulates on top of this.
7
+ """
8
+
9
+ from __future__ import annotations
10
+ from dataclasses import dataclass, field
11
+ import numpy as np
12
+
13
+
14
+ @dataclass
15
+ class Manifold:
16
+ """
17
+ Core geometric state object.
18
+ Everything in kaft navigates or simulates on top of this.
19
+ """
20
+ embeddings: np.ndarray # shape (N, 384) — unified metric space
21
+ records: list # original corpus with "text" key
22
+ domain_type: str = "auto"
23
+ metric_tensor: np.ndarray | None = None
24
+ k_density: np.ndarray | None = None
25
+ jordan_boundaries: list | None = None
26
+
27
+
28
+ def build_manifold(records: list[dict], domain_type: str = "auto") -> Manifold:
29
+ """
30
+ Entry point: corpus → Manifold.
31
+ Embeds all records into one unified Fisher-Rao coordinate space.
32
+
33
+ Parameters
34
+ ----------
35
+ records : list[dict]
36
+ Each record must have a "text" key.
37
+ domain_type : str
38
+ Routing hint — 'research', 'molecular', 'patent', 'auto'
39
+
40
+ Returns
41
+ -------
42
+ Manifold
43
+ Geometric state with embeddings ready for metric computation.
44
+
45
+ Example
46
+ -------
47
+ >>> state = build_manifold([
48
+ ... {"text": "CRISPR-Cas9 gene editing mechanism"},
49
+ ... {"text": "drug resistance mutation pathway"},
50
+ ... ])
51
+ >>> state.embeddings.shape
52
+ (2, 384)
53
+ """
54
+ from sentence_transformers import SentenceTransformer
55
+
56
+ if not records:
57
+ raise ValueError("records cannot be empty — no manifold to build")
58
+
59
+ texts = [r["text"] for r in records]
60
+
61
+ # all-MiniLM-L6-v2: 384 dimensions, fast, strong semantic geometry
62
+ # This is the ONE embedding model used everywhere in kaft
63
+ # It fixes the two-stream divergence from geometric_bridge vs geometric_prompting
64
+ model = SentenceTransformer("all-MiniLM-L6-v2")
65
+ embeddings = model.encode(texts, show_progress_bar=False)
66
+
67
+ return Manifold(
68
+ embeddings=np.array(embeddings),
69
+ records=records,
70
+ domain_type=domain_type,
71
+ )
@@ -0,0 +1,66 @@
1
+ """
2
+ FisherRaoMetric — the mathematically forced metric.
3
+
4
+ Čencov's uniqueness theorem (1981): Fisher-Rao is the ONLY
5
+ Riemannian metric on statistical manifolds invariant under
6
+ sufficient-statistic Markov morphisms. Not chosen. Forced.
7
+
8
+ g^FR_μν = E[ ∂log p/∂θ_μ · ∂log p/∂θ_ν ]
9
+ """
10
+ from __future__ import annotations
11
+ import numpy as np
12
+ from sklearn.metrics.pairwise import cosine_similarity
13
+ from kaft.core.manifold import Manifold
14
+
15
+
16
+ class FisherRaoMetric:
17
+ """
18
+ Fisher-Rao metric on the knowledge manifold.
19
+
20
+ Sentence-transformer embeddings live on a hypersphere S^383.
21
+ The natural Riemannian metric on a hypersphere gives geodesic
22
+ distance as angular distance — arccos of cosine similarity.
23
+
24
+ This IS curved geometry. Not Euclidean. Not dot-product similarity.
25
+ Two concepts can be close in dot-product space but far on the manifold
26
+ if the curved path between them crosses a semantic boundary.
27
+
28
+ Čencov forcing: Fisher-Rao is the unique invariant metric on
29
+ statistical manifolds. We don't choose it. It's the only valid one.
30
+ """
31
+
32
+ def __init__(self, manifold: Manifold):
33
+ self.manifold = manifold
34
+ self._distances: np.ndarray | None = None
35
+
36
+ def compute(self) -> np.ndarray:
37
+ """
38
+ Compute pairwise Fisher-Rao geodesic distances.
39
+
40
+ Returns
41
+ -------
42
+ np.ndarray, shape (N, N)
43
+ D[i,j] = arccos(e_i · e_j) — geodesic distance on hypersphere.
44
+ D[i,i] = 0 always. Symmetric. Range [0, π].
45
+ """
46
+ E = self.manifold.embeddings # (N, 384)
47
+ cos_sim = cosine_similarity(E) # (N, N), range [-1, 1]
48
+ cos_sim = np.clip(cos_sim, -1.0, 1.0) # numerical safety for arccos
49
+ self._distances = np.arccos(cos_sim) # geodesic distance
50
+ return self._distances
51
+
52
+ def geodesic_distance(self, i: int, j: int) -> float:
53
+ """
54
+ Fisher-Rao geodesic distance between points i and j.
55
+ This is the d in K ∝ I₁·I₂/d² — curved, not Euclidean.
56
+ Context reshapes this distance by curving the manifold.
57
+ """
58
+ if self._distances is None:
59
+ self.compute()
60
+ return float(self._distances[i, j])
61
+
62
+ @property
63
+ def distances(self) -> np.ndarray:
64
+ if self._distances is None:
65
+ self.compute()
66
+ return self._distances
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+ import numpy as np
3
+ from kaft.core.topology import KDensity
4
+
5
+
6
+ class ResonanceField:
7
+ """
8
+ R ≡ K² · v²_cog
9
+
10
+ Attention density — regions where knowledge self-amplifies most strongly.
11
+ NOT designed. Falls directly out of K² recursion.
12
+
13
+ High R = powerful attractor. Knowledge flows toward these regions.
14
+ Low R = exploratory space. Jordan noise dominates here.
15
+
16
+ This is the first term in the master evolution equation.
17
+ """
18
+
19
+ def __init__(self, k_density: KDensity, v_cog: float = 1.0):
20
+ self.k_density = k_density
21
+ self.v_cog = v_cog
22
+
23
+ def compute(self) -> np.ndarray:
24
+ """
25
+ Returns R = K² · v²_cog for every point.
26
+ Shape (N,) — same shape as K-density.
27
+ """
28
+ K = self.k_density.density # (N,)
29
+ return (K ** 2) * (self.v_cog ** 2) # emerges — not imposed