@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.
- package/README.md +1565 -0
- package/bin/ruv-swarm-clean.js +1872 -0
- package/bin/ruv-swarm-memory.js +119 -0
- package/bin/ruv-swarm-secure-heartbeat.js +1549 -0
- package/bin/ruv-swarm-secure.js +1689 -0
- package/package.json +221 -0
- package/src/agent.ts +342 -0
- package/src/benchmark.js +267 -0
- package/src/claude-flow-enhanced.js +839 -0
- package/src/claude-integration/advanced-commands.js +561 -0
- package/src/claude-integration/core.js +112 -0
- package/src/claude-integration/docs.js +1548 -0
- package/src/claude-integration/env-template.js +39 -0
- package/src/claude-integration/index.js +209 -0
- package/src/claude-integration/remote.js +408 -0
- package/src/cli-diagnostics.js +364 -0
- package/src/cognitive-pattern-evolution.js +1317 -0
- package/src/daa-cognition.js +977 -0
- package/src/daa-service.d.ts +298 -0
- package/src/daa-service.js +1116 -0
- package/src/diagnostics.js +533 -0
- package/src/errors.js +528 -0
- package/src/github-coordinator/README.md +193 -0
- package/src/github-coordinator/claude-hooks.js +162 -0
- package/src/github-coordinator/gh-cli-coordinator.js +260 -0
- package/src/hooks/cli.js +82 -0
- package/src/hooks/index.js +1900 -0
- package/src/index-enhanced.d.ts +371 -0
- package/src/index-enhanced.js +734 -0
- package/src/index.d.ts +287 -0
- package/src/index.js +405 -0
- package/src/index.ts +457 -0
- package/src/logger.js +182 -0
- package/src/logging-config.js +179 -0
- package/src/mcp-daa-tools.js +735 -0
- package/src/mcp-tools-benchmarks.js +328 -0
- package/src/mcp-tools-enhanced.js +2863 -0
- package/src/memory-config.js +42 -0
- package/src/meta-learning-framework.js +1359 -0
- package/src/neural-agent.js +830 -0
- package/src/neural-coordination-protocol.js +1363 -0
- package/src/neural-models/README.md +118 -0
- package/src/neural-models/autoencoder.js +543 -0
- package/src/neural-models/base.js +269 -0
- package/src/neural-models/cnn.js +497 -0
- package/src/neural-models/gnn.js +447 -0
- package/src/neural-models/gru.js +536 -0
- package/src/neural-models/index.js +273 -0
- package/src/neural-models/lstm.js +551 -0
- package/src/neural-models/neural-presets-complete.js +1306 -0
- package/src/neural-models/presets/graph.js +392 -0
- package/src/neural-models/presets/index.js +279 -0
- package/src/neural-models/presets/nlp.js +328 -0
- package/src/neural-models/presets/timeseries.js +368 -0
- package/src/neural-models/presets/vision.js +387 -0
- package/src/neural-models/resnet.js +534 -0
- package/src/neural-models/transformer.js +515 -0
- package/src/neural-models/vae.js +489 -0
- package/src/neural-network-manager.js +1938 -0
- package/src/neural-network.ts +296 -0
- package/src/neural.js +574 -0
- package/src/performance-benchmarks.js +898 -0
- package/src/performance.js +458 -0
- package/src/persistence-pooled.js +695 -0
- package/src/persistence.js +480 -0
- package/src/schemas.js +864 -0
- package/src/security.js +218 -0
- package/src/singleton-container.js +183 -0
- package/src/sqlite-pool.js +587 -0
- package/src/sqlite-worker.js +141 -0
- package/src/types.ts +164 -0
- package/src/utils.ts +286 -0
- package/src/wasm-loader.js +601 -0
- package/src/wasm-loader2.js +404 -0
- package/src/wasm-memory-optimizer.js +783 -0
- package/src/wasm-types.d.ts +63 -0
- package/wasm/README.md +347 -0
- package/wasm/neuro-divergent.wasm +0 -0
- package/wasm/package.json +18 -0
- package/wasm/ruv-fann.wasm +0 -0
- package/wasm/ruv_swarm_simd.wasm +0 -0
- package/wasm/ruv_swarm_wasm.d.ts +391 -0
- package/wasm/ruv_swarm_wasm.js +2164 -0
- package/wasm/ruv_swarm_wasm_bg.wasm +0 -0
- package/wasm/ruv_swarm_wasm_bg.wasm.d.ts +123 -0
- package/wasm/wasm-bindings-loader.mjs +435 -0
- package/wasm/wasm-updates.md +684 -0
|
@@ -0,0 +1,1359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta-Learning Framework
|
|
3
|
+
* Enables learning how to learn and domain adaptation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class MetaLearningFramework {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.agentExperiences = new Map();
|
|
9
|
+
this.domainAdaptations = new Map();
|
|
10
|
+
this.transferLearning = new Map();
|
|
11
|
+
this.metaStrategies = new Map();
|
|
12
|
+
this.learningMetrics = new Map();
|
|
13
|
+
|
|
14
|
+
// Initialize meta-learning strategies
|
|
15
|
+
this.initializeMetaStrategies();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Initialize meta-learning strategies
|
|
20
|
+
*/
|
|
21
|
+
initializeMetaStrategies() {
|
|
22
|
+
// Model-Agnostic Meta-Learning (MAML)
|
|
23
|
+
this.metaStrategies.set('maml', {
|
|
24
|
+
name: 'Model-Agnostic Meta-Learning',
|
|
25
|
+
description: 'Learn good parameter initializations for quick adaptation',
|
|
26
|
+
type: 'gradient_based',
|
|
27
|
+
parameters: {
|
|
28
|
+
innerLearningRate: 0.01,
|
|
29
|
+
outerLearningRate: 0.001,
|
|
30
|
+
innerSteps: 5,
|
|
31
|
+
metaBatchSize: 4,
|
|
32
|
+
},
|
|
33
|
+
applicability: {
|
|
34
|
+
fewShotLearning: 0.9,
|
|
35
|
+
domainTransfer: 0.8,
|
|
36
|
+
taskAdaptation: 0.9,
|
|
37
|
+
continualLearning: 0.6,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Prototypical Networks
|
|
42
|
+
this.metaStrategies.set('prototypical', {
|
|
43
|
+
name: 'Prototypical Networks',
|
|
44
|
+
description: 'Learn metric space for few-shot classification',
|
|
45
|
+
type: 'metric_based',
|
|
46
|
+
parameters: {
|
|
47
|
+
embeddingDim: 64,
|
|
48
|
+
distanceMetric: 'euclidean',
|
|
49
|
+
temperatureScale: 1.0,
|
|
50
|
+
},
|
|
51
|
+
applicability: {
|
|
52
|
+
fewShotLearning: 0.95,
|
|
53
|
+
domainTransfer: 0.7,
|
|
54
|
+
taskAdaptation: 0.8,
|
|
55
|
+
continualLearning: 0.5,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Memory-Augmented Networks
|
|
60
|
+
this.metaStrategies.set('memory_augmented', {
|
|
61
|
+
name: 'Memory-Augmented Networks',
|
|
62
|
+
description: 'Use external memory for rapid learning',
|
|
63
|
+
type: 'memory_based',
|
|
64
|
+
parameters: {
|
|
65
|
+
memorySize: 128,
|
|
66
|
+
keySize: 64,
|
|
67
|
+
valueSize: 64,
|
|
68
|
+
readHeads: 1,
|
|
69
|
+
writeHeads: 1,
|
|
70
|
+
},
|
|
71
|
+
applicability: {
|
|
72
|
+
fewShotLearning: 0.8,
|
|
73
|
+
domainTransfer: 0.6,
|
|
74
|
+
taskAdaptation: 0.7,
|
|
75
|
+
continualLearning: 0.9,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Reptile Meta-Learning
|
|
80
|
+
this.metaStrategies.set('reptile', {
|
|
81
|
+
name: 'Reptile',
|
|
82
|
+
description: 'Simple meta-learning algorithm for good initialization',
|
|
83
|
+
type: 'gradient_based',
|
|
84
|
+
parameters: {
|
|
85
|
+
innerLearningRate: 0.02,
|
|
86
|
+
outerLearningRate: 1.0,
|
|
87
|
+
innerSteps: 10,
|
|
88
|
+
metaBatchSize: 5,
|
|
89
|
+
},
|
|
90
|
+
applicability: {
|
|
91
|
+
fewShotLearning: 0.85,
|
|
92
|
+
domainTransfer: 0.75,
|
|
93
|
+
taskAdaptation: 0.8,
|
|
94
|
+
continualLearning: 0.7,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Learning to Optimize
|
|
99
|
+
this.metaStrategies.set('learning_to_optimize', {
|
|
100
|
+
name: 'Learning to Optimize',
|
|
101
|
+
description: 'Learn optimization strategies for different tasks',
|
|
102
|
+
type: 'optimization_based',
|
|
103
|
+
parameters: {
|
|
104
|
+
optimizerType: 'lstm',
|
|
105
|
+
optimizerHiddenSize: 20,
|
|
106
|
+
learningRate: 0.001,
|
|
107
|
+
coordinatewise: true,
|
|
108
|
+
},
|
|
109
|
+
applicability: {
|
|
110
|
+
fewShotLearning: 0.7,
|
|
111
|
+
domainTransfer: 0.8,
|
|
112
|
+
taskAdaptation: 0.9,
|
|
113
|
+
continualLearning: 0.8,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Meta-Learning for Domain Adaptation
|
|
118
|
+
this.metaStrategies.set('domain_adaptation', {
|
|
119
|
+
name: 'Meta-Domain Adaptation',
|
|
120
|
+
description: 'Learn domain-invariant representations',
|
|
121
|
+
type: 'domain_based',
|
|
122
|
+
parameters: {
|
|
123
|
+
domainDiscriminatorStrength: 0.1,
|
|
124
|
+
gradientReversalLambda: 1.0,
|
|
125
|
+
alignmentLoss: 'coral',
|
|
126
|
+
adaptationSteps: 20,
|
|
127
|
+
},
|
|
128
|
+
applicability: {
|
|
129
|
+
fewShotLearning: 0.6,
|
|
130
|
+
domainTransfer: 0.95,
|
|
131
|
+
taskAdaptation: 0.7,
|
|
132
|
+
continualLearning: 0.6,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Continual Meta-Learning
|
|
137
|
+
this.metaStrategies.set('continual_meta', {
|
|
138
|
+
name: 'Continual Meta-Learning',
|
|
139
|
+
description: 'Meta-learning while avoiding catastrophic forgetting',
|
|
140
|
+
type: 'continual_based',
|
|
141
|
+
parameters: {
|
|
142
|
+
regularizationStrength: 0.01,
|
|
143
|
+
memoryReplayRatio: 0.2,
|
|
144
|
+
plasticity: 0.8,
|
|
145
|
+
stability: 0.7,
|
|
146
|
+
},
|
|
147
|
+
applicability: {
|
|
148
|
+
fewShotLearning: 0.7,
|
|
149
|
+
domainTransfer: 0.7,
|
|
150
|
+
taskAdaptation: 0.8,
|
|
151
|
+
continualLearning: 0.95,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Multi-Task Meta-Learning
|
|
156
|
+
this.metaStrategies.set('multi_task_meta', {
|
|
157
|
+
name: 'Multi-Task Meta-Learning',
|
|
158
|
+
description: 'Learn shared representations across multiple tasks',
|
|
159
|
+
type: 'multi_task_based',
|
|
160
|
+
parameters: {
|
|
161
|
+
sharedLayers: 3,
|
|
162
|
+
taskSpecificLayers: 2,
|
|
163
|
+
taskWeighting: 'equal',
|
|
164
|
+
gradientNormalization: true,
|
|
165
|
+
},
|
|
166
|
+
applicability: {
|
|
167
|
+
fewShotLearning: 0.8,
|
|
168
|
+
domainTransfer: 0.8,
|
|
169
|
+
taskAdaptation: 0.9,
|
|
170
|
+
continualLearning: 0.8,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Adapt configuration for agent based on meta-learning
|
|
177
|
+
* @param {string} agentId - Agent identifier
|
|
178
|
+
* @param {Object} config - Initial configuration
|
|
179
|
+
*/
|
|
180
|
+
async adaptConfiguration(agentId, config) {
|
|
181
|
+
// Get agent's learning history
|
|
182
|
+
const experiences = this.agentExperiences.get(agentId) || [];
|
|
183
|
+
|
|
184
|
+
if (experiences.length === 0) {
|
|
185
|
+
// No prior experience, return base config
|
|
186
|
+
return this.applyDefaultMetaLearning(config);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Analyze learning patterns
|
|
190
|
+
const learningPatterns = this.analyzeLearningPatterns(experiences);
|
|
191
|
+
|
|
192
|
+
// Select appropriate meta-learning strategy
|
|
193
|
+
const strategy = this.selectMetaLearningStrategy(learningPatterns, config);
|
|
194
|
+
|
|
195
|
+
// Adapt configuration based on strategy
|
|
196
|
+
const adaptedConfig = await this.applyMetaLearningStrategy(config, strategy, learningPatterns);
|
|
197
|
+
|
|
198
|
+
console.log(`Applied meta-learning strategy '${strategy.name}' for agent ${agentId}`);
|
|
199
|
+
|
|
200
|
+
return adaptedConfig;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Apply default meta-learning configuration for new agents
|
|
205
|
+
* @param {Object} config - Base configuration
|
|
206
|
+
*/
|
|
207
|
+
applyDefaultMetaLearning(config) {
|
|
208
|
+
// Apply conservative meta-learning defaults
|
|
209
|
+
return {
|
|
210
|
+
...config,
|
|
211
|
+
metaLearning: {
|
|
212
|
+
enabled: true,
|
|
213
|
+
strategy: 'maml',
|
|
214
|
+
adaptiveRate: 0.01,
|
|
215
|
+
experienceBuffer: 100,
|
|
216
|
+
transferThreshold: 0.7,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Analyze learning patterns from agent experiences
|
|
223
|
+
* @param {Array} experiences - Agent's learning experiences
|
|
224
|
+
*/
|
|
225
|
+
analyzeLearningPatterns(experiences) {
|
|
226
|
+
const patterns = {
|
|
227
|
+
learningSpeed: this.calculateLearningSpeed(experiences),
|
|
228
|
+
convergenceStability: this.calculateConvergenceStability(experiences),
|
|
229
|
+
domainVariability: this.calculateDomainVariability(experiences),
|
|
230
|
+
taskComplexity: this.calculateAverageTaskComplexity(experiences),
|
|
231
|
+
adaptationSuccess: this.calculateAdaptationSuccess(experiences),
|
|
232
|
+
forgettingRate: this.calculateForgettingRate(experiences),
|
|
233
|
+
transferEfficiency: this.calculateTransferEfficiency(experiences),
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
return patterns;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Calculate learning speed from experiences
|
|
241
|
+
* @param {Array} experiences - Learning experiences
|
|
242
|
+
*/
|
|
243
|
+
calculateLearningSpeed(experiences) {
|
|
244
|
+
if (experiences.length === 0) {
|
|
245
|
+
return 0.5;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
let totalSpeed = 0;
|
|
249
|
+
let validExperiences = 0;
|
|
250
|
+
|
|
251
|
+
for (const exp of experiences) {
|
|
252
|
+
if (exp.metrics && exp.metrics.convergenceEpochs) {
|
|
253
|
+
// Faster convergence = higher speed
|
|
254
|
+
const speed = 1 / (1 + exp.metrics.convergenceEpochs / 10);
|
|
255
|
+
totalSpeed += speed;
|
|
256
|
+
validExperiences++;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return validExperiences > 0 ? totalSpeed / validExperiences : 0.5;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Calculate convergence stability
|
|
265
|
+
* @param {Array} experiences - Learning experiences
|
|
266
|
+
*/
|
|
267
|
+
calculateConvergenceStability(experiences) {
|
|
268
|
+
if (experiences.length === 0) {
|
|
269
|
+
return 0.5;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let totalStability = 0;
|
|
273
|
+
let validExperiences = 0;
|
|
274
|
+
|
|
275
|
+
for (const exp of experiences) {
|
|
276
|
+
if (exp.metrics && exp.metrics.lossVariance !== undefined) {
|
|
277
|
+
// Lower variance = higher stability
|
|
278
|
+
const stability = 1 / (1 + exp.metrics.lossVariance);
|
|
279
|
+
totalStability += stability;
|
|
280
|
+
validExperiences++;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return validExperiences > 0 ? totalStability / validExperiences : 0.5;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Calculate domain variability across experiences
|
|
289
|
+
* @param {Array} experiences - Learning experiences
|
|
290
|
+
*/
|
|
291
|
+
calculateDomainVariability(experiences) {
|
|
292
|
+
if (experiences.length === 0) {
|
|
293
|
+
return 0.5;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const domains = new Set();
|
|
297
|
+
|
|
298
|
+
for (const exp of experiences) {
|
|
299
|
+
if (exp.domain) {
|
|
300
|
+
domains.add(exp.domain);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Normalize by maximum expected domains
|
|
305
|
+
return Math.min(1, domains.size / 10);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Calculate average task complexity
|
|
310
|
+
* @param {Array} experiences - Learning experiences
|
|
311
|
+
*/
|
|
312
|
+
calculateAverageTaskComplexity(experiences) {
|
|
313
|
+
if (experiences.length === 0) {
|
|
314
|
+
return 0.5;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
let totalComplexity = 0;
|
|
318
|
+
let validExperiences = 0;
|
|
319
|
+
|
|
320
|
+
for (const exp of experiences) {
|
|
321
|
+
if (exp.taskComplexity !== undefined) {
|
|
322
|
+
totalComplexity += exp.taskComplexity;
|
|
323
|
+
validExperiences++;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return validExperiences > 0 ? totalComplexity / validExperiences : 0.5;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Calculate adaptation success rate
|
|
332
|
+
* @param {Array} experiences - Learning experiences
|
|
333
|
+
*/
|
|
334
|
+
calculateAdaptationSuccess(experiences) {
|
|
335
|
+
if (experiences.length === 0) {
|
|
336
|
+
return 0.5;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const successfulAdaptations = experiences.filter(exp =>
|
|
340
|
+
exp.adaptationResult && exp.adaptationResult.success,
|
|
341
|
+
).length;
|
|
342
|
+
|
|
343
|
+
return successfulAdaptations / experiences.length;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Calculate forgetting rate
|
|
348
|
+
* @param {Array} experiences - Learning experiences
|
|
349
|
+
*/
|
|
350
|
+
calculateForgettingRate(experiences) {
|
|
351
|
+
if (experiences.length < 2) {
|
|
352
|
+
return 0.5;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let totalForgetting = 0;
|
|
356
|
+
let validComparisons = 0;
|
|
357
|
+
|
|
358
|
+
for (let i = 1; i < experiences.length; i++) {
|
|
359
|
+
const prev = experiences[i - 1];
|
|
360
|
+
const curr = experiences[i];
|
|
361
|
+
|
|
362
|
+
if (prev.metrics && curr.metrics && prev.metrics.accuracy && curr.metrics.accuracy) {
|
|
363
|
+
// If accuracy drops significantly when learning new task, high forgetting
|
|
364
|
+
const forgetting = Math.max(0, prev.metrics.accuracy - curr.metrics.accuracy);
|
|
365
|
+
totalForgetting += forgetting;
|
|
366
|
+
validComparisons++;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return validComparisons > 0 ? totalForgetting / validComparisons : 0.5;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Calculate transfer learning efficiency
|
|
375
|
+
* @param {Array} experiences - Learning experiences
|
|
376
|
+
*/
|
|
377
|
+
calculateTransferEfficiency(experiences) {
|
|
378
|
+
if (experiences.length === 0) {
|
|
379
|
+
return 0.5;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const transferExperiences = experiences.filter(exp => exp.transferLearning);
|
|
383
|
+
if (transferExperiences.length === 0) {
|
|
384
|
+
return 0.5;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let totalEfficiency = 0;
|
|
388
|
+
|
|
389
|
+
for (const exp of transferExperiences) {
|
|
390
|
+
if (exp.transferLearning.efficiencyGain !== undefined) {
|
|
391
|
+
totalEfficiency += exp.transferLearning.efficiencyGain;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return transferExperiences.length > 0 ? totalEfficiency / transferExperiences.length : 0.5;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Select appropriate meta-learning strategy
|
|
400
|
+
* @param {Object} patterns - Learning patterns
|
|
401
|
+
* @param {Object} config - Configuration
|
|
402
|
+
*/
|
|
403
|
+
selectMetaLearningStrategy(patterns, config) {
|
|
404
|
+
let bestStrategy = null;
|
|
405
|
+
let bestScore = 0;
|
|
406
|
+
|
|
407
|
+
// Define task characteristics
|
|
408
|
+
const taskCharacteristics = this.inferTaskCharacteristics(patterns, config);
|
|
409
|
+
|
|
410
|
+
for (const [strategyName, strategy] of this.metaStrategies.entries()) {
|
|
411
|
+
let score = 0;
|
|
412
|
+
|
|
413
|
+
// Score based on applicability to current task characteristics
|
|
414
|
+
if (taskCharacteristics.fewShot) {
|
|
415
|
+
score += strategy.applicability.fewShotLearning * 0.3;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (taskCharacteristics.domainTransfer) {
|
|
419
|
+
score += strategy.applicability.domainTransfer * 0.3;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (taskCharacteristics.taskAdaptation) {
|
|
423
|
+
score += strategy.applicability.taskAdaptation * 0.2;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (taskCharacteristics.continualLearning) {
|
|
427
|
+
score += strategy.applicability.continualLearning * 0.2;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Adjust score based on learning patterns
|
|
431
|
+
if (patterns.learningSpeed < 0.3 && strategy.type === 'gradient_based') {
|
|
432
|
+
score += 0.1; // Boost gradient-based methods for slow learners
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (patterns.forgettingRate > 0.7 && strategy.type === 'memory_based') {
|
|
436
|
+
score += 0.2; // Boost memory-based methods for high forgetting
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (patterns.domainVariability > 0.6 && strategy.type === 'domain_based') {
|
|
440
|
+
score += 0.15; // Boost domain adaptation for high variability
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (score > bestScore) {
|
|
444
|
+
bestScore = score;
|
|
445
|
+
bestStrategy = strategy;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return bestStrategy || this.metaStrategies.get('maml');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Infer task characteristics from patterns and config
|
|
454
|
+
* @param {Object} patterns - Learning patterns
|
|
455
|
+
* @param {Object} config - Configuration
|
|
456
|
+
*/
|
|
457
|
+
inferTaskCharacteristics(patterns, config) {
|
|
458
|
+
return {
|
|
459
|
+
fewShot: patterns.learningSpeed < 0.4 || config.dataSize < 1000,
|
|
460
|
+
domainTransfer: patterns.domainVariability > 0.5,
|
|
461
|
+
taskAdaptation: patterns.adaptationSuccess < 0.6,
|
|
462
|
+
continualLearning: patterns.forgettingRate > 0.5,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Apply meta-learning strategy to configuration
|
|
468
|
+
* @param {Object} config - Base configuration
|
|
469
|
+
* @param {Object} strategy - Selected strategy
|
|
470
|
+
* @param {Object} patterns - Learning patterns
|
|
471
|
+
*/
|
|
472
|
+
async applyMetaLearningStrategy(config, strategy, patterns) {
|
|
473
|
+
const adaptedConfig = { ...config };
|
|
474
|
+
|
|
475
|
+
// Apply strategy-specific adaptations
|
|
476
|
+
switch (strategy.type) {
|
|
477
|
+
case 'gradient_based':
|
|
478
|
+
adaptedConfig.metaLearning = this.applyGradientBasedMeta(strategy, patterns);
|
|
479
|
+
break;
|
|
480
|
+
|
|
481
|
+
case 'metric_based':
|
|
482
|
+
adaptedConfig.metaLearning = this.applyMetricBasedMeta(strategy, patterns);
|
|
483
|
+
break;
|
|
484
|
+
|
|
485
|
+
case 'memory_based':
|
|
486
|
+
adaptedConfig.metaLearning = this.applyMemoryBasedMeta(strategy, patterns);
|
|
487
|
+
break;
|
|
488
|
+
|
|
489
|
+
case 'optimization_based':
|
|
490
|
+
adaptedConfig.metaLearning = this.applyOptimizationBasedMeta(strategy, patterns);
|
|
491
|
+
break;
|
|
492
|
+
|
|
493
|
+
case 'domain_based':
|
|
494
|
+
adaptedConfig.metaLearning = this.applyDomainBasedMeta(strategy, patterns);
|
|
495
|
+
break;
|
|
496
|
+
|
|
497
|
+
case 'continual_based':
|
|
498
|
+
adaptedConfig.metaLearning = this.applyContinualBasedMeta(strategy, patterns);
|
|
499
|
+
break;
|
|
500
|
+
|
|
501
|
+
case 'multi_task_based':
|
|
502
|
+
adaptedConfig.metaLearning = this.applyMultiTaskBasedMeta(strategy, patterns);
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// Add common meta-learning properties
|
|
507
|
+
adaptedConfig.metaLearning.strategyName = strategy.name;
|
|
508
|
+
adaptedConfig.metaLearning.enabled = true;
|
|
509
|
+
adaptedConfig.metaLearning.adaptiveThreshold = this.calculateAdaptiveThreshold(patterns);
|
|
510
|
+
|
|
511
|
+
return adaptedConfig;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Apply gradient-based meta-learning configuration
|
|
516
|
+
* @param {Object} strategy - Strategy configuration
|
|
517
|
+
* @param {Object} patterns - Learning patterns
|
|
518
|
+
*/
|
|
519
|
+
applyGradientBasedMeta(strategy, patterns) {
|
|
520
|
+
const config = { ...strategy.parameters };
|
|
521
|
+
|
|
522
|
+
// Adapt inner learning rate based on learning speed
|
|
523
|
+
if (patterns.learningSpeed < 0.3) {
|
|
524
|
+
config.innerLearningRate *= 1.5; // Increase for slow learners
|
|
525
|
+
} else if (patterns.learningSpeed > 0.7) {
|
|
526
|
+
config.innerLearningRate *= 0.7; // Decrease for fast learners
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// Adapt inner steps based on convergence stability
|
|
530
|
+
if (patterns.convergenceStability < 0.4) {
|
|
531
|
+
config.innerSteps = Math.max(3, config.innerSteps - 2);
|
|
532
|
+
} else if (patterns.convergenceStability > 0.8) {
|
|
533
|
+
config.innerSteps = Math.min(10, config.innerSteps + 3);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return { type: 'gradient_based', ...config };
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Apply metric-based meta-learning configuration
|
|
541
|
+
* @param {Object} strategy - Strategy configuration
|
|
542
|
+
* @param {Object} patterns - Learning patterns
|
|
543
|
+
*/
|
|
544
|
+
applyMetricBasedMeta(strategy, patterns) {
|
|
545
|
+
const config = { ...strategy.parameters };
|
|
546
|
+
|
|
547
|
+
// Adapt embedding dimension based on task complexity
|
|
548
|
+
if (patterns.taskComplexity > 0.7) {
|
|
549
|
+
config.embeddingDim = Math.min(128, config.embeddingDim * 1.5);
|
|
550
|
+
} else if (patterns.taskComplexity < 0.3) {
|
|
551
|
+
config.embeddingDim = Math.max(32, config.embeddingDim * 0.7);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Adapt temperature based on convergence stability
|
|
555
|
+
if (patterns.convergenceStability < 0.5) {
|
|
556
|
+
config.temperatureScale = Math.max(0.5, config.temperatureScale - 0.2);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
return { type: 'metric_based', ...config };
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Apply memory-based meta-learning configuration
|
|
564
|
+
* @param {Object} strategy - Strategy configuration
|
|
565
|
+
* @param {Object} patterns - Learning patterns
|
|
566
|
+
*/
|
|
567
|
+
applyMemoryBasedMeta(strategy, patterns) {
|
|
568
|
+
const config = { ...strategy.parameters };
|
|
569
|
+
|
|
570
|
+
// Increase memory size for high forgetting rate
|
|
571
|
+
if (patterns.forgettingRate > 0.6) {
|
|
572
|
+
config.memorySize = Math.min(256, config.memorySize * 1.5);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Adjust read/write heads based on domain variability
|
|
576
|
+
if (patterns.domainVariability > 0.5) {
|
|
577
|
+
config.readHeads = Math.min(4, config.readHeads + 1);
|
|
578
|
+
config.writeHeads = Math.min(2, config.writeHeads + 1);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return { type: 'memory_based', ...config };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Apply optimization-based meta-learning configuration
|
|
586
|
+
* @param {Object} strategy - Strategy configuration
|
|
587
|
+
* @param {Object} patterns - Learning patterns
|
|
588
|
+
*/
|
|
589
|
+
applyOptimizationBasedMeta(strategy, patterns) {
|
|
590
|
+
const config = { ...strategy.parameters };
|
|
591
|
+
|
|
592
|
+
// Adapt optimizer based on learning speed
|
|
593
|
+
if (patterns.learningSpeed < 0.4) {
|
|
594
|
+
config.optimizerHiddenSize = Math.min(40, config.optimizerHiddenSize * 1.3);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Enable coordinate-wise optimization for complex tasks
|
|
598
|
+
if (patterns.taskComplexity > 0.6) {
|
|
599
|
+
config.coordinatewise = true;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return { type: 'optimization_based', ...config };
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Apply domain-based meta-learning configuration
|
|
607
|
+
* @param {Object} strategy - Strategy configuration
|
|
608
|
+
* @param {Object} patterns - Learning patterns
|
|
609
|
+
*/
|
|
610
|
+
applyDomainBasedMeta(strategy, patterns) {
|
|
611
|
+
const config = { ...strategy.parameters };
|
|
612
|
+
|
|
613
|
+
// Strengthen domain discriminator for high domain variability
|
|
614
|
+
if (patterns.domainVariability > 0.7) {
|
|
615
|
+
config.domainDiscriminatorStrength *= 1.3;
|
|
616
|
+
config.gradientReversalLambda *= 1.2;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Increase adaptation steps for low transfer efficiency
|
|
620
|
+
if (patterns.transferEfficiency < 0.4) {
|
|
621
|
+
config.adaptationSteps = Math.min(50, config.adaptationSteps * 1.5);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return { type: 'domain_based', ...config };
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Apply continual-based meta-learning configuration
|
|
629
|
+
* @param {Object} strategy - Strategy configuration
|
|
630
|
+
* @param {Object} patterns - Learning patterns
|
|
631
|
+
*/
|
|
632
|
+
applyContinualBasedMeta(strategy, patterns) {
|
|
633
|
+
const config = { ...strategy.parameters };
|
|
634
|
+
|
|
635
|
+
// Increase regularization for high forgetting
|
|
636
|
+
if (patterns.forgettingRate > 0.6) {
|
|
637
|
+
config.regularizationStrength *= 1.4;
|
|
638
|
+
config.stability = Math.min(0.9, config.stability + 0.1);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Increase memory replay for domain variability
|
|
642
|
+
if (patterns.domainVariability > 0.5) {
|
|
643
|
+
config.memoryReplayRatio = Math.min(0.4, config.memoryReplayRatio + 0.1);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return { type: 'continual_based', ...config };
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Apply multi-task based meta-learning configuration
|
|
651
|
+
* @param {Object} strategy - Strategy configuration
|
|
652
|
+
* @param {Object} patterns - Learning patterns
|
|
653
|
+
*/
|
|
654
|
+
applyMultiTaskBasedMeta(strategy, patterns) {
|
|
655
|
+
const config = { ...strategy.parameters };
|
|
656
|
+
|
|
657
|
+
// Adjust shared layers based on transfer efficiency
|
|
658
|
+
if (patterns.transferEfficiency > 0.7) {
|
|
659
|
+
config.sharedLayers = Math.min(5, config.sharedLayers + 1);
|
|
660
|
+
} else if (patterns.transferEfficiency < 0.3) {
|
|
661
|
+
config.taskSpecificLayers = Math.min(4, config.taskSpecificLayers + 1);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// Enable gradient normalization for stability
|
|
665
|
+
if (patterns.convergenceStability < 0.5) {
|
|
666
|
+
config.gradientNormalization = true;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
return { type: 'multi_task_based', ...config };
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Calculate adaptive threshold based on patterns
|
|
674
|
+
* @param {Object} patterns - Learning patterns
|
|
675
|
+
*/
|
|
676
|
+
calculateAdaptiveThreshold(patterns) {
|
|
677
|
+
// Base threshold adjusted by learning characteristics
|
|
678
|
+
let threshold = 0.7;
|
|
679
|
+
|
|
680
|
+
if (patterns.learningSpeed < 0.3) {
|
|
681
|
+
threshold -= 0.1;
|
|
682
|
+
} // Lower threshold for slow learners
|
|
683
|
+
if (patterns.adaptationSuccess < 0.5) {
|
|
684
|
+
threshold -= 0.05;
|
|
685
|
+
} // Lower threshold for poor adapters
|
|
686
|
+
if (patterns.forgettingRate > 0.6) {
|
|
687
|
+
threshold += 0.1;
|
|
688
|
+
} // Higher threshold if prone to forgetting
|
|
689
|
+
|
|
690
|
+
return Math.max(0.3, Math.min(0.9, threshold));
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Optimize training parameters using meta-learning
|
|
695
|
+
* @param {string} agentId - Agent identifier
|
|
696
|
+
* @param {Object} options - Training options
|
|
697
|
+
*/
|
|
698
|
+
async optimizeTraining(agentId, options) {
|
|
699
|
+
const experiences = this.agentExperiences.get(agentId) || [];
|
|
700
|
+
|
|
701
|
+
if (experiences.length === 0) {
|
|
702
|
+
return options; // No optimization without experience
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
const patterns = this.analyzeLearningPatterns(experiences);
|
|
706
|
+
const optimizedOptions = { ...options };
|
|
707
|
+
|
|
708
|
+
// Optimize learning rate
|
|
709
|
+
optimizedOptions.learningRate = this.optimizeLearningRate(patterns, options.learningRate);
|
|
710
|
+
|
|
711
|
+
// Optimize batch size
|
|
712
|
+
optimizedOptions.batchSize = this.optimizeBatchSize(patterns, options.batchSize);
|
|
713
|
+
|
|
714
|
+
// Optimize epochs
|
|
715
|
+
optimizedOptions.epochs = this.optimizeEpochs(patterns, options.epochs);
|
|
716
|
+
|
|
717
|
+
// Add meta-learning specific optimizations
|
|
718
|
+
optimizedOptions.metaOptimizations = {
|
|
719
|
+
warmupEpochs: this.calculateWarmupEpochs(patterns),
|
|
720
|
+
schedulerType: this.selectSchedulerType(patterns),
|
|
721
|
+
regularizationStrength: this.optimizeRegularization(patterns),
|
|
722
|
+
earlyStoppingPatience: this.optimizeEarlyStopping(patterns),
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
console.log(`Optimized training parameters for agent ${agentId} based on meta-learning`);
|
|
726
|
+
|
|
727
|
+
return optimizedOptions;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Optimize learning rate based on patterns
|
|
732
|
+
* @param {Object} patterns - Learning patterns
|
|
733
|
+
* @param {number} baseLR - Base learning rate
|
|
734
|
+
*/
|
|
735
|
+
optimizeLearningRate(patterns, baseLR) {
|
|
736
|
+
let multiplier = 1.0;
|
|
737
|
+
|
|
738
|
+
// Adjust based on learning speed
|
|
739
|
+
if (patterns.learningSpeed < 0.3) {
|
|
740
|
+
multiplier *= 1.3; // Increase LR for slow learners
|
|
741
|
+
} else if (patterns.learningSpeed > 0.7) {
|
|
742
|
+
multiplier *= 0.8; // Decrease LR for fast learners
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Adjust based on convergence stability
|
|
746
|
+
if (patterns.convergenceStability < 0.4) {
|
|
747
|
+
multiplier *= 0.7; // Lower LR for unstable convergence
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return baseLR * multiplier;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Optimize batch size based on patterns
|
|
755
|
+
* @param {Object} patterns - Learning patterns
|
|
756
|
+
* @param {number} baseBatchSize - Base batch size
|
|
757
|
+
*/
|
|
758
|
+
optimizeBatchSize(patterns, baseBatchSize) {
|
|
759
|
+
let multiplier = 1.0;
|
|
760
|
+
|
|
761
|
+
// Adjust based on convergence stability
|
|
762
|
+
if (patterns.convergenceStability < 0.4) {
|
|
763
|
+
multiplier *= 1.5; // Larger batches for stability
|
|
764
|
+
} else if (patterns.convergenceStability > 0.8) {
|
|
765
|
+
multiplier *= 0.8; // Smaller batches for exploration
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// Adjust based on task complexity
|
|
769
|
+
if (patterns.taskComplexity > 0.7) {
|
|
770
|
+
multiplier *= 0.7; // Smaller batches for complex tasks
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const optimizedSize = Math.round(baseBatchSize * multiplier);
|
|
774
|
+
return Math.max(1, Math.min(256, optimizedSize)); // Clamp to reasonable range
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Optimize number of epochs based on patterns
|
|
779
|
+
* @param {Object} patterns - Learning patterns
|
|
780
|
+
* @param {number} baseEpochs - Base number of epochs
|
|
781
|
+
*/
|
|
782
|
+
optimizeEpochs(patterns, baseEpochs) {
|
|
783
|
+
let multiplier = 1.0;
|
|
784
|
+
|
|
785
|
+
// Adjust based on learning speed
|
|
786
|
+
if (patterns.learningSpeed < 0.3) {
|
|
787
|
+
multiplier *= 1.5; // More epochs for slow learners
|
|
788
|
+
} else if (patterns.learningSpeed > 0.7) {
|
|
789
|
+
multiplier *= 0.7; // Fewer epochs for fast learners
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// Adjust based on forgetting rate
|
|
793
|
+
if (patterns.forgettingRate > 0.6) {
|
|
794
|
+
multiplier *= 0.8; // Fewer epochs to avoid overfitting
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const optimizedEpochs = Math.round(baseEpochs * multiplier);
|
|
798
|
+
return Math.max(1, Math.min(200, optimizedEpochs)); // Clamp to reasonable range
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Calculate optimal warmup epochs
|
|
803
|
+
* @param {Object} patterns - Learning patterns
|
|
804
|
+
*/
|
|
805
|
+
calculateWarmupEpochs(patterns) {
|
|
806
|
+
let warmupEpochs = 0;
|
|
807
|
+
|
|
808
|
+
// Use warmup for unstable convergence
|
|
809
|
+
if (patterns.convergenceStability < 0.5) {
|
|
810
|
+
warmupEpochs = Math.ceil(5 * (1 - patterns.convergenceStability));
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
return Math.max(0, Math.min(10, warmupEpochs));
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Select learning rate scheduler type
|
|
818
|
+
* @param {Object} patterns - Learning patterns
|
|
819
|
+
*/
|
|
820
|
+
selectSchedulerType(patterns) {
|
|
821
|
+
if (patterns.convergenceStability < 0.4) {
|
|
822
|
+
return 'cosine_annealing'; // Smooth schedule for unstable training
|
|
823
|
+
} else if (patterns.learningSpeed < 0.3) {
|
|
824
|
+
return 'exponential_decay'; // Gradual reduction for slow learners
|
|
825
|
+
} else if (patterns.taskComplexity > 0.7) {
|
|
826
|
+
return 'step_decay'; // Stepwise reduction for complex tasks
|
|
827
|
+
}
|
|
828
|
+
return 'constant'; // Keep constant for stable cases
|
|
829
|
+
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Optimize regularization strength
|
|
834
|
+
* @param {Object} patterns - Learning patterns
|
|
835
|
+
*/
|
|
836
|
+
optimizeRegularization(patterns) {
|
|
837
|
+
let baseStrength = 0.01;
|
|
838
|
+
|
|
839
|
+
// Increase regularization for high task complexity
|
|
840
|
+
if (patterns.taskComplexity > 0.6) {
|
|
841
|
+
baseStrength *= 1.5;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Increase regularization for low convergence stability
|
|
845
|
+
if (patterns.convergenceStability < 0.5) {
|
|
846
|
+
baseStrength *= 1.3;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
// Decrease regularization for high forgetting rate (may be overregularized)
|
|
850
|
+
if (patterns.forgettingRate > 0.7) {
|
|
851
|
+
baseStrength *= 0.7;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return Math.max(0.001, Math.min(0.1, baseStrength));
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Optimize early stopping patience
|
|
859
|
+
* @param {Object} patterns - Learning patterns
|
|
860
|
+
*/
|
|
861
|
+
optimizeEarlyStopping(patterns) {
|
|
862
|
+
let basePatienceEpochs = 10;
|
|
863
|
+
|
|
864
|
+
// Increase patience for slow learners
|
|
865
|
+
if (patterns.learningSpeed < 0.3) {
|
|
866
|
+
basePatienceEpochs *= 1.5;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Decrease patience for fast learners
|
|
870
|
+
if (patterns.learningSpeed > 0.7) {
|
|
871
|
+
basePatienceEpochs *= 0.7;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// Increase patience for unstable convergence
|
|
875
|
+
if (patterns.convergenceStability < 0.4) {
|
|
876
|
+
basePatienceEpochs *= 1.3;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
return Math.max(3, Math.min(25, Math.round(basePatienceEpochs)));
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Extract experiences from agent for meta-learning
|
|
884
|
+
* @param {string} agentId - Agent identifier
|
|
885
|
+
*/
|
|
886
|
+
async extractExperiences(agentId) {
|
|
887
|
+
return this.agentExperiences.get(agentId) || [];
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Record learning experience for meta-learning
|
|
892
|
+
* @param {string} agentId - Agent identifier
|
|
893
|
+
* @param {Object} experience - Learning experience
|
|
894
|
+
*/
|
|
895
|
+
recordExperience(agentId, experience) {
|
|
896
|
+
if (!this.agentExperiences.has(agentId)) {
|
|
897
|
+
this.agentExperiences.set(agentId, []);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
const experiences = this.agentExperiences.get(agentId);
|
|
901
|
+
|
|
902
|
+
// Add timestamp and unique ID
|
|
903
|
+
const enrichedExperience = {
|
|
904
|
+
...experience,
|
|
905
|
+
timestamp: Date.now(),
|
|
906
|
+
id: `exp_${agentId}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
experiences.push(enrichedExperience);
|
|
910
|
+
|
|
911
|
+
// Keep only recent experiences (last 100)
|
|
912
|
+
if (experiences.length > 100) {
|
|
913
|
+
experiences.splice(0, experiences.length - 100);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// Update learning metrics
|
|
917
|
+
this.updateLearningMetrics(agentId, enrichedExperience);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Update learning metrics for agent
|
|
922
|
+
* @param {string} agentId - Agent identifier
|
|
923
|
+
* @param {Object} experience - Learning experience
|
|
924
|
+
*/
|
|
925
|
+
updateLearningMetrics(agentId, experience) {
|
|
926
|
+
if (!this.learningMetrics.has(agentId)) {
|
|
927
|
+
this.learningMetrics.set(agentId, {
|
|
928
|
+
totalExperiences: 0,
|
|
929
|
+
averageLearningTime: 0,
|
|
930
|
+
averageAccuracy: 0,
|
|
931
|
+
adaptationSuccessRate: 0,
|
|
932
|
+
domainTransferCount: 0,
|
|
933
|
+
lastUpdate: Date.now(),
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
const metrics = this.learningMetrics.get(agentId);
|
|
938
|
+
|
|
939
|
+
metrics.totalExperiences++;
|
|
940
|
+
metrics.lastUpdate = Date.now();
|
|
941
|
+
|
|
942
|
+
// Update running averages
|
|
943
|
+
if (experience.metrics) {
|
|
944
|
+
if (experience.metrics.trainingTime) {
|
|
945
|
+
metrics.averageLearningTime = this.updateRunningAverage(
|
|
946
|
+
metrics.averageLearningTime,
|
|
947
|
+
experience.metrics.trainingTime,
|
|
948
|
+
metrics.totalExperiences,
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
if (experience.metrics.accuracy) {
|
|
953
|
+
metrics.averageAccuracy = this.updateRunningAverage(
|
|
954
|
+
metrics.averageAccuracy,
|
|
955
|
+
experience.metrics.accuracy,
|
|
956
|
+
metrics.totalExperiences,
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// Update success rate
|
|
962
|
+
if (experience.adaptationResult) {
|
|
963
|
+
const successCount = metrics.adaptationSuccessRate * (metrics.totalExperiences - 1);
|
|
964
|
+
const newSuccess = experience.adaptationResult.success ? 1 : 0;
|
|
965
|
+
metrics.adaptationSuccessRate = (successCount + newSuccess) / metrics.totalExperiences;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// Count domain transfers
|
|
969
|
+
if (experience.transferLearning) {
|
|
970
|
+
metrics.domainTransferCount++;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Update running average
|
|
976
|
+
* @param {number} currentAvg - Current average
|
|
977
|
+
* @param {number} newValue - New value
|
|
978
|
+
* @param {number} count - Total count
|
|
979
|
+
*/
|
|
980
|
+
updateRunningAverage(currentAvg, newValue, count) {
|
|
981
|
+
return currentAvg + (newValue - currentAvg) / count;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* Perform domain adaptation using meta-learning
|
|
986
|
+
* @param {string} agentId - Agent identifier
|
|
987
|
+
* @param {Object} sourceData - Source domain data
|
|
988
|
+
* @param {Object} targetData - Target domain data
|
|
989
|
+
*/
|
|
990
|
+
async performDomainAdaptation(agentId, sourceData, targetData) {
|
|
991
|
+
// Analyze domain shift
|
|
992
|
+
const domainShift = this.analyzeDomainShift(sourceData, targetData);
|
|
993
|
+
|
|
994
|
+
// Select adaptation strategy
|
|
995
|
+
const adaptationStrategy = this.selectAdaptationStrategy(domainShift);
|
|
996
|
+
|
|
997
|
+
// Apply domain adaptation
|
|
998
|
+
const adaptationResult = await this.applyDomainAdaptation(
|
|
999
|
+
agentId,
|
|
1000
|
+
adaptationStrategy,
|
|
1001
|
+
sourceData,
|
|
1002
|
+
targetData,
|
|
1003
|
+
);
|
|
1004
|
+
|
|
1005
|
+
// Record domain adaptation experience
|
|
1006
|
+
this.recordExperience(agentId, {
|
|
1007
|
+
type: 'domain_adaptation',
|
|
1008
|
+
sourceData: this.summarizeData(sourceData),
|
|
1009
|
+
targetData: this.summarizeData(targetData),
|
|
1010
|
+
domainShift,
|
|
1011
|
+
adaptationStrategy,
|
|
1012
|
+
adaptationResult,
|
|
1013
|
+
transferLearning: {
|
|
1014
|
+
enabled: true,
|
|
1015
|
+
efficiencyGain: adaptationResult.efficiencyGain || 0,
|
|
1016
|
+
},
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
return adaptationResult;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Analyze domain shift between source and target
|
|
1024
|
+
* @param {Object} sourceData - Source domain data
|
|
1025
|
+
* @param {Object} targetData - Target domain data
|
|
1026
|
+
*/
|
|
1027
|
+
analyzeDomainShift(sourceData, targetData) {
|
|
1028
|
+
return {
|
|
1029
|
+
distributionShift: this.calculateDistributionShift(sourceData, targetData),
|
|
1030
|
+
featureShift: this.calculateFeatureShift(sourceData, targetData),
|
|
1031
|
+
labelShift: this.calculateLabelShift(sourceData, targetData),
|
|
1032
|
+
marginalShift: this.calculateMarginalShift(sourceData, targetData),
|
|
1033
|
+
conditionalShift: this.calculateConditionalShift(sourceData, targetData),
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* Calculate distribution shift between domains
|
|
1039
|
+
* @param {Object} sourceData - Source domain data
|
|
1040
|
+
* @param {Object} targetData - Target domain data
|
|
1041
|
+
*/
|
|
1042
|
+
calculateDistributionShift(sourceData, targetData) {
|
|
1043
|
+
// Simplified distribution shift calculation
|
|
1044
|
+
if (!sourceData.samples || !targetData.samples) {
|
|
1045
|
+
return 0.5;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// Calculate basic statistics for both domains
|
|
1049
|
+
const sourceStats = this.calculateDataStatistics(sourceData.samples);
|
|
1050
|
+
const targetStats = this.calculateDataStatistics(targetData.samples);
|
|
1051
|
+
|
|
1052
|
+
// Calculate shift as difference in statistics
|
|
1053
|
+
const meanShift = Math.abs(sourceStats.mean - targetStats.mean);
|
|
1054
|
+
const varianceShift = Math.abs(sourceStats.variance - targetStats.variance);
|
|
1055
|
+
|
|
1056
|
+
return Math.min(1, (meanShift + varianceShift) / 2);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Calculate basic data statistics
|
|
1061
|
+
* @param {Array} samples - Data samples
|
|
1062
|
+
*/
|
|
1063
|
+
calculateDataStatistics(samples) {
|
|
1064
|
+
if (samples.length === 0) {
|
|
1065
|
+
return { mean: 0, variance: 0 };
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// Flatten samples to get all numeric values
|
|
1069
|
+
const values = samples.flat().filter(v => typeof v === 'number');
|
|
1070
|
+
|
|
1071
|
+
if (values.length === 0) {
|
|
1072
|
+
return { mean: 0, variance: 0 };
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
const mean = values.reduce((sum, v) => sum + v, 0) / values.length;
|
|
1076
|
+
const variance = values.reduce((sum, v) => sum + Math.pow(v - mean, 2), 0) / values.length;
|
|
1077
|
+
|
|
1078
|
+
return { mean, variance };
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Calculate feature shift (simplified)
|
|
1083
|
+
* @param {Object} sourceData - Source domain data
|
|
1084
|
+
* @param {Object} targetData - Target domain data
|
|
1085
|
+
*/
|
|
1086
|
+
calculateFeatureShift(sourceData, targetData) {
|
|
1087
|
+
// Simplified feature shift - compare feature dimensions
|
|
1088
|
+
const sourceDim = this.getFeatureDimensions(sourceData);
|
|
1089
|
+
const targetDim = this.getFeatureDimensions(targetData);
|
|
1090
|
+
|
|
1091
|
+
if (sourceDim === 0 || targetDim === 0) {
|
|
1092
|
+
return 0.5;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
return Math.abs(sourceDim - targetDim) / Math.max(sourceDim, targetDim);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Get feature dimensions from data
|
|
1100
|
+
* @param {Object} data - Data object
|
|
1101
|
+
*/
|
|
1102
|
+
getFeatureDimensions(data) {
|
|
1103
|
+
if (!data.samples || data.samples.length === 0) {
|
|
1104
|
+
return 0;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
const sample = data.samples[0];
|
|
1108
|
+
if (Array.isArray(sample)) {
|
|
1109
|
+
return sample.length;
|
|
1110
|
+
}
|
|
1111
|
+
if (typeof sample === 'object' && sample.input) {
|
|
1112
|
+
return Array.isArray(sample.input) ? sample.input.length : 1;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
return 1;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Calculate label shift (simplified)
|
|
1120
|
+
* @param {Object} sourceData - Source domain data
|
|
1121
|
+
* @param {Object} targetData - Target domain data
|
|
1122
|
+
*/
|
|
1123
|
+
calculateLabelShift(sourceData, targetData) {
|
|
1124
|
+
// Compare label distributions
|
|
1125
|
+
const sourceLabels = this.extractLabels(sourceData);
|
|
1126
|
+
const targetLabels = this.extractLabels(targetData);
|
|
1127
|
+
|
|
1128
|
+
if (sourceLabels.size === 0 || targetLabels.size === 0) {
|
|
1129
|
+
return 0.5;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
const intersection = new Set([...sourceLabels].filter(x => targetLabels.has(x)));
|
|
1133
|
+
const union = new Set([...sourceLabels, ...targetLabels]);
|
|
1134
|
+
|
|
1135
|
+
return 1 - (intersection.size / union.size); // Jaccard distance
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* Extract unique labels from data
|
|
1140
|
+
* @param {Object} data - Data object
|
|
1141
|
+
*/
|
|
1142
|
+
extractLabels(data) {
|
|
1143
|
+
const labels = new Set();
|
|
1144
|
+
|
|
1145
|
+
if (data.samples) {
|
|
1146
|
+
data.samples.forEach(sample => {
|
|
1147
|
+
if (sample.label !== undefined) {
|
|
1148
|
+
labels.add(sample.label);
|
|
1149
|
+
}
|
|
1150
|
+
if (sample.target !== undefined) {
|
|
1151
|
+
labels.add(sample.target);
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
return labels;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Calculate marginal shift (simplified)
|
|
1161
|
+
* @param {Object} sourceData - Source domain data
|
|
1162
|
+
* @param {Object} targetData - Target domain data
|
|
1163
|
+
*/
|
|
1164
|
+
calculateMarginalShift(sourceData, targetData) {
|
|
1165
|
+
// Simplified marginal shift calculation
|
|
1166
|
+
return this.calculateDistributionShift(sourceData, targetData);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Calculate conditional shift (simplified)
|
|
1171
|
+
* @param {Object} sourceData - Source domain data
|
|
1172
|
+
* @param {Object} targetData - Target domain data
|
|
1173
|
+
*/
|
|
1174
|
+
calculateConditionalShift(sourceData, targetData) {
|
|
1175
|
+
// Simplified conditional shift calculation
|
|
1176
|
+
const featureShift = this.calculateFeatureShift(sourceData, targetData);
|
|
1177
|
+
const labelShift = this.calculateLabelShift(sourceData, targetData);
|
|
1178
|
+
|
|
1179
|
+
return (featureShift + labelShift) / 2;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Select appropriate domain adaptation strategy
|
|
1184
|
+
* @param {Object} domainShift - Domain shift analysis
|
|
1185
|
+
*/
|
|
1186
|
+
selectAdaptationStrategy(domainShift) {
|
|
1187
|
+
const { distributionShift, featureShift, labelShift } = domainShift;
|
|
1188
|
+
|
|
1189
|
+
if (distributionShift > 0.7) {
|
|
1190
|
+
return 'adversarial_adaptation';
|
|
1191
|
+
} else if (featureShift > 0.6) {
|
|
1192
|
+
return 'feature_alignment';
|
|
1193
|
+
} else if (labelShift > 0.5) {
|
|
1194
|
+
return 'label_adaptation';
|
|
1195
|
+
}
|
|
1196
|
+
return 'fine_tuning';
|
|
1197
|
+
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Apply domain adaptation strategy
|
|
1202
|
+
* @param {string} agentId - Agent identifier
|
|
1203
|
+
* @param {string} strategy - Adaptation strategy
|
|
1204
|
+
* @param {Object} sourceData - Source domain data
|
|
1205
|
+
* @param {Object} targetData - Target domain data
|
|
1206
|
+
*/
|
|
1207
|
+
async applyDomainAdaptation(agentId, strategy, sourceData, targetData) {
|
|
1208
|
+
console.log(`Applying domain adaptation strategy '${strategy}' for agent ${agentId}`);
|
|
1209
|
+
|
|
1210
|
+
// Simulate domain adaptation (in practice, would involve actual training)
|
|
1211
|
+
const adaptationResult = {
|
|
1212
|
+
strategy,
|
|
1213
|
+
success: Math.random() > 0.3, // 70% success rate simulation
|
|
1214
|
+
efficiencyGain: Math.random() * 0.4 + 0.1, // 10-50% efficiency gain
|
|
1215
|
+
accuracyImprovement: Math.random() * 0.2 + 0.05, // 5-25% accuracy improvement
|
|
1216
|
+
adaptationTime: Math.random() * 100 + 50, // 50-150 time units
|
|
1217
|
+
transferredKnowledge: this.calculateTransferredKnowledge(sourceData, targetData),
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
// Store adaptation in transfer learning map
|
|
1221
|
+
if (!this.transferLearning.has(agentId)) {
|
|
1222
|
+
this.transferLearning.set(agentId, []);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
this.transferLearning.get(agentId).push({
|
|
1226
|
+
timestamp: Date.now(),
|
|
1227
|
+
strategy,
|
|
1228
|
+
result: adaptationResult,
|
|
1229
|
+
sourceDataSummary: this.summarizeData(sourceData),
|
|
1230
|
+
targetDataSummary: this.summarizeData(targetData),
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
return adaptationResult;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* Calculate amount of knowledge transferred
|
|
1238
|
+
* @param {Object} sourceData - Source domain data
|
|
1239
|
+
* @param {Object} targetData - Target domain data
|
|
1240
|
+
*/
|
|
1241
|
+
calculateTransferredKnowledge(sourceData, targetData) {
|
|
1242
|
+
// Simplified calculation based on data similarity
|
|
1243
|
+
const similarity = 1 - this.calculateDistributionShift(sourceData, targetData);
|
|
1244
|
+
return Math.max(0.1, similarity * 0.8); // 10-80% knowledge transfer
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* Summarize data for storage
|
|
1249
|
+
* @param {Object} data - Data to summarize
|
|
1250
|
+
*/
|
|
1251
|
+
summarizeData(data) {
|
|
1252
|
+
return {
|
|
1253
|
+
sampleCount: data.samples ? data.samples.length : 0,
|
|
1254
|
+
featureDimensions: this.getFeatureDimensions(data),
|
|
1255
|
+
uniqueLabels: this.extractLabels(data).size,
|
|
1256
|
+
dataType: this.inferDataType(data),
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Infer data type from samples
|
|
1262
|
+
* @param {Object} data - Data object
|
|
1263
|
+
*/
|
|
1264
|
+
inferDataType(data) {
|
|
1265
|
+
if (!data.samples || data.samples.length === 0) {
|
|
1266
|
+
return 'unknown';
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
const sample = data.samples[0];
|
|
1270
|
+
|
|
1271
|
+
if (Array.isArray(sample)) {
|
|
1272
|
+
return sample.length > 100 ? 'image' : 'vector';
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
if (typeof sample === 'object') {
|
|
1276
|
+
if (sample.sequence) {
|
|
1277
|
+
return 'sequence';
|
|
1278
|
+
}
|
|
1279
|
+
if (sample.text) {
|
|
1280
|
+
return 'text';
|
|
1281
|
+
}
|
|
1282
|
+
if (sample.image) {
|
|
1283
|
+
return 'image';
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
return 'scalar';
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Get meta-learning statistics
|
|
1292
|
+
*/
|
|
1293
|
+
getStatistics() {
|
|
1294
|
+
const totalAgents = this.agentExperiences.size;
|
|
1295
|
+
let totalExperiences = 0;
|
|
1296
|
+
let totalAdaptations = 0;
|
|
1297
|
+
let avgSuccessRate = 0;
|
|
1298
|
+
|
|
1299
|
+
for (const [agentId, experiences] of this.agentExperiences.entries()) {
|
|
1300
|
+
totalExperiences += experiences.length;
|
|
1301
|
+
|
|
1302
|
+
const adaptations = experiences.filter(exp => exp.type === 'domain_adaptation');
|
|
1303
|
+
totalAdaptations += adaptations.length;
|
|
1304
|
+
|
|
1305
|
+
const metrics = this.learningMetrics.get(agentId);
|
|
1306
|
+
if (metrics) {
|
|
1307
|
+
avgSuccessRate += metrics.adaptationSuccessRate;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
return {
|
|
1312
|
+
totalAgents,
|
|
1313
|
+
totalExperiences,
|
|
1314
|
+
totalAdaptations,
|
|
1315
|
+
avgExperiencesPerAgent: totalAgents > 0 ? totalExperiences / totalAgents : 0,
|
|
1316
|
+
avgSuccessRate: totalAgents > 0 ? avgSuccessRate / totalAgents : 0,
|
|
1317
|
+
availableStrategies: this.metaStrategies.size,
|
|
1318
|
+
transferLearningInstances: this.transferLearning.size,
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Preserve meta-learning state for agent
|
|
1324
|
+
* @param {string} agentId - Agent identifier
|
|
1325
|
+
*/
|
|
1326
|
+
async preserveState(agentId) {
|
|
1327
|
+
return {
|
|
1328
|
+
experiences: this.agentExperiences.get(agentId) || [],
|
|
1329
|
+
domainAdaptations: this.domainAdaptations.get(agentId) || [],
|
|
1330
|
+
transferLearning: this.transferLearning.get(agentId) || [],
|
|
1331
|
+
learningMetrics: this.learningMetrics.get(agentId) || null,
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* Restore meta-learning state for agent
|
|
1337
|
+
* @param {string} agentId - Agent identifier
|
|
1338
|
+
* @param {Object} state - Preserved state
|
|
1339
|
+
*/
|
|
1340
|
+
async restoreState(agentId, state) {
|
|
1341
|
+
if (state.experiences) {
|
|
1342
|
+
this.agentExperiences.set(agentId, state.experiences);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
if (state.domainAdaptations) {
|
|
1346
|
+
this.domainAdaptations.set(agentId, state.domainAdaptations);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
if (state.transferLearning) {
|
|
1350
|
+
this.transferLearning.set(agentId, state.transferLearning);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
if (state.learningMetrics) {
|
|
1354
|
+
this.learningMetrics.set(agentId, state.learningMetrics);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
export { MetaLearningFramework };
|