agentdb 2.0.0-alpha.1 → 2.0.0-alpha.2
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.
- package/dist/agentdb.min.js +4 -4
- package/dist/simulation/cli.js +0 -0
- package/dist/src/cli/lib/config-manager.d.ts.map +1 -1
- package/dist/src/cli/lib/config-manager.js.map +1 -1
- package/dist/src/cli/lib/history-tracker.d.ts.map +1 -1
- package/dist/src/cli/lib/history-tracker.js +7 -1
- package/dist/src/cli/lib/history-tracker.js.map +1 -1
- package/examples/README.md +105 -0
- package/examples/quickstart.js +43 -0
- package/package.json +6 -2
- package/simulation/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/.claude-flow/metrics/performance.json +87 -0
- package/simulation/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/COMPLETION-STATUS.md +139 -0
- package/simulation/FINAL-RESULTS.md +414 -0
- package/simulation/FINAL-STATUS.md +281 -0
- package/simulation/INTEGRATION-COMPLETE.md +452 -0
- package/simulation/MIGRATION-STATUS.md +231 -0
- package/simulation/OPTIMIZATION-RESULTS.md +397 -0
- package/simulation/PHASE1-COMPLETE.md +163 -0
- package/simulation/README.md +848 -0
- package/simulation/SIMULATION-RESULTS.md +239 -0
- package/simulation/cli.ts +78 -0
- package/simulation/configs/default.json +37 -0
- package/simulation/data/advanced/aidefence.graph +0 -0
- package/simulation/data/advanced/bmssp.graph +0 -0
- package/simulation/data/advanced/consciousness.graph +0 -0
- package/simulation/data/advanced/goalie.graph +0 -0
- package/simulation/data/advanced/psycho-symbolic.graph +0 -0
- package/simulation/data/advanced/research-swarm.graph +0 -0
- package/simulation/data/advanced/sublinear.graph +0 -0
- package/simulation/data/advanced/temporal.graph +0 -0
- package/simulation/data/causal.graph +0 -0
- package/simulation/data/graph-traversal.graph +0 -0
- package/simulation/data/lean-agentic.graph +0 -0
- package/simulation/data/reflexion.graph +0 -0
- package/simulation/data/skills.graph +0 -0
- package/simulation/data/stock-market.graph +0 -0
- package/simulation/data/strange-loops.graph +0 -0
- package/simulation/data/swarm.graph +0 -0
- package/simulation/data/voting-consensus.graph +0 -0
- package/simulation/docs/CLI-INTEGRATION-PLAN.md +1038 -0
- package/simulation/docs/COMPREHENSIVE-LATENT-SPACE-COMPLETION.md +354 -0
- package/simulation/docs/DOCUMENTATION-INDEX.md +226 -0
- package/simulation/docs/IMPLEMENTATION-COMPLETE.md +521 -0
- package/simulation/docs/OPTIMIZATION-SUMMARY.md +279 -0
- package/simulation/docs/README.md +229 -0
- package/simulation/docs/SWARM-5-INTEGRATION-SUMMARY.md +528 -0
- package/simulation/docs/TESTING-SUMMARY.md +304 -0
- package/simulation/docs/architecture/EXTENSION-API.md +868 -0
- package/simulation/docs/architecture/INTEGRATION-ARCHITECTURE.md +1138 -0
- package/simulation/docs/architecture/OPTIMIZATION-STRATEGY.md +778 -0
- package/simulation/docs/architecture/SIMULATION-ARCHITECTURE.md +892 -0
- package/simulation/docs/guides/CLI-REFERENCE.md +896 -0
- package/simulation/docs/guides/CUSTOM-SIMULATIONS.md +931 -0
- package/simulation/docs/guides/DEPLOYMENT.md +832 -0
- package/simulation/docs/guides/IMPLEMENTATION-SUMMARY.md +544 -0
- package/simulation/docs/guides/MIGRATION-GUIDE.md +591 -0
- package/simulation/docs/guides/QUICK-START.md +361 -0
- package/simulation/docs/guides/README.md +736 -0
- package/simulation/docs/guides/TROUBLESHOOTING.md +817 -0
- package/simulation/docs/guides/WIZARD-GUIDE.md +869 -0
- package/simulation/docs/reports/latent-space/MASTER-SYNTHESIS.md +345 -0
- package/simulation/docs/reports/latent-space/README.md +132 -0
- package/simulation/docs/reports/latent-space/attention-analysis-RESULTS.md +238 -0
- package/simulation/docs/reports/latent-space/clustering-analysis-RESULTS.md +210 -0
- package/simulation/docs/reports/latent-space/hnsw-exploration-RESULTS.md +332 -0
- package/simulation/docs/reports/latent-space/hypergraph-exploration-RESULTS.md +37 -0
- package/simulation/docs/reports/latent-space/neural-augmentation-RESULTS.md +69 -0
- package/simulation/docs/reports/latent-space/quantum-hybrid-RESULTS.md +91 -0
- package/simulation/docs/reports/latent-space/self-organizing-hnsw-RESULTS.md +51 -0
- package/simulation/docs/reports/latent-space/traversal-optimization-RESULTS.md +238 -0
- package/simulation/reports/README.md +397 -0
- package/simulation/reports/advanced-simulations-performance.md +1241 -0
- package/simulation/reports/aidefence-integration-2025-11-30T01-36-53-486Z.json +30 -0
- package/simulation/reports/architecture-analysis.md +1396 -0
- package/simulation/reports/basic-scenarios-performance.md +1840 -0
- package/simulation/reports/bmssp-integration-2025-11-30T01-36-27-193Z.json +30 -0
- package/simulation/reports/bmssp-integration-2025-11-30T03-38-12-887Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-29T23-35-21-795Z.json +36 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-58-42-862Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-59-12-546Z.json +40 -0
- package/simulation/reports/consciousness-explorer-2025-11-30T01-36-51-269Z.json +31 -0
- package/simulation/reports/core-benchmarks.md +727 -0
- package/simulation/reports/goalie-integration-2025-11-30T01-36-52-377Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-35-35-279Z.json +78 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-37-36-697Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-03-59-716Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-05-10-984Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-16-334Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-53-312Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-07-51-075Z.json +24 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-08-22-179Z.json +42 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-29T23-37-23-804Z.json +148 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T01-31-24-401Z.json +31 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T03-38-01-470Z.json +31 -0
- package/simulation/reports/multi-agent-swarm-2025-11-29T23-35-28-093Z.json +78 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-03-54-062Z.json +42 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-05-06-092Z.json +42 -0
- package/simulation/reports/psycho-symbolic-reasoner-2025-11-30T01-36-50-180Z.json +30 -0
- package/simulation/reports/quality-metrics.md +727 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-35-09-774Z.json +48 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-37-16-934Z.json +36 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-07-49-259Z.json +30 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-09-29-319Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-28-37-659Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T01-31-30-690Z.json +29 -0
- package/simulation/reports/reflexion-learning-2025-11-30T03-38-06-937Z.json +29 -0
- package/simulation/reports/research-foundations.md +2004 -0
- package/simulation/reports/research-swarm-2025-11-30T01-36-54-647Z.json +30 -0
- package/simulation/reports/scalability-deployment.md +2404 -0
- package/simulation/reports/skill-evolution-2025-11-29T23-35-15-945Z.json +36 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-17-995Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-48-441Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-05-00-554Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-11-436Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-51-979Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-07-32-695Z.json +40 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-11-43-865Z.json +56 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-28-57-495Z.json +56 -0
- package/simulation/reports/strange-loops-2025-11-29T23-37-30-621Z.json +78 -0
- package/simulation/reports/strange-loops-2025-11-30T00-07-55-415Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-09-35-133Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-48-50-744Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-54-48-044Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-27-633Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-59-135Z.json +42 -0
- package/simulation/reports/sublinear-solver-2025-11-30T01-36-33-134Z.json +30 -0
- package/simulation/reports/temporal-lead-solver-2025-11-30T01-36-38-628Z.json +30 -0
- package/simulation/reports/use-cases-applications.md +2212 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-11-37-199Z.json +58 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-28-47-735Z.json +58 -0
- package/simulation/runner.ts +300 -0
- package/simulation/scenarios/README-advanced/aidefence-integration.md +63 -0
- package/simulation/scenarios/README-advanced/bmssp-integration.md +58 -0
- package/simulation/scenarios/README-advanced/consciousness-explorer.md +53 -0
- package/simulation/scenarios/README-advanced/goalie-integration.md +61 -0
- package/simulation/scenarios/README-advanced/psycho-symbolic-reasoner.md +55 -0
- package/simulation/scenarios/README-advanced/research-swarm.md +63 -0
- package/simulation/scenarios/README-advanced/sublinear-solver.md +58 -0
- package/simulation/scenarios/README-advanced/temporal-lead-solver.md +55 -0
- package/simulation/scenarios/README-basic/causal-reasoning.md +39 -0
- package/simulation/scenarios/README-basic/graph-traversal.md +41 -0
- package/simulation/scenarios/README-basic/lean-agentic-swarm.md +122 -0
- package/simulation/scenarios/README-basic/multi-agent-swarm.md +34 -0
- package/simulation/scenarios/README-basic/reflexion-learning.md +41 -0
- package/simulation/scenarios/README-basic/skill-evolution.md +38 -0
- package/simulation/scenarios/README-basic/stock-market-emergence.md +28 -0
- package/simulation/scenarios/README-basic/strange-loops.md +36 -0
- package/simulation/scenarios/README-basic/voting-system-consensus.md +28 -0
- package/simulation/scenarios/README.md +438 -0
- package/simulation/scenarios/aidefence-integration.ts +165 -0
- package/simulation/scenarios/bmssp-integration.ts +137 -0
- package/simulation/scenarios/causal-reasoning.ts +143 -0
- package/simulation/scenarios/consciousness-explorer.ts +139 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/performance.json +87 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/scenarios/domain-examples/README.md +525 -0
- package/simulation/scenarios/domain-examples/e-commerce-recommendations.ts +220 -0
- package/simulation/scenarios/domain-examples/index.ts +81 -0
- package/simulation/scenarios/domain-examples/iot-sensor-networks.ts +290 -0
- package/simulation/scenarios/domain-examples/medical-imaging.ts +181 -0
- package/simulation/scenarios/domain-examples/robotics-navigation.ts +214 -0
- package/simulation/scenarios/domain-examples/scientific-research.ts +250 -0
- package/simulation/scenarios/domain-examples/trading-systems.ts +138 -0
- package/simulation/scenarios/goalie-integration.ts +161 -0
- package/simulation/scenarios/graph-traversal.ts +129 -0
- package/simulation/scenarios/latent-space/OPTIMIZATION-COMPLETE.md +287 -0
- package/simulation/scenarios/latent-space/README-attention-analysis.md +170 -0
- package/simulation/scenarios/latent-space/README-clustering-analysis.md +239 -0
- package/simulation/scenarios/latent-space/README-hnsw-exploration.md +199 -0
- package/simulation/scenarios/latent-space/README-hypergraph-exploration.md +279 -0
- package/simulation/scenarios/latent-space/README-neural-augmentation.md +267 -0
- package/simulation/scenarios/latent-space/README-quantum-hybrid.md +276 -0
- package/simulation/scenarios/latent-space/README-self-organizing-hnsw.md +244 -0
- package/simulation/scenarios/latent-space/README-traversal-optimization.md +212 -0
- package/simulation/scenarios/latent-space/attention-analysis.ts +598 -0
- package/simulation/scenarios/latent-space/clustering-analysis.ts +796 -0
- package/simulation/scenarios/latent-space/hnsw-exploration.ts +526 -0
- package/simulation/scenarios/latent-space/hypergraph-exploration.ts +706 -0
- package/simulation/scenarios/latent-space/index.ts +47 -0
- package/simulation/scenarios/latent-space/neural-augmentation.ts +604 -0
- package/simulation/scenarios/latent-space/quantum-hybrid.ts +508 -0
- package/simulation/scenarios/latent-space/self-organizing-hnsw.ts +680 -0
- package/simulation/scenarios/latent-space/traversal-optimization.ts +782 -0
- package/simulation/scenarios/lean-agentic-swarm.ts +182 -0
- package/simulation/scenarios/multi-agent-swarm.ts +146 -0
- package/simulation/scenarios/psycho-symbolic-reasoner.ts +136 -0
- package/simulation/scenarios/reflexion-learning.ts +132 -0
- package/simulation/scenarios/research-swarm.ts +187 -0
- package/simulation/scenarios/skill-evolution.ts +135 -0
- package/simulation/scenarios/stock-market-emergence.ts +323 -0
- package/simulation/scenarios/strange-loops.ts +175 -0
- package/simulation/scenarios/sublinear-solver.ts +108 -0
- package/simulation/scenarios/temporal-lead-solver.ts +121 -0
- package/simulation/scenarios/voting-system-consensus.ts +251 -0
- package/simulation/tests/latent-space/attention-analysis.test.ts +204 -0
- package/simulation/tests/latent-space/clustering-analysis.test.ts +281 -0
- package/simulation/tests/latent-space/hnsw-exploration.test.ts +253 -0
- package/simulation/tests/latent-space/hypergraph-exploration.test.ts +295 -0
- package/simulation/tests/latent-space/neural-augmentation.test.ts +326 -0
- package/simulation/tests/latent-space/quantum-hybrid.test.ts +307 -0
- package/simulation/tests/latent-space/self-organizing-hnsw.test.ts +291 -0
- package/simulation/tests/latent-space/traversal-optimization.test.ts +261 -0
- package/simulation/types.ts +177 -0
- package/simulation/utils/PerformanceOptimizer.ts +269 -0
- package/src/cli/lib/history-tracker.ts +7 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attention Analysis Simulation Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests multi-head attention mechanism validation, query enhancement,
|
|
5
|
+
* and learning convergence for RuVector GNN integration.
|
|
6
|
+
*
|
|
7
|
+
* Target Metrics:
|
|
8
|
+
* - 8-head attention (optimal)
|
|
9
|
+
* - Forward pass <5ms (target: 3.8ms)
|
|
10
|
+
* - Query enhancement +12.4%
|
|
11
|
+
* - Convergence: 35 epochs to 95% performance
|
|
12
|
+
* - Transferability: 91% on unseen data
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
16
|
+
import { attentionAnalysisScenario } from '../../scenarios/latent-space/attention-analysis';
|
|
17
|
+
import type { SimulationReport } from '../../types';
|
|
18
|
+
|
|
19
|
+
describe('AttentionAnalysis', () => {
|
|
20
|
+
let report: SimulationReport;
|
|
21
|
+
|
|
22
|
+
beforeAll(async () => {
|
|
23
|
+
report = await attentionAnalysisScenario.run(attentionAnalysisScenario.config);
|
|
24
|
+
}, 60000); // 60s timeout
|
|
25
|
+
|
|
26
|
+
describe('Optimal Configuration', () => {
|
|
27
|
+
it('should use 8-head attention configuration', () => {
|
|
28
|
+
const bestConfig = report.summary.bestConfiguration;
|
|
29
|
+
expect(bestConfig.attentionConfig.heads).toBe(8);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should have 2-3 GNN layers', () => {
|
|
33
|
+
const bestConfig = report.summary.bestConfiguration;
|
|
34
|
+
expect(bestConfig.attentionConfig.layers).toBeGreaterThanOrEqual(2);
|
|
35
|
+
expect(bestConfig.attentionConfig.layers).toBeLessThanOrEqual(3);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should use GAT attention type', () => {
|
|
39
|
+
const bestConfig = report.summary.bestConfiguration;
|
|
40
|
+
expect(bestConfig.attentionConfig.attentionType).toBe('gat');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('Performance Metrics', () => {
|
|
45
|
+
it('should achieve forward pass <5ms', () => {
|
|
46
|
+
const bestResult = report.summary.bestConfiguration;
|
|
47
|
+
expect(bestResult.metrics.performance.forwardPassMs).toBeLessThan(5.0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should target ~3.8ms forward pass latency', () => {
|
|
51
|
+
const bestResult = report.summary.bestConfiguration;
|
|
52
|
+
expect(bestResult.metrics.performance.forwardPassMs).toBeCloseTo(3.8, 1);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should have reasonable backward pass time', () => {
|
|
56
|
+
const results = report.detailedResults as any[];
|
|
57
|
+
const avgBackward = results.reduce((sum, r) =>
|
|
58
|
+
sum + r.metrics.performance.backwardPassMs, 0) / results.length;
|
|
59
|
+
expect(avgBackward).toBeLessThan(15); // Should be <15ms
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should track memory usage', () => {
|
|
63
|
+
const bestResult = report.summary.bestConfiguration;
|
|
64
|
+
expect(bestResult.metrics.performance.memoryMB).toBeGreaterThan(0);
|
|
65
|
+
expect(bestResult.metrics.performance.memoryMB).toBeLessThan(1000); // Reasonable limit
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('Query Enhancement', () => {
|
|
70
|
+
it('should improve recall by >10%', () => {
|
|
71
|
+
const bestResult = report.summary.bestConfiguration;
|
|
72
|
+
expect(bestResult.metrics.queryEnhancement.recallImprovement).toBeGreaterThan(0.10);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should target +12.4% recall improvement', () => {
|
|
76
|
+
const bestResult = report.summary.bestConfiguration;
|
|
77
|
+
expect(bestResult.metrics.queryEnhancement.recallImprovement).toBeCloseTo(0.124, 0.03);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should improve NDCG scores', () => {
|
|
81
|
+
const bestResult = report.summary.bestConfiguration;
|
|
82
|
+
expect(bestResult.metrics.queryEnhancement.ndcgImprovement).toBeGreaterThan(0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should increase cosine similarity', () => {
|
|
86
|
+
const bestResult = report.summary.bestConfiguration;
|
|
87
|
+
expect(bestResult.metrics.queryEnhancement.cosineSimilarityGain).toBeGreaterThan(0.5);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('Learning Convergence', () => {
|
|
92
|
+
it('should converge within 50 epochs', () => {
|
|
93
|
+
const bestResult = report.summary.bestConfiguration;
|
|
94
|
+
expect(bestResult.metrics.learning.convergenceEpochs).toBeLessThan(50);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should target ~35 epochs to 95% performance', () => {
|
|
98
|
+
const bestResult = report.summary.bestConfiguration;
|
|
99
|
+
expect(bestResult.metrics.learning.convergenceEpochs).toBeCloseTo(35, 15);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should have high sample efficiency', () => {
|
|
103
|
+
const bestResult = report.summary.bestConfiguration;
|
|
104
|
+
expect(bestResult.metrics.learning.sampleEfficiency).toBeGreaterThan(0.85);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should achieve >90% transferability', () => {
|
|
108
|
+
const bestResult = report.summary.bestConfiguration;
|
|
109
|
+
expect(bestResult.metrics.learning.transferability).toBeGreaterThan(0.90);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should target 91% transferability on unseen data', () => {
|
|
113
|
+
const bestResult = report.summary.bestConfiguration;
|
|
114
|
+
expect(bestResult.metrics.learning.transferability).toBeCloseTo(0.91, 0.05);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('Attention Weight Distribution', () => {
|
|
119
|
+
it('should calculate entropy correctly', () => {
|
|
120
|
+
const results = report.detailedResults as any[];
|
|
121
|
+
const hasEntropy = results.some(r => r.metrics.weightDistribution.entropy > 0);
|
|
122
|
+
expect(hasEntropy).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should measure concentration (Gini coefficient)', () => {
|
|
126
|
+
const results = report.detailedResults as any[];
|
|
127
|
+
const ginis = results.map(r => r.metrics.weightDistribution.concentration);
|
|
128
|
+
expect(ginis.every(g => g >= 0 && g <= 1)).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should track sparsity percentage', () => {
|
|
132
|
+
const results = report.detailedResults as any[];
|
|
133
|
+
const sparsities = results.map(r => r.metrics.weightDistribution.sparsity);
|
|
134
|
+
expect(sparsities.every(s => s >= 0 && s <= 1)).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('Scalability Analysis', () => {
|
|
139
|
+
it('should test multiple vector counts', () => {
|
|
140
|
+
const vectorCounts = attentionAnalysisScenario.config.vectorCounts;
|
|
141
|
+
expect(vectorCounts.length).toBeGreaterThan(1);
|
|
142
|
+
expect(vectorCounts).toContain(100000);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should test multiple dimensions', () => {
|
|
146
|
+
const dimensions = attentionAnalysisScenario.config.dimensions;
|
|
147
|
+
expect(dimensions).toContain(384);
|
|
148
|
+
expect(dimensions).toContain(768);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should scale performance metrics', () => {
|
|
152
|
+
const scalability = report.metrics.scalabilityAnalysis;
|
|
153
|
+
expect(Array.isArray(scalability)).toBe(true);
|
|
154
|
+
expect(scalability.length).toBeGreaterThan(0);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('Industry Comparison', () => {
|
|
159
|
+
it('should compare with Pinterest PinSage', () => {
|
|
160
|
+
const comparison = report.summary.industryComparison;
|
|
161
|
+
expect(comparison).toHaveProperty('pinterestPinSage');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('should compare with Google Maps', () => {
|
|
165
|
+
const comparison = report.summary.industryComparison;
|
|
166
|
+
expect(comparison).toHaveProperty('googleMaps');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should provide competitive assessment', () => {
|
|
170
|
+
const comparison = report.summary.industryComparison;
|
|
171
|
+
expect(comparison).toHaveProperty('comparison');
|
|
172
|
+
expect(typeof comparison.comparison).toBe('string');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe('Report Generation', () => {
|
|
177
|
+
it('should generate complete simulation report', () => {
|
|
178
|
+
expect(report).toBeDefined();
|
|
179
|
+
expect(report.scenarioId).toBe('attention-analysis');
|
|
180
|
+
expect(report.timestamp).toBeDefined();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should include detailed analysis', () => {
|
|
184
|
+
expect(report.analysis).toBeDefined();
|
|
185
|
+
expect(report.analysis.length).toBeGreaterThan(100);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should provide recommendations', () => {
|
|
189
|
+
expect(report.recommendations).toBeDefined();
|
|
190
|
+
expect(report.recommendations.length).toBeGreaterThan(0);
|
|
191
|
+
expect(report.recommendations[0]).toContain('8');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should generate artifacts', () => {
|
|
195
|
+
expect(report.artifacts).toBeDefined();
|
|
196
|
+
expect(report.artifacts.attentionHeatmaps).toBeDefined();
|
|
197
|
+
expect(report.artifacts.weightDistributions).toBeDefined();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should complete within reasonable time', () => {
|
|
201
|
+
expect(report.executionTimeMs).toBeLessThan(60000); // <60s
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clustering Analysis Simulation Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests community detection algorithms and semantic clustering quality
|
|
5
|
+
* in RuVector's latent space.
|
|
6
|
+
*
|
|
7
|
+
* Target Metrics:
|
|
8
|
+
* - Louvain algorithm (optimal)
|
|
9
|
+
* - Modularity Q >0.75 (target: 0.758)
|
|
10
|
+
* - Semantic purity: 87.2%
|
|
11
|
+
* - Hierarchical levels: 3
|
|
12
|
+
* - Community detection quality
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
16
|
+
import { clusteringAnalysisScenario } from '../../scenarios/latent-space/clustering-analysis';
|
|
17
|
+
import type { SimulationReport } from '../../types';
|
|
18
|
+
|
|
19
|
+
describe('ClusteringAnalysis', () => {
|
|
20
|
+
let report: SimulationReport;
|
|
21
|
+
|
|
22
|
+
beforeAll(async () => {
|
|
23
|
+
report = await clusteringAnalysisScenario.run(clusteringAnalysisScenario.config);
|
|
24
|
+
}, 90000); // 90s timeout
|
|
25
|
+
|
|
26
|
+
describe('Optimal Algorithm', () => {
|
|
27
|
+
it('should select Louvain as best', () => {
|
|
28
|
+
const best = report.summary.bestAlgorithm;
|
|
29
|
+
expect(best.algorithm).toBe('louvain');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should test Louvain algorithm', () => {
|
|
33
|
+
const algorithms = clusteringAnalysisScenario.config.algorithms;
|
|
34
|
+
const louvain = algorithms.find(a => a.name === 'louvain');
|
|
35
|
+
expect(louvain).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should test Label Propagation', () => {
|
|
39
|
+
const algorithms = clusteringAnalysisScenario.config.algorithms;
|
|
40
|
+
const lp = algorithms.find(a => a.name === 'label-propagation');
|
|
41
|
+
expect(lp).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should test multiple algorithms', () => {
|
|
45
|
+
const algorithms = clusteringAnalysisScenario.config.algorithms;
|
|
46
|
+
expect(algorithms.length).toBeGreaterThanOrEqual(3);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('Modularity Score', () => {
|
|
51
|
+
it('should achieve Q >0.75', () => {
|
|
52
|
+
const avgModularity = report.summary.avgModularity;
|
|
53
|
+
expect(avgModularity).toBeGreaterThan(0.75);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should target Q=0.758', () => {
|
|
57
|
+
const avgModularity = report.summary.avgModularity;
|
|
58
|
+
expect(avgModularity).toBeCloseTo(0.758, 0.05);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should have positive modularity', () => {
|
|
62
|
+
const results = report.detailedResults as any[];
|
|
63
|
+
results.forEach(r => {
|
|
64
|
+
expect(r.metrics.modularityScore).toBeGreaterThan(0);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should not exceed 1.0', () => {
|
|
69
|
+
const results = report.detailedResults as any[];
|
|
70
|
+
results.forEach(r => {
|
|
71
|
+
expect(r.metrics.modularityScore).toBeLessThanOrEqual(1.0);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('Semantic Purity', () => {
|
|
77
|
+
it('should achieve >85% semantic purity', () => {
|
|
78
|
+
const purity = report.summary.semanticPurity;
|
|
79
|
+
expect(purity).toBeGreaterThan(0.85);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should target 87.2% semantic purity', () => {
|
|
83
|
+
const purity = report.summary.semanticPurity;
|
|
84
|
+
expect(purity).toBeCloseTo(0.872, 0.03);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should align graph clusters with embeddings', () => {
|
|
88
|
+
const results = report.detailedResults as any[];
|
|
89
|
+
results.forEach(r => {
|
|
90
|
+
expect(r.metrics.embeddingClusterOverlap).toBeGreaterThan(0.7);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('Community Structure', () => {
|
|
96
|
+
it('should detect multiple communities', () => {
|
|
97
|
+
const results = report.detailedResults as any[];
|
|
98
|
+
results.forEach(r => {
|
|
99
|
+
expect(r.metrics.numCommunities).toBeGreaterThan(1);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should have balanced distribution', () => {
|
|
104
|
+
const results = report.detailedResults as any[];
|
|
105
|
+
results.forEach(r => {
|
|
106
|
+
expect(Array.isArray(r.metrics.communityDistribution)).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should track community sizes', () => {
|
|
111
|
+
const metrics = report.metrics.communityStructure;
|
|
112
|
+
expect(metrics.avgNumCommunities).toBeGreaterThan(0);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('Hierarchical Properties', () => {
|
|
117
|
+
it('should have hierarchical depth', () => {
|
|
118
|
+
const results = report.detailedResults as any[];
|
|
119
|
+
results.forEach(r => {
|
|
120
|
+
expect(r.metrics.hierarchyDepth).toBeGreaterThan(0);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should target 3 hierarchical levels', () => {
|
|
125
|
+
const hierarchy = report.metrics.hierarchicalProperties;
|
|
126
|
+
if (hierarchy && hierarchy.avgDepth) {
|
|
127
|
+
expect(hierarchy.avgDepth).toBeCloseTo(3, 1);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should track dendrogram balance', () => {
|
|
132
|
+
const results = report.detailedResults as any[];
|
|
133
|
+
results.forEach(r => {
|
|
134
|
+
if (r.metrics.dendrogramBalance) {
|
|
135
|
+
expect(r.metrics.dendrogramBalance).toBeGreaterThan(0);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should record merging pattern', () => {
|
|
141
|
+
const results = report.detailedResults as any[];
|
|
142
|
+
results.forEach(r => {
|
|
143
|
+
expect(Array.isArray(r.metrics.mergingPattern)).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('Semantic Alignment', () => {
|
|
149
|
+
it('should measure cross-modal alignment', () => {
|
|
150
|
+
const results = report.detailedResults as any[];
|
|
151
|
+
results.forEach(r => {
|
|
152
|
+
if (r.metrics.crossModalAlignment) {
|
|
153
|
+
expect(r.metrics.crossModalAlignment).toBeGreaterThan(0.7);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should validate semantic categories', () => {
|
|
159
|
+
const categories = clusteringAnalysisScenario.config.semanticCategories;
|
|
160
|
+
expect(categories).toContain('text');
|
|
161
|
+
expect(categories).toContain('code');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('Agent Collaboration', () => {
|
|
166
|
+
it('should identify collaboration clusters', () => {
|
|
167
|
+
const results = report.detailedResults as any[];
|
|
168
|
+
results.forEach(r => {
|
|
169
|
+
expect(r.metrics.collaborationClusters).toBeGreaterThanOrEqual(0);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should measure task specialization', () => {
|
|
174
|
+
const results = report.detailedResults as any[];
|
|
175
|
+
results.forEach(r => {
|
|
176
|
+
if (r.metrics.taskSpecialization) {
|
|
177
|
+
expect(r.metrics.taskSpecialization).toBeGreaterThan(0.6);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should track communication efficiency', () => {
|
|
183
|
+
const results = report.detailedResults as any[];
|
|
184
|
+
results.forEach(r => {
|
|
185
|
+
if (r.metrics.communicationEfficiency) {
|
|
186
|
+
expect(r.metrics.communicationEfficiency).toBeGreaterThan(0.7);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('Algorithm Comparison', () => {
|
|
193
|
+
it('should compare Louvain vs Label Propagation', () => {
|
|
194
|
+
const louvain = (report.detailedResults as any[]).find(r => r.algorithm === 'louvain');
|
|
195
|
+
const lp = (report.detailedResults as any[]).find(r => r.algorithm === 'label-propagation');
|
|
196
|
+
|
|
197
|
+
if (louvain && lp) {
|
|
198
|
+
expect(louvain.metrics.modularityScore).toBeGreaterThan(0);
|
|
199
|
+
expect(lp.metrics.modularityScore).toBeGreaterThan(0);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should test Leiden algorithm', () => {
|
|
204
|
+
const leiden = (report.detailedResults as any[]).find(r => r.algorithm === 'leiden');
|
|
205
|
+
if (leiden) {
|
|
206
|
+
expect(leiden.metrics.modularityScore).toBeGreaterThan(0.7);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should test spectral clustering', () => {
|
|
211
|
+
const spectral = (report.detailedResults as any[]).find(r => r.algorithm === 'spectral');
|
|
212
|
+
if (spectral) {
|
|
213
|
+
expect(spectral.metrics.numCommunities).toBeGreaterThan(0);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('Graph Density Impact', () => {
|
|
219
|
+
it('should test multiple densities', () => {
|
|
220
|
+
const densities = clusteringAnalysisScenario.config.graphDensities;
|
|
221
|
+
expect(densities.length).toBeGreaterThanOrEqual(3);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should handle sparse graphs', () => {
|
|
225
|
+
const sparse = (report.detailedResults as any[]).filter(r => r.graphDensity === 0.01);
|
|
226
|
+
sparse.forEach(r => {
|
|
227
|
+
expect(r.metrics.modularityScore).toBeGreaterThan(0);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should handle dense graphs', () => {
|
|
232
|
+
const dense = (report.detailedResults as any[]).filter(r => r.graphDensity === 0.1);
|
|
233
|
+
dense.forEach(r => {
|
|
234
|
+
expect(r.metrics.modularityScore).toBeGreaterThan(0);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe('Scalability', () => {
|
|
240
|
+
it('should scale to 100k nodes', () => {
|
|
241
|
+
const sizes = clusteringAnalysisScenario.config.vectorCounts;
|
|
242
|
+
expect(sizes).toContain(100000);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should maintain quality at scale', () => {
|
|
246
|
+
const large = (report.detailedResults as any[]).filter(r => r.vectorCount === 100000);
|
|
247
|
+
large.forEach(r => {
|
|
248
|
+
expect(r.metrics.modularityScore).toBeGreaterThan(0.70);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('should track detection time', () => {
|
|
253
|
+
const results = report.detailedResults as any[];
|
|
254
|
+
results.forEach(r => {
|
|
255
|
+
expect(r.detectionTimeMs).toBeGreaterThan(0);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe('Report Generation', () => {
|
|
261
|
+
it('should generate analysis report', () => {
|
|
262
|
+
expect(report.analysis).toBeDefined();
|
|
263
|
+
expect(report.analysis).toContain('Clustering');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('should provide recommendations', () => {
|
|
267
|
+
expect(report.recommendations).toBeDefined();
|
|
268
|
+
expect(report.recommendations.some(r => r.includes('Louvain'))).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should generate visualizations', () => {
|
|
272
|
+
expect(report.artifacts.dendrograms).toBeDefined();
|
|
273
|
+
expect(report.artifacts.communityVisualizations).toBeDefined();
|
|
274
|
+
expect(report.artifacts.modularityCharts).toBeDefined();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('should complete within timeout', () => {
|
|
278
|
+
expect(report.executionTimeMs).toBeLessThan(90000);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|