@sparkleideas/ruv-swarm 1.0.18-patch.1

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.
Files changed (87) hide show
  1. package/README.md +1565 -0
  2. package/bin/ruv-swarm-clean.js +1872 -0
  3. package/bin/ruv-swarm-memory.js +119 -0
  4. package/bin/ruv-swarm-secure-heartbeat.js +1549 -0
  5. package/bin/ruv-swarm-secure.js +1689 -0
  6. package/package.json +221 -0
  7. package/src/agent.ts +342 -0
  8. package/src/benchmark.js +267 -0
  9. package/src/claude-flow-enhanced.js +839 -0
  10. package/src/claude-integration/advanced-commands.js +561 -0
  11. package/src/claude-integration/core.js +112 -0
  12. package/src/claude-integration/docs.js +1548 -0
  13. package/src/claude-integration/env-template.js +39 -0
  14. package/src/claude-integration/index.js +209 -0
  15. package/src/claude-integration/remote.js +408 -0
  16. package/src/cli-diagnostics.js +364 -0
  17. package/src/cognitive-pattern-evolution.js +1317 -0
  18. package/src/daa-cognition.js +977 -0
  19. package/src/daa-service.d.ts +298 -0
  20. package/src/daa-service.js +1116 -0
  21. package/src/diagnostics.js +533 -0
  22. package/src/errors.js +528 -0
  23. package/src/github-coordinator/README.md +193 -0
  24. package/src/github-coordinator/claude-hooks.js +162 -0
  25. package/src/github-coordinator/gh-cli-coordinator.js +260 -0
  26. package/src/hooks/cli.js +82 -0
  27. package/src/hooks/index.js +1900 -0
  28. package/src/index-enhanced.d.ts +371 -0
  29. package/src/index-enhanced.js +734 -0
  30. package/src/index.d.ts +287 -0
  31. package/src/index.js +405 -0
  32. package/src/index.ts +457 -0
  33. package/src/logger.js +182 -0
  34. package/src/logging-config.js +179 -0
  35. package/src/mcp-daa-tools.js +735 -0
  36. package/src/mcp-tools-benchmarks.js +328 -0
  37. package/src/mcp-tools-enhanced.js +2863 -0
  38. package/src/memory-config.js +42 -0
  39. package/src/meta-learning-framework.js +1359 -0
  40. package/src/neural-agent.js +830 -0
  41. package/src/neural-coordination-protocol.js +1363 -0
  42. package/src/neural-models/README.md +118 -0
  43. package/src/neural-models/autoencoder.js +543 -0
  44. package/src/neural-models/base.js +269 -0
  45. package/src/neural-models/cnn.js +497 -0
  46. package/src/neural-models/gnn.js +447 -0
  47. package/src/neural-models/gru.js +536 -0
  48. package/src/neural-models/index.js +273 -0
  49. package/src/neural-models/lstm.js +551 -0
  50. package/src/neural-models/neural-presets-complete.js +1306 -0
  51. package/src/neural-models/presets/graph.js +392 -0
  52. package/src/neural-models/presets/index.js +279 -0
  53. package/src/neural-models/presets/nlp.js +328 -0
  54. package/src/neural-models/presets/timeseries.js +368 -0
  55. package/src/neural-models/presets/vision.js +387 -0
  56. package/src/neural-models/resnet.js +534 -0
  57. package/src/neural-models/transformer.js +515 -0
  58. package/src/neural-models/vae.js +489 -0
  59. package/src/neural-network-manager.js +1938 -0
  60. package/src/neural-network.ts +296 -0
  61. package/src/neural.js +574 -0
  62. package/src/performance-benchmarks.js +898 -0
  63. package/src/performance.js +458 -0
  64. package/src/persistence-pooled.js +695 -0
  65. package/src/persistence.js +480 -0
  66. package/src/schemas.js +864 -0
  67. package/src/security.js +218 -0
  68. package/src/singleton-container.js +183 -0
  69. package/src/sqlite-pool.js +587 -0
  70. package/src/sqlite-worker.js +141 -0
  71. package/src/types.ts +164 -0
  72. package/src/utils.ts +286 -0
  73. package/src/wasm-loader.js +601 -0
  74. package/src/wasm-loader2.js +404 -0
  75. package/src/wasm-memory-optimizer.js +783 -0
  76. package/src/wasm-types.d.ts +63 -0
  77. package/wasm/README.md +347 -0
  78. package/wasm/neuro-divergent.wasm +0 -0
  79. package/wasm/package.json +18 -0
  80. package/wasm/ruv-fann.wasm +0 -0
  81. package/wasm/ruv_swarm_simd.wasm +0 -0
  82. package/wasm/ruv_swarm_wasm.d.ts +391 -0
  83. package/wasm/ruv_swarm_wasm.js +2164 -0
  84. package/wasm/ruv_swarm_wasm_bg.wasm +0 -0
  85. package/wasm/ruv_swarm_wasm_bg.wasm.d.ts +123 -0
  86. package/wasm/wasm-bindings-loader.mjs +435 -0
  87. package/wasm/wasm-updates.md +684 -0
@@ -0,0 +1,392 @@
1
+ /**
2
+ * Graph Analysis Neural Network Presets
3
+ * Production-ready configurations for graph-based learning tasks
4
+ */
5
+
6
+ export const graphPresets = {
7
+ // Social Network Influence
8
+ social_network_influence: {
9
+ name: 'Social Network Influence Predictor',
10
+ description: 'Predict influence propagation in social networks',
11
+ model: 'gnn',
12
+ config: {
13
+ nodeDimensions: 256,
14
+ edgeDimensions: 128,
15
+ hiddenDimensions: 512,
16
+ outputDimensions: 64,
17
+ numLayers: 4,
18
+ aggregation: 'attention',
19
+ messagePassingType: 'gcn',
20
+ readoutFunction: 'mean',
21
+ dropoutRate: 0.3,
22
+ useResidualConnections: true,
23
+ },
24
+ training: {
25
+ batchSize: 16,
26
+ learningRate: 1e-3,
27
+ epochs: 150,
28
+ optimizer: 'adam',
29
+ scheduler: 'cosine',
30
+ graphSampling: 'fastgcn',
31
+ samplingDepth: 2,
32
+ samplingWidth: 20,
33
+ },
34
+ performance: {
35
+ expectedAccuracy: '84-87% influence prediction',
36
+ inferenceTime: '25ms per graph',
37
+ memoryUsage: '800MB',
38
+ trainingTime: '12-16 hours on GPU',
39
+ },
40
+ useCase: 'Social media marketing, viral content prediction, community detection',
41
+ },
42
+
43
+ // Fraud Detection Financial
44
+ fraud_detection_financial: {
45
+ name: 'Financial Fraud Detector',
46
+ description: 'Detect fraudulent transactions in financial networks',
47
+ model: 'gnn',
48
+ config: {
49
+ nodeDimensions: 128,
50
+ edgeDimensions: 64,
51
+ hiddenDimensions: 256,
52
+ outputDimensions: 2, // Fraud/Not fraud
53
+ numLayers: 3,
54
+ aggregation: 'max',
55
+ messagePassingType: 'gat',
56
+ attentionHeads: 4,
57
+ dropoutRate: 0.4,
58
+ useEdgeFeatures: true,
59
+ temporalAggregation: true,
60
+ },
61
+ training: {
62
+ batchSize: 32,
63
+ learningRate: 5e-4,
64
+ epochs: 200,
65
+ optimizer: 'adamw',
66
+ lossFunction: 'focal_loss',
67
+ focalGamma: 2.0,
68
+ classWeights: [1.0, 50.0], // Heavy penalty for missing fraud
69
+ graphAugmentation: {
70
+ nodeDropout: 0.1,
71
+ edgeDropout: 0.05,
72
+ },
73
+ },
74
+ performance: {
75
+ expectedAccuracy: '96-98% precision on fraud class',
76
+ inferenceTime: '8ms per transaction',
77
+ memoryUsage: '400MB',
78
+ trainingTime: '24-36 hours on GPU',
79
+ },
80
+ useCase: 'Credit card fraud, money laundering detection, banking security',
81
+ },
82
+
83
+ // Recommendation Engine
84
+ recommendation_engine: {
85
+ name: 'Graph-based Recommender',
86
+ description: 'User-item recommendation using graph neural networks',
87
+ model: 'gnn',
88
+ config: {
89
+ nodeDimensions: 64,
90
+ edgeDimensions: 32,
91
+ hiddenDimensions: 128,
92
+ embeddingDimensions: 64,
93
+ numLayers: 3,
94
+ aggregation: 'mean',
95
+ messagePassingType: 'lightgcn',
96
+ useUserItemBias: true,
97
+ dropoutRate: 0.1,
98
+ negativeSampling: 5,
99
+ },
100
+ training: {
101
+ batchSize: 1024,
102
+ learningRate: 2e-3,
103
+ epochs: 100,
104
+ optimizer: 'adam',
105
+ lossFunction: 'bpr_loss',
106
+ regularizationWeight: 1e-4,
107
+ evaluationMetrics: ['recall@10', 'ndcg@10'],
108
+ edgeSampling: 'random_walk',
109
+ },
110
+ performance: {
111
+ expectedAccuracy: '88-91% Recall@10',
112
+ inferenceTime: '2ms per user',
113
+ memoryUsage: '600MB',
114
+ trainingTime: '8-12 hours on GPU',
115
+ },
116
+ useCase: 'E-commerce, content streaming, social media feeds',
117
+ },
118
+
119
+ // Knowledge Graph QA
120
+ knowledge_graph_qa: {
121
+ name: 'Knowledge Graph Question Answering',
122
+ description: 'Answer questions using knowledge graph reasoning',
123
+ model: 'gnn',
124
+ config: {
125
+ nodeDimensions: 300, // Entity embeddings
126
+ edgeDimensions: 100, // Relation embeddings
127
+ hiddenDimensions: 400,
128
+ outputDimensions: 1, // Answer score
129
+ numLayers: 5,
130
+ aggregation: 'attention',
131
+ messagePassingType: 'rgcn',
132
+ numRelationTypes: 200,
133
+ questionEncoder: 'lstm',
134
+ questionEmbeddingSize: 256,
135
+ multiHopReasoning: true,
136
+ },
137
+ training: {
138
+ batchSize: 8,
139
+ learningRate: 1e-4,
140
+ epochs: 80,
141
+ optimizer: 'adamw',
142
+ gradientClipping: 1.0,
143
+ subgraphSampling: 'khop',
144
+ samplingHops: 3,
145
+ negativeAnswers: 10,
146
+ },
147
+ performance: {
148
+ expectedAccuracy: '78-82% answer accuracy',
149
+ inferenceTime: '150ms per question',
150
+ memoryUsage: '1.2GB',
151
+ trainingTime: '48-72 hours on GPU',
152
+ },
153
+ useCase: 'Intelligent search, virtual assistants, fact checking',
154
+ },
155
+
156
+ // Supply Chain Optimization
157
+ supply_chain_optimization: {
158
+ name: 'Supply Chain Network Optimizer',
159
+ description: 'Optimize supply chain operations using graph analysis',
160
+ model: 'gnn',
161
+ config: {
162
+ nodeDimensions: 200, // Supplier/warehouse features
163
+ edgeDimensions: 50, // Transportation features
164
+ hiddenDimensions: 300,
165
+ outputDimensions: 100, // Optimization decisions
166
+ numLayers: 4,
167
+ aggregation: 'sum',
168
+ messagePassingType: 'graphsage',
169
+ samplerType: 'neighbor',
170
+ useTemporalFeatures: true,
171
+ constraintHandling: true,
172
+ },
173
+ training: {
174
+ batchSize: 12,
175
+ learningRate: 3e-4,
176
+ epochs: 120,
177
+ optimizer: 'adam',
178
+ lossFunction: 'custom_cost_minimization',
179
+ constraintPenalty: 100.0,
180
+ simulationBasedTraining: true,
181
+ realTimeAdaptation: true,
182
+ },
183
+ performance: {
184
+ expectedAccuracy: '12-15% cost reduction',
185
+ inferenceTime: '50ms per decision',
186
+ memoryUsage: '700MB',
187
+ trainingTime: '24-36 hours on GPU',
188
+ },
189
+ useCase: 'Logistics optimization, inventory management, route planning',
190
+ },
191
+
192
+ // Molecular Property Prediction
193
+ molecular_property_prediction: {
194
+ name: 'Molecular Property Predictor',
195
+ description: 'Predict molecular properties for drug discovery',
196
+ model: 'gnn',
197
+ config: {
198
+ nodeDimensions: 74, // Atom features
199
+ edgeDimensions: 12, // Bond features
200
+ hiddenDimensions: 256,
201
+ outputDimensions: 1, // Property value
202
+ numLayers: 5,
203
+ aggregation: 'mean',
204
+ messagePassingType: 'mpnn',
205
+ globalPooling: 'set2set',
206
+ readoutLayers: [128, 64],
207
+ dropoutRate: 0.2,
208
+ },
209
+ training: {
210
+ batchSize: 64,
211
+ learningRate: 1e-3,
212
+ epochs: 200,
213
+ optimizer: 'adam',
214
+ lossFunction: 'mae',
215
+ scheduler: 'plateau',
216
+ molecularAugmentation: {
217
+ randomRotation: true,
218
+ atomMasking: 0.1,
219
+ bondDropout: 0.05,
220
+ },
221
+ },
222
+ performance: {
223
+ expectedAccuracy: '85-88% R² for solubility',
224
+ inferenceTime: '5ms per molecule',
225
+ memoryUsage: '300MB',
226
+ trainingTime: '16-24 hours on GPU',
227
+ },
228
+ useCase: 'Drug discovery, material science, chemical engineering',
229
+ },
230
+
231
+ // Traffic Flow Prediction
232
+ traffic_flow_prediction: {
233
+ name: 'Urban Traffic Flow Predictor',
234
+ description: 'Predict traffic patterns in road networks',
235
+ model: 'gnn',
236
+ config: {
237
+ nodeDimensions: 20, // Road segment features
238
+ edgeDimensions: 10, // Connection features
239
+ hiddenDimensions: 128,
240
+ outputDimensions: 12, // 12 future time steps
241
+ numLayers: 3,
242
+ aggregation: 'attention',
243
+ messagePassingType: 'gcn',
244
+ temporalConvolution: true,
245
+ spatialTemporalFusion: 'gated',
246
+ dropoutRate: 0.25,
247
+ },
248
+ training: {
249
+ batchSize: 24,
250
+ learningRate: 2e-3,
251
+ epochs: 100,
252
+ optimizer: 'adam',
253
+ lossFunction: 'masked_mae',
254
+ maskingRatio: 0.1,
255
+ timeSeriesSplit: true,
256
+ augmentation: {
257
+ temporalJitter: 0.1,
258
+ gaussianNoise: 0.05,
259
+ },
260
+ },
261
+ performance: {
262
+ expectedAccuracy: '91-94% MAE < 15%',
263
+ inferenceTime: '15ms per prediction',
264
+ memoryUsage: '500MB',
265
+ trainingTime: '12-18 hours on GPU',
266
+ },
267
+ useCase: 'Smart city planning, traffic management, route optimization',
268
+ },
269
+
270
+ // Scientific Citation Analysis
271
+ citation_analysis: {
272
+ name: 'Scientific Citation Analyzer',
273
+ description: 'Analyze citation networks for research insights',
274
+ model: 'gnn',
275
+ config: {
276
+ nodeDimensions: 512, // Paper embeddings
277
+ edgeDimensions: 64, // Citation context
278
+ hiddenDimensions: 256,
279
+ outputDimensions: 128, // Paper influence score
280
+ numLayers: 4,
281
+ aggregation: 'attention',
282
+ messagePassingType: 'gat',
283
+ attentionHeads: 8,
284
+ temporalEvolution: true,
285
+ fieldSpecialization: true,
286
+ },
287
+ training: {
288
+ batchSize: 16,
289
+ learningRate: 5e-4,
290
+ epochs: 150,
291
+ optimizer: 'adamw',
292
+ lossFunction: 'ranking_loss',
293
+ marginRanking: 1.0,
294
+ metaPathSampling: true,
295
+ communityAware: true,
296
+ },
297
+ performance: {
298
+ expectedAccuracy: '86-89% citation prediction',
299
+ inferenceTime: '30ms per paper',
300
+ memoryUsage: '1GB',
301
+ trainingTime: '36-48 hours on GPU',
302
+ },
303
+ useCase: 'Research recommendation, impact prediction, academic analytics',
304
+ },
305
+
306
+ // Protein-Protein Interaction
307
+ protein_interaction: {
308
+ name: 'Protein Interaction Predictor',
309
+ description: 'Predict protein-protein interactions',
310
+ model: 'gnn',
311
+ config: {
312
+ nodeDimensions: 1280, // Protein sequence embeddings
313
+ edgeDimensions: 100, // Interaction features
314
+ hiddenDimensions: 512,
315
+ outputDimensions: 1, // Interaction probability
316
+ numLayers: 6,
317
+ aggregation: 'mean',
318
+ messagePassingType: 'gin',
319
+ proteinEncoder: 'esm',
320
+ structuralFeatures: true,
321
+ dropoutRate: 0.3,
322
+ },
323
+ training: {
324
+ batchSize: 8,
325
+ learningRate: 1e-4,
326
+ epochs: 100,
327
+ optimizer: 'adamw',
328
+ lossFunction: 'weighted_bce',
329
+ classImbalance: 100, // Many more negative than positive examples
330
+ crossValidation: 'species_split',
331
+ augmentation: {
332
+ sequenceNoise: 0.02,
333
+ structuralPerturbation: 0.1,
334
+ },
335
+ },
336
+ performance: {
337
+ expectedAccuracy: '92-94% AUC-ROC',
338
+ inferenceTime: '100ms per protein pair',
339
+ memoryUsage: '2GB',
340
+ trainingTime: '3-5 days on GPU',
341
+ },
342
+ useCase: 'Drug target identification, pathway analysis, systems biology',
343
+ },
344
+
345
+ // Cybersecurity Threat Detection
346
+ cybersecurity_threat: {
347
+ name: 'Network Threat Detector',
348
+ description: 'Detect cybersecurity threats in network graphs',
349
+ model: 'gnn',
350
+ config: {
351
+ nodeDimensions: 100, // Host/device features
352
+ edgeDimensions: 50, // Network connection features
353
+ hiddenDimensions: 200,
354
+ outputDimensions: 5, // Threat categories
355
+ numLayers: 3,
356
+ aggregation: 'max',
357
+ messagePassingType: 'graphsaint',
358
+ temporalAggregation: 'gru',
359
+ anomalyDetection: true,
360
+ dropoutRate: 0.35,
361
+ },
362
+ training: {
363
+ batchSize: 32,
364
+ learningRate: 1e-3,
365
+ epochs: 80,
366
+ optimizer: 'adam',
367
+ lossFunction: 'focal_loss',
368
+ onlineLearning: true,
369
+ adaptationRate: 0.01,
370
+ adversarialTraining: true,
371
+ fewShotAdaptation: true,
372
+ },
373
+ performance: {
374
+ expectedAccuracy: '94-96% threat detection',
375
+ inferenceTime: '10ms per network state',
376
+ memoryUsage: '400MB',
377
+ trainingTime: '16-24 hours on GPU',
378
+ },
379
+ useCase: 'Network security, intrusion detection, malware analysis',
380
+ },
381
+ };
382
+
383
+ // Export utility function to get preset by name
384
+ export const getGraphPreset = (presetName) => {
385
+ if (!graphPresets[presetName]) {
386
+ throw new Error(`Graph preset '${presetName}' not found. Available presets: ${Object.keys(graphPresets).join(', ')}`);
387
+ }
388
+ return graphPresets[presetName];
389
+ };
390
+
391
+ // Export list of available presets
392
+ export const availableGraphPresets = Object.keys(graphPresets);
@@ -0,0 +1,279 @@
1
+ /**
2
+ * Neural Network Presets Index
3
+ * Centralized access to all production-ready neural network configurations
4
+ */
5
+
6
+ import { nlpPresets, getNLPPreset, availableNLPPresets } from './nlp.js';
7
+ import { visionPresets, getVisionPreset, availableVisionPresets } from './vision.js';
8
+ import { timeSeriesPresets, getTimeSeriesPreset, availableTimeSeriesPresets } from './timeseries.js';
9
+ import { graphPresets, getGraphPreset, availableGraphPresets } from './graph.js';
10
+
11
+ // Combined presets object
12
+ export const NEURAL_PRESETS = {
13
+ nlp: nlpPresets,
14
+ vision: visionPresets,
15
+ timeseries: timeSeriesPresets,
16
+ graph: graphPresets,
17
+ };
18
+
19
+ // Category-specific getters
20
+ export {
21
+ getNLPPreset,
22
+ getVisionPreset,
23
+ getTimeSeriesPreset,
24
+ getGraphPreset,
25
+ };
26
+
27
+ // Available presets lists
28
+ export {
29
+ availableNLPPresets,
30
+ availableVisionPresets,
31
+ availableTimeSeriesPresets,
32
+ availableGraphPresets,
33
+ };
34
+
35
+ // Universal preset getter function
36
+ export const getPreset = (category, presetName) => {
37
+ const categoryMap = {
38
+ nlp: getNLPPreset,
39
+ vision: getVisionPreset,
40
+ timeseries: getTimeSeriesPreset,
41
+ graph: getGraphPreset,
42
+ };
43
+
44
+ if (!categoryMap[category]) {
45
+ throw new Error(`Unknown preset category: ${category}. Available categories: ${Object.keys(categoryMap).join(', ')}`);
46
+ }
47
+
48
+ return categoryMap[category](presetName);
49
+ };
50
+
51
+ // Get all presets for a category
52
+ export const getCategoryPresets = (category) => {
53
+ const categoryMap = {
54
+ nlp: nlpPresets,
55
+ vision: visionPresets,
56
+ timeseries: timeSeriesPresets,
57
+ graph: graphPresets,
58
+ };
59
+
60
+ if (!categoryMap[category]) {
61
+ throw new Error(`Unknown preset category: ${category}. Available categories: ${Object.keys(categoryMap).join(', ')}`);
62
+ }
63
+
64
+ return categoryMap[category];
65
+ };
66
+
67
+ // Get all available preset names by category
68
+ export const getAllPresetNames = () => {
69
+ return {
70
+ nlp: availableNLPPresets,
71
+ vision: availableVisionPresets,
72
+ timeseries: availableTimeSeriesPresets,
73
+ graph: availableGraphPresets,
74
+ };
75
+ };
76
+
77
+ // Search presets by use case
78
+ export const searchPresetsByUseCase = (searchTerm) => {
79
+ const results = [];
80
+ const searchLower = searchTerm.toLowerCase();
81
+
82
+ Object.entries(NEURAL_PRESETS).forEach(([category, presets]) => {
83
+ Object.entries(presets).forEach(([presetName, preset]) => {
84
+ if (
85
+ preset.useCase.toLowerCase().includes(searchLower) ||
86
+ preset.name.toLowerCase().includes(searchLower) ||
87
+ preset.description.toLowerCase().includes(searchLower)
88
+ ) {
89
+ results.push({
90
+ category,
91
+ presetName,
92
+ preset,
93
+ });
94
+ }
95
+ });
96
+ });
97
+
98
+ return results;
99
+ };
100
+
101
+ // Search presets by accuracy range
102
+ export const searchPresetsByAccuracy = (minAccuracy) => {
103
+ const results = [];
104
+
105
+ Object.entries(NEURAL_PRESETS).forEach(([category, presets]) => {
106
+ Object.entries(presets).forEach(([presetName, preset]) => {
107
+ const accuracyStr = preset.performance.expectedAccuracy;
108
+ const accuracyMatch = accuracyStr.match(/(\d+)-?(\d+)?%/);
109
+
110
+ if (accuracyMatch) {
111
+ const minAcc = parseInt(accuracyMatch[1], 10);
112
+ if (minAcc >= minAccuracy) {
113
+ results.push({
114
+ category,
115
+ presetName,
116
+ preset,
117
+ accuracy: minAcc,
118
+ });
119
+ }
120
+ }
121
+ });
122
+ });
123
+
124
+ return results.sort((a, b) => b.accuracy - a.accuracy);
125
+ };
126
+
127
+ // Search presets by inference time
128
+ export const searchPresetsByInferenceTime = (maxTimeMs) => {
129
+ const results = [];
130
+
131
+ Object.entries(NEURAL_PRESETS).forEach(([category, presets]) => {
132
+ Object.entries(presets).forEach(([presetName, preset]) => {
133
+ const timeStr = preset.performance.inferenceTime;
134
+ const timeMatch = timeStr.match(/(\d+)ms/);
135
+
136
+ if (timeMatch) {
137
+ const timeMs = parseInt(timeMatch[1], 10);
138
+ if (timeMs <= maxTimeMs) {
139
+ results.push({
140
+ category,
141
+ presetName,
142
+ preset,
143
+ inferenceTime: timeMs,
144
+ });
145
+ }
146
+ }
147
+ });
148
+ });
149
+
150
+ return results.sort((a, b) => a.inferenceTime - b.inferenceTime);
151
+ };
152
+
153
+ // Get preset statistics
154
+ export const getPresetStatistics = () => {
155
+ const stats = {
156
+ totalPresets: 0,
157
+ categories: {},
158
+ models: {},
159
+ accuracyRanges: {
160
+ '90-100%': 0,
161
+ '80-89%': 0,
162
+ '70-79%': 0,
163
+ 'below-70%': 0,
164
+ },
165
+ inferenceTimeRanges: {
166
+ 'under-10ms': 0,
167
+ '10-50ms': 0,
168
+ '50-100ms': 0,
169
+ 'over-100ms': 0,
170
+ },
171
+ };
172
+
173
+ Object.entries(NEURAL_PRESETS).forEach(([category, presets]) => {
174
+ stats.categories[category] = Object.keys(presets).length;
175
+ stats.totalPresets += Object.keys(presets).length;
176
+
177
+ Object.values(presets).forEach(preset => {
178
+ // Count model types
179
+ const modelType = preset.model;
180
+ stats.models[modelType] = (stats.models[modelType] || 0) + 1;
181
+
182
+ // Categorize accuracy
183
+ const accuracyStr = preset.performance.expectedAccuracy;
184
+ const accuracyMatch = accuracyStr.match(/(\d+)-?(\d+)?%/);
185
+ if (accuracyMatch) {
186
+ const minAcc = parseInt(accuracyMatch[1], 10);
187
+ if (minAcc >= 90) {
188
+ stats.accuracyRanges['90-100%']++;
189
+ } else if (minAcc >= 80) {
190
+ stats.accuracyRanges['80-89%']++;
191
+ } else if (minAcc >= 70) {
192
+ stats.accuracyRanges['70-79%']++;
193
+ } else {
194
+ stats.accuracyRanges['below-70%']++;
195
+ }
196
+ }
197
+
198
+ // Categorize inference time
199
+ const timeStr = preset.performance.inferenceTime;
200
+ const timeMatch = timeStr.match(/(\d+)ms/);
201
+ if (timeMatch) {
202
+ const timeMs = parseInt(timeMatch[1], 10);
203
+ if (timeMs < 10) {
204
+ stats.inferenceTimeRanges['under-10ms']++;
205
+ } else if (timeMs < 50) {
206
+ stats.inferenceTimeRanges['10-50ms']++;
207
+ } else if (timeMs < 100) {
208
+ stats.inferenceTimeRanges['50-100ms']++;
209
+ } else {
210
+ stats.inferenceTimeRanges['over-100ms']++;
211
+ }
212
+ }
213
+ });
214
+ });
215
+
216
+ return stats;
217
+ };
218
+
219
+ // Export preset categories for easy reference
220
+ export const PRESET_CATEGORIES = {
221
+ NLP: 'nlp',
222
+ VISION: 'vision',
223
+ TIME_SERIES: 'timeseries',
224
+ GRAPH: 'graph',
225
+ };
226
+
227
+ // Export model types used in presets
228
+ export const PRESET_MODEL_TYPES = [
229
+ 'transformer',
230
+ 'cnn',
231
+ 'lstm',
232
+ 'gru',
233
+ 'autoencoder',
234
+ 'gnn',
235
+ 'resnet',
236
+ 'vae',
237
+ ];
238
+
239
+ // Utility function to validate preset configuration
240
+ export const validatePresetConfig = (preset) => {
241
+ const requiredFields = ['name', 'description', 'model', 'config', 'training', 'performance', 'useCase'];
242
+ const missingFields = requiredFields.filter(field => !preset[field]);
243
+
244
+ if (missingFields.length > 0) {
245
+ throw new Error(`Preset validation failed. Missing fields: ${missingFields.join(', ')}`);
246
+ }
247
+
248
+ // Validate performance fields
249
+ const requiredPerformanceFields = ['expectedAccuracy', 'inferenceTime', 'memoryUsage', 'trainingTime'];
250
+ const missingPerfFields = requiredPerformanceFields.filter(field => !preset.performance[field]);
251
+
252
+ if (missingPerfFields.length > 0) {
253
+ throw new Error(`Preset performance validation failed. Missing fields: ${missingPerfFields.join(', ')}`);
254
+ }
255
+
256
+ return true;
257
+ };
258
+
259
+ // Export default preset recommendations by use case
260
+ export const DEFAULT_RECOMMENDATIONS = {
261
+ 'chatbot': { category: 'nlp', preset: 'conversational_ai' },
262
+ 'sentiment_analysis': { category: 'nlp', preset: 'sentiment_analysis_social' },
263
+ 'object_detection': { category: 'vision', preset: 'object_detection_realtime' },
264
+ 'face_recognition': { category: 'vision', preset: 'facial_recognition_secure' },
265
+ 'stock_prediction': { category: 'timeseries', preset: 'stock_market_prediction' },
266
+ 'weather_forecast': { category: 'timeseries', preset: 'weather_forecasting' },
267
+ 'fraud_detection': { category: 'graph', preset: 'fraud_detection_financial' },
268
+ 'recommendation': { category: 'graph', preset: 'recommendation_engine' },
269
+ };
270
+
271
+ // Get recommended preset for a use case
272
+ export const getRecommendedPreset = (useCase) => {
273
+ const recommendation = DEFAULT_RECOMMENDATIONS[useCase.toLowerCase()];
274
+ if (!recommendation) {
275
+ return null;
276
+ }
277
+
278
+ return getPreset(recommendation.category, recommendation.preset);
279
+ };