agentdb 1.0.0
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/LICENSE +38 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +953 -0
- package/bin/agentdb.js +485 -0
- package/bin/plugin-cli-wrapper.mjs +21 -0
- package/dist/cache/query-cache.d.ts +105 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +224 -0
- package/dist/cache/query-cache.js.map +1 -0
- package/dist/cache/query-cache.mjs +219 -0
- package/dist/cli/cache/query-cache.d.ts +104 -0
- package/dist/cli/cache/query-cache.js +244 -0
- package/dist/cli/cli/db-commands.d.ts +48 -0
- package/dist/cli/cli/db-commands.js +613 -0
- package/dist/cli/commands.d.ts +7 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +113 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/core/backend-interface.d.ts +70 -0
- package/dist/cli/core/backend-interface.js +15 -0
- package/dist/cli/core/native-backend.d.ts +140 -0
- package/dist/cli/core/native-backend.js +432 -0
- package/dist/cli/core/vector-db.d.ts +126 -0
- package/dist/cli/core/vector-db.js +338 -0
- package/dist/cli/core/wasm-backend.d.ts +95 -0
- package/dist/cli/core/wasm-backend.js +418 -0
- package/dist/cli/db-commands.d.ts +49 -0
- package/dist/cli/db-commands.d.ts.map +1 -0
- package/dist/cli/db-commands.js +533 -0
- package/dist/cli/db-commands.js.map +1 -0
- package/dist/cli/db-commands.mjs +522 -0
- package/dist/cli/generator.d.ts +11 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +567 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/generator.mjs +527 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +676 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/help.mjs +667 -0
- package/dist/cli/index/hnsw.d.ts +164 -0
- package/dist/cli/index/hnsw.js +558 -0
- package/dist/cli/plugin-cli.d.ts +7 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +295 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-cli.mjs +289 -0
- package/dist/cli/quantization/product-quantization.d.ts +108 -0
- package/dist/cli/quantization/product-quantization.js +350 -0
- package/dist/cli/query/query-builder.d.ts +322 -0
- package/dist/cli/query/query-builder.js +600 -0
- package/dist/cli/templates.d.ts +14 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +182 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/templates.mjs +176 -0
- package/dist/cli/types/index.d.ts +116 -0
- package/dist/cli/types/index.js +5 -0
- package/dist/cli/types.d.ts +91 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +6 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/types.mjs +4 -0
- package/dist/cli/wizard/index.d.ts +6 -0
- package/dist/cli/wizard/index.d.ts.map +1 -0
- package/dist/cli/wizard/index.js +138 -0
- package/dist/cli/wizard/index.js.map +1 -0
- package/dist/cli/wizard/index.mjs +131 -0
- package/dist/cli/wizard/prompts.d.ts +11 -0
- package/dist/cli/wizard/prompts.d.ts.map +1 -0
- package/dist/cli/wizard/prompts.js +482 -0
- package/dist/cli/wizard/prompts.js.map +1 -0
- package/dist/cli/wizard/prompts.mjs +470 -0
- package/dist/cli/wizard/validator.d.ts +13 -0
- package/dist/cli/wizard/validator.d.ts.map +1 -0
- package/dist/cli/wizard/validator.js +234 -0
- package/dist/cli/wizard/validator.js.map +1 -0
- package/dist/cli/wizard/validator.mjs +224 -0
- package/dist/core/backend-interface.d.ts +71 -0
- package/dist/core/backend-interface.d.ts.map +1 -0
- package/dist/core/backend-interface.js +16 -0
- package/dist/core/backend-interface.js.map +1 -0
- package/dist/core/backend-interface.mjs +12 -0
- package/dist/core/native-backend.d.ts +141 -0
- package/dist/core/native-backend.d.ts.map +1 -0
- package/dist/core/native-backend.js +457 -0
- package/dist/core/native-backend.js.map +1 -0
- package/dist/core/native-backend.mjs +449 -0
- package/dist/core/vector-db.d.ts +127 -0
- package/dist/core/vector-db.d.ts.map +1 -0
- package/dist/core/vector-db.js +266 -0
- package/dist/core/vector-db.js.map +1 -0
- package/dist/core/vector-db.mjs +261 -0
- package/dist/core/wasm-backend.d.ts +96 -0
- package/dist/core/wasm-backend.d.ts.map +1 -0
- package/dist/core/wasm-backend.js +393 -0
- package/dist/core/wasm-backend.js.map +1 -0
- package/dist/core/wasm-backend.mjs +385 -0
- package/dist/index/hnsw-optimized.d.ts +75 -0
- package/dist/index/hnsw-optimized.d.ts.map +1 -0
- package/dist/index/hnsw-optimized.js +412 -0
- package/dist/index/hnsw-optimized.js.map +1 -0
- package/dist/index/hnsw-optimized.mjs +407 -0
- package/dist/index/hnsw.d.ts +165 -0
- package/dist/index/hnsw.d.ts.map +1 -0
- package/dist/index/hnsw.js +521 -0
- package/dist/index/hnsw.js.map +1 -0
- package/dist/index/hnsw.mjs +516 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +789 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +784 -0
- package/dist/plugins/base-plugin.d.ts +114 -0
- package/dist/plugins/base-plugin.d.ts.map +1 -0
- package/dist/plugins/base-plugin.js +313 -0
- package/dist/plugins/base-plugin.js.map +1 -0
- package/dist/plugins/base-plugin.mjs +275 -0
- package/dist/plugins/implementations/active-learning.d.ts +135 -0
- package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/active-learning.js +372 -0
- package/dist/plugins/implementations/active-learning.js.map +1 -0
- package/dist/plugins/implementations/active-learning.mjs +367 -0
- package/dist/plugins/implementations/actor-critic.d.ts +64 -0
- package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
- package/dist/plugins/implementations/actor-critic.js +363 -0
- package/dist/plugins/implementations/actor-critic.js.map +1 -0
- package/dist/plugins/implementations/actor-critic.mjs +358 -0
- package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
- package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
- package/dist/plugins/implementations/adversarial-training.js +409 -0
- package/dist/plugins/implementations/adversarial-training.js.map +1 -0
- package/dist/plugins/implementations/adversarial-training.mjs +404 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.js +354 -0
- package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
- package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
- package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
- package/dist/plugins/implementations/decision-transformer.js +422 -0
- package/dist/plugins/implementations/decision-transformer.js.map +1 -0
- package/dist/plugins/implementations/decision-transformer.mjs +417 -0
- package/dist/plugins/implementations/federated-learning.d.ts +126 -0
- package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/federated-learning.js +436 -0
- package/dist/plugins/implementations/federated-learning.js.map +1 -0
- package/dist/plugins/implementations/federated-learning.mjs +431 -0
- package/dist/plugins/implementations/index.d.ts +30 -0
- package/dist/plugins/implementations/index.d.ts.map +1 -0
- package/dist/plugins/implementations/index.js +45 -0
- package/dist/plugins/implementations/index.js.map +1 -0
- package/dist/plugins/implementations/index.mjs +31 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.js +369 -0
- package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.js +379 -0
- package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
- package/dist/plugins/implementations/q-learning.d.ts +98 -0
- package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/q-learning.js +435 -0
- package/dist/plugins/implementations/q-learning.js.map +1 -0
- package/dist/plugins/implementations/q-learning.mjs +430 -0
- package/dist/plugins/implementations/sarsa.d.ts +103 -0
- package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
- package/dist/plugins/implementations/sarsa.js +347 -0
- package/dist/plugins/implementations/sarsa.js.map +1 -0
- package/dist/plugins/implementations/sarsa.mjs +342 -0
- package/dist/plugins/index.d.ts +107 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +179 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +168 -0
- package/dist/plugins/interface.d.ts +439 -0
- package/dist/plugins/interface.d.ts.map +1 -0
- package/dist/plugins/interface.js +12 -0
- package/dist/plugins/interface.js.map +1 -0
- package/dist/plugins/interface.mjs +10 -0
- package/dist/plugins/learning-plugin.interface.d.ts +257 -0
- package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
- package/dist/plugins/learning-plugin.interface.js +7 -0
- package/dist/plugins/learning-plugin.interface.js.map +1 -0
- package/dist/plugins/learning-plugin.interface.mjs +5 -0
- package/dist/plugins/plugin-exports.d.ts +71 -0
- package/dist/plugins/plugin-exports.d.ts.map +1 -0
- package/dist/plugins/plugin-exports.js +78 -0
- package/dist/plugins/plugin-exports.js.map +1 -0
- package/dist/plugins/plugin-exports.mjs +69 -0
- package/dist/plugins/registry.d.ts +206 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +365 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/registry.mjs +356 -0
- package/dist/plugins/validator.d.ts +63 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +464 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/plugins/validator.mjs +458 -0
- package/dist/quantization/binary-quantization.d.ts +104 -0
- package/dist/quantization/binary-quantization.d.ts.map +1 -0
- package/dist/quantization/binary-quantization.js +246 -0
- package/dist/quantization/binary-quantization.js.map +1 -0
- package/dist/quantization/binary-quantization.mjs +240 -0
- package/dist/quantization/optimized-pq.d.ts +138 -0
- package/dist/quantization/optimized-pq.d.ts.map +1 -0
- package/dist/quantization/optimized-pq.js +320 -0
- package/dist/quantization/optimized-pq.js.map +1 -0
- package/dist/quantization/optimized-pq.mjs +313 -0
- package/dist/quantization/product-quantization.d.ts +109 -0
- package/dist/quantization/product-quantization.d.ts.map +1 -0
- package/dist/quantization/product-quantization.js +287 -0
- package/dist/quantization/product-quantization.js.map +1 -0
- package/dist/quantization/product-quantization.mjs +282 -0
- package/dist/quantization/scalar-quantization.d.ts +100 -0
- package/dist/quantization/scalar-quantization.d.ts.map +1 -0
- package/dist/quantization/scalar-quantization.js +324 -0
- package/dist/quantization/scalar-quantization.js.map +1 -0
- package/dist/quantization/scalar-quantization.mjs +319 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +9 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/index.mjs +4 -0
- package/dist/query/query-builder.d.ts +323 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +524 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +519 -0
- package/dist/reasoning/context-synthesizer.d.ts +57 -0
- package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoning/context-synthesizer.js +224 -0
- package/dist/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoning/context-synthesizer.mjs +219 -0
- package/dist/reasoning/experience-curator.d.ts +66 -0
- package/dist/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoning/experience-curator.js +288 -0
- package/dist/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoning/experience-curator.mjs +283 -0
- package/dist/reasoning/memory-optimizer.d.ts +69 -0
- package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoning/memory-optimizer.js +331 -0
- package/dist/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoning/memory-optimizer.mjs +326 -0
- package/dist/reasoning/pattern-matcher.d.ts +59 -0
- package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoning/pattern-matcher.js +229 -0
- package/dist/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoning/pattern-matcher.mjs +224 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
- package/dist/reasoningbank/adapter/types.d.ts +113 -0
- package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/types.js +9 -0
- package/dist/reasoningbank/adapter/types.js.map +1 -0
- package/dist/reasoningbank/cli/commands.d.ts +16 -0
- package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
- package/dist/reasoningbank/cli/commands.js +272 -0
- package/dist/reasoningbank/cli/commands.js.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
- package/dist/reasoningbank/migration/migrate.d.ts +25 -0
- package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
- package/dist/reasoningbank/migration/migrate.js +178 -0
- package/dist/reasoningbank/migration/migrate.js.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
- package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.js +165 -0
- package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
- package/dist/sync/conflict.d.ts +78 -0
- package/dist/sync/conflict.d.ts.map +1 -0
- package/dist/sync/conflict.js +202 -0
- package/dist/sync/conflict.js.map +1 -0
- package/dist/sync/conflict.mjs +196 -0
- package/dist/sync/coordinator.d.ts +111 -0
- package/dist/sync/coordinator.d.ts.map +1 -0
- package/dist/sync/coordinator.js +256 -0
- package/dist/sync/coordinator.js.map +1 -0
- package/dist/sync/coordinator.mjs +250 -0
- package/dist/sync/delta.d.ts +81 -0
- package/dist/sync/delta.d.ts.map +1 -0
- package/dist/sync/delta.js +245 -0
- package/dist/sync/delta.js.map +1 -0
- package/dist/sync/delta.mjs +238 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +22 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/index.mjs +9 -0
- package/dist/sync/quic-sync.d.ts +81 -0
- package/dist/sync/quic-sync.d.ts.map +1 -0
- package/dist/sync/quic-sync.js +329 -0
- package/dist/sync/quic-sync.js.map +1 -0
- package/dist/sync/quic-sync.mjs +323 -0
- package/dist/sync/types.d.ts +168 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +8 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/types.mjs +6 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/wasm-loader.d.ts +32 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +75 -0
- package/dist/wasm-loader.js.map +1 -0
- package/dist/wasm-loader.mjs +64 -0
- package/examples/adaptive-learning.ts +284 -0
- package/examples/browser/README.md +732 -0
- package/examples/browser/adaptive-recommendations/index.html +427 -0
- package/examples/browser/collaborative-filtering/index.html +310 -0
- package/examples/browser/continual-learning/index.html +736 -0
- package/examples/browser/experience-replay/index.html +616 -0
- package/examples/browser/index.html +369 -0
- package/examples/browser/meta-learning/index.html +789 -0
- package/examples/browser/neuro-symbolic/index.html +692 -0
- package/examples/browser/pattern-learning/index.html +620 -0
- package/examples/browser/quantum-inspired/index.html +728 -0
- package/examples/browser/rag/index.html +624 -0
- package/examples/browser/swarm-intelligence/index.html +811 -0
- package/examples/browser-basic.html +170 -0
- package/examples/hnsw-example.ts +148 -0
- package/examples/node-basic.js +70 -0
- package/examples/quic-sync-example.ts +310 -0
- package/examples/quick-start.js +68 -0
- package/examples/wasm-example.ts +222 -0
- package/package.json +118 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision Transformer Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements the Decision Transformer algorithm with 3-tier action selection:
|
|
5
|
+
* - Tier 1: Exact retrieval (99% similarity)
|
|
6
|
+
* - Tier 2: k-NN interpolation (95% similarity)
|
|
7
|
+
* - Tier 3: Neural network generation
|
|
8
|
+
*
|
|
9
|
+
* Based on "Decision Transformer: Reinforcement Learning via Sequence Modeling"
|
|
10
|
+
* https://arxiv.org/abs/2106.01345
|
|
11
|
+
*/
|
|
12
|
+
import { BasePlugin } from '../base-plugin.mjs';
|
|
13
|
+
/**
|
|
14
|
+
* Decision layer network for neural action generation
|
|
15
|
+
*/
|
|
16
|
+
class DecisionLayer {
|
|
17
|
+
constructor(inputSize = 2304, hiddenSize = 256, outputSize = 768) {
|
|
18
|
+
this.lastConfidence = 0;
|
|
19
|
+
this.inputSize = inputSize;
|
|
20
|
+
this.hiddenSize = hiddenSize;
|
|
21
|
+
this.outputSize = outputSize;
|
|
22
|
+
// Initialize weights with Xavier/He initialization
|
|
23
|
+
this.weights = {
|
|
24
|
+
W1: this.initializeWeights(inputSize * hiddenSize, inputSize),
|
|
25
|
+
b1: new Float32Array(hiddenSize),
|
|
26
|
+
W2: this.initializeWeights(hiddenSize * outputSize, hiddenSize),
|
|
27
|
+
b2: new Float32Array(outputSize),
|
|
28
|
+
};
|
|
29
|
+
// Initialize Adam optimizer state
|
|
30
|
+
this.optimizer = {
|
|
31
|
+
m_W1: new Float32Array(inputSize * hiddenSize),
|
|
32
|
+
v_W1: new Float32Array(inputSize * hiddenSize),
|
|
33
|
+
m_b1: new Float32Array(hiddenSize),
|
|
34
|
+
v_b1: new Float32Array(hiddenSize),
|
|
35
|
+
m_W2: new Float32Array(hiddenSize * outputSize),
|
|
36
|
+
v_W2: new Float32Array(hiddenSize * outputSize),
|
|
37
|
+
m_b2: new Float32Array(outputSize),
|
|
38
|
+
v_b2: new Float32Array(outputSize),
|
|
39
|
+
t: 0,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Initialize weights using He initialization
|
|
44
|
+
*/
|
|
45
|
+
initializeWeights(size, fanIn) {
|
|
46
|
+
const weights = new Float32Array(size);
|
|
47
|
+
const std = Math.sqrt(2.0 / fanIn);
|
|
48
|
+
for (let i = 0; i < size; i++) {
|
|
49
|
+
weights[i] = (Math.random() * 2 - 1) * std;
|
|
50
|
+
}
|
|
51
|
+
return weights;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Forward pass through the network
|
|
55
|
+
*/
|
|
56
|
+
predict(state, desiredReturn, history = []) {
|
|
57
|
+
// Prepare input
|
|
58
|
+
const returnEncoding = this.encodeReturn(desiredReturn);
|
|
59
|
+
const historyEncoding = history.length > 0 ? history : new Array(768).fill(0);
|
|
60
|
+
const input = new Float32Array([...state, ...returnEncoding, ...historyEncoding]);
|
|
61
|
+
// Layer 1: hidden = ReLU(W1 * input + b1)
|
|
62
|
+
const z1 = this.matmul(this.weights.W1, input, this.hiddenSize, this.inputSize);
|
|
63
|
+
const hidden = this.relu(this.add(z1, this.weights.b1));
|
|
64
|
+
// Layer 2: output = W2 * hidden + b2
|
|
65
|
+
const z2 = this.matmul(this.weights.W2, hidden, this.outputSize, this.hiddenSize);
|
|
66
|
+
const output = this.add(z2, this.weights.b2);
|
|
67
|
+
// Compute confidence
|
|
68
|
+
this.lastConfidence = this.computeConfidence(hidden, output);
|
|
69
|
+
return Array.from(output);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Train on a batch of experiences
|
|
73
|
+
*/
|
|
74
|
+
trainBatch(states, actions, returns, learningRate = 0.001) {
|
|
75
|
+
let totalLoss = 0;
|
|
76
|
+
for (let i = 0; i < states.length; i++) {
|
|
77
|
+
const predicted = this.predict(states[i], returns[i]);
|
|
78
|
+
const target = actions[i];
|
|
79
|
+
// Compute MSE loss
|
|
80
|
+
const loss = this.computeLoss(predicted, target);
|
|
81
|
+
totalLoss += loss;
|
|
82
|
+
// Backward pass
|
|
83
|
+
this.backward(predicted, target, learningRate);
|
|
84
|
+
}
|
|
85
|
+
return totalLoss / states.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Compute MSE loss
|
|
89
|
+
*/
|
|
90
|
+
computeLoss(predicted, target) {
|
|
91
|
+
let sum = 0;
|
|
92
|
+
for (let i = 0; i < predicted.length; i++) {
|
|
93
|
+
const diff = predicted[i] - target[i];
|
|
94
|
+
sum += diff * diff;
|
|
95
|
+
}
|
|
96
|
+
return sum / predicted.length;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Backward pass (simplified)
|
|
100
|
+
*/
|
|
101
|
+
backward(predicted, target, learningRate) {
|
|
102
|
+
// Compute gradient
|
|
103
|
+
const gradient = new Float32Array(predicted.length);
|
|
104
|
+
for (let i = 0; i < predicted.length; i++) {
|
|
105
|
+
gradient[i] = predicted[i] - target[i];
|
|
106
|
+
}
|
|
107
|
+
// Update weights using Adam optimizer
|
|
108
|
+
this.optimizer.t++;
|
|
109
|
+
// Simplified Adam update (full implementation would update all layers)
|
|
110
|
+
const beta1 = 0.9;
|
|
111
|
+
const beta2 = 0.999;
|
|
112
|
+
const epsilon = 1e-8;
|
|
113
|
+
// Update bias for output layer as example
|
|
114
|
+
for (let i = 0; i < this.weights.b2.length; i++) {
|
|
115
|
+
const g = gradient[i];
|
|
116
|
+
this.optimizer.m_b2[i] = beta1 * this.optimizer.m_b2[i] + (1 - beta1) * g;
|
|
117
|
+
this.optimizer.v_b2[i] = beta2 * this.optimizer.v_b2[i] + (1 - beta2) * g * g;
|
|
118
|
+
const mHat = this.optimizer.m_b2[i] / (1 - Math.pow(beta1, this.optimizer.t));
|
|
119
|
+
const vHat = this.optimizer.v_b2[i] / (1 - Math.pow(beta2, this.optimizer.t));
|
|
120
|
+
this.weights.b2[i] -= learningRate * mHat / (Math.sqrt(vHat) + epsilon);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Encode desired return as positional embedding
|
|
125
|
+
*/
|
|
126
|
+
encodeReturn(r) {
|
|
127
|
+
const encoding = new Float32Array(768);
|
|
128
|
+
for (let i = 0; i < 768; i++) {
|
|
129
|
+
const pos = r * 10000;
|
|
130
|
+
const div = Math.exp((i * -Math.log(10000)) / 768);
|
|
131
|
+
encoding[i] = i % 2 === 0 ? Math.sin(pos * div) : Math.cos(pos * div);
|
|
132
|
+
}
|
|
133
|
+
return Array.from(encoding);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Compute confidence from network activations
|
|
137
|
+
*/
|
|
138
|
+
computeConfidence(hidden, output) {
|
|
139
|
+
const hiddenNorm = Math.sqrt(Array.from(hidden).reduce((sum, x) => sum + x * x, 0));
|
|
140
|
+
const outputNorm = Math.sqrt(Array.from(output).reduce((sum, x) => sum + x * x, 0));
|
|
141
|
+
const hiddenScore = 1.0 - Math.abs(hiddenNorm - 50) / 100;
|
|
142
|
+
const outputScore = 1.0 - Math.abs(outputNorm - 10) / 20;
|
|
143
|
+
return Math.max(0, Math.min(1, (hiddenScore + outputScore) / 2));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Matrix-vector multiplication
|
|
147
|
+
*/
|
|
148
|
+
matmul(matrix, vector, rows, cols) {
|
|
149
|
+
const result = new Float32Array(rows);
|
|
150
|
+
for (let i = 0; i < rows; i++) {
|
|
151
|
+
let sum = 0;
|
|
152
|
+
for (let j = 0; j < cols; j++) {
|
|
153
|
+
sum += matrix[i * cols + j] * vector[j];
|
|
154
|
+
}
|
|
155
|
+
result[i] = sum;
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* ReLU activation
|
|
161
|
+
*/
|
|
162
|
+
relu(x) {
|
|
163
|
+
return x.map(val => Math.max(0, val));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Vector addition
|
|
167
|
+
*/
|
|
168
|
+
add(a, b) {
|
|
169
|
+
const result = new Float32Array(a.length);
|
|
170
|
+
for (let i = 0; i < a.length; i++) {
|
|
171
|
+
result[i] = a[i] + b[i];
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
getLastConfidence() {
|
|
176
|
+
return this.lastConfidence;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Decision Transformer Plugin Implementation
|
|
181
|
+
*/
|
|
182
|
+
export class DecisionTransformerPlugin extends BasePlugin {
|
|
183
|
+
constructor() {
|
|
184
|
+
super(...arguments);
|
|
185
|
+
this.name = 'decision-transformer';
|
|
186
|
+
this.version = '1.0.0';
|
|
187
|
+
this.tier1Threshold = 0.99;
|
|
188
|
+
this.tier2Threshold = 0.95;
|
|
189
|
+
this.kNeighbors = 5;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Initialize the Decision Transformer plugin
|
|
193
|
+
*/
|
|
194
|
+
async onInitialize() {
|
|
195
|
+
// Initialize decision layer
|
|
196
|
+
const stateSize = this.config.algorithm.stateDim || 768;
|
|
197
|
+
const hiddenSize = this.config.algorithm.hiddenSize || 256;
|
|
198
|
+
this.decisionLayer = new DecisionLayer(stateSize * 3, hiddenSize, stateSize);
|
|
199
|
+
// Get configuration parameters
|
|
200
|
+
this.tier1Threshold = this.config.algorithm.tier1Threshold || 0.99;
|
|
201
|
+
this.tier2Threshold = this.config.algorithm.tier2Threshold || 0.95;
|
|
202
|
+
this.kNeighbors = this.config.algorithm.kNeighbors || 5;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Select action using 3-tier strategy
|
|
206
|
+
*
|
|
207
|
+
* @param state - Current state vector
|
|
208
|
+
* @param context - Optional context including desired return
|
|
209
|
+
* @returns Selected action
|
|
210
|
+
*/
|
|
211
|
+
async selectAction(state, context) {
|
|
212
|
+
this.checkInitialized();
|
|
213
|
+
const desiredReturn = context?.desiredReturn || 1.0;
|
|
214
|
+
const startTime = Date.now();
|
|
215
|
+
// Tier 1: Exact retrieval
|
|
216
|
+
const tier1Action = await this.tryExactRetrieval(state, desiredReturn);
|
|
217
|
+
if (tier1Action) {
|
|
218
|
+
return {
|
|
219
|
+
...tier1Action,
|
|
220
|
+
metadata: { ...tier1Action.metadata, latency: Date.now() - startTime },
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
// Tier 2: k-NN interpolation
|
|
224
|
+
const tier2Action = await this.tryKNNInterpolation(state, desiredReturn);
|
|
225
|
+
if (tier2Action) {
|
|
226
|
+
return {
|
|
227
|
+
...tier2Action,
|
|
228
|
+
metadata: { ...tier2Action.metadata, latency: Date.now() - startTime },
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
// Tier 3: Neural generation
|
|
232
|
+
const tier3Action = await this.useNeuralGeneration(state, desiredReturn, context);
|
|
233
|
+
return {
|
|
234
|
+
...tier3Action,
|
|
235
|
+
metadata: { ...tier3Action.metadata, latency: Date.now() - startTime },
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Tier 1: Try exact retrieval
|
|
240
|
+
*/
|
|
241
|
+
async tryExactRetrieval(state, desiredReturn) {
|
|
242
|
+
const results = await this.retrieveSimilar(state, 1);
|
|
243
|
+
if (results.length === 0 || results[0].score < this.tier1Threshold) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const best = results[0];
|
|
247
|
+
if (!best.metadata) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
const returnToGo = this.computeReturnToGo(best.metadata);
|
|
251
|
+
if (returnToGo >= desiredReturn) {
|
|
252
|
+
return {
|
|
253
|
+
id: best.id,
|
|
254
|
+
embedding: best.metadata.action,
|
|
255
|
+
source: 'exact_retrieval',
|
|
256
|
+
confidence: best.score,
|
|
257
|
+
metadata: { tier: 1, returnToGo },
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Tier 2: Try k-NN interpolation
|
|
264
|
+
*/
|
|
265
|
+
async tryKNNInterpolation(state, desiredReturn) {
|
|
266
|
+
const results = await this.retrieveSimilar(state, this.kNeighbors);
|
|
267
|
+
// Filter by similarity and return
|
|
268
|
+
const successful = results.filter(r => r.metadata && r.score >= this.tier2Threshold && this.computeReturnToGo(r.metadata) >= desiredReturn);
|
|
269
|
+
if (successful.length < 3 || !successful[0].metadata) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
// Weighted average of actions
|
|
273
|
+
const weights = successful.map(r => r.score);
|
|
274
|
+
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
|
275
|
+
const actionDim = successful[0].metadata.action.length;
|
|
276
|
+
const avgEmbedding = new Float32Array(actionDim);
|
|
277
|
+
for (let i = 0; i < successful.length; i++) {
|
|
278
|
+
const weight = weights[i] / totalWeight;
|
|
279
|
+
const action = successful[i].metadata.action;
|
|
280
|
+
for (let j = 0; j < actionDim; j++) {
|
|
281
|
+
avgEmbedding[j] += action[j] * weight;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
id: `interpolated_${successful.length}`,
|
|
286
|
+
embedding: Array.from(avgEmbedding),
|
|
287
|
+
source: 'knn_interpolation',
|
|
288
|
+
confidence: totalWeight / successful.length,
|
|
289
|
+
metadata: { tier: 2, kNeighbors: successful.length },
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Tier 3: Use neural network generation
|
|
294
|
+
*/
|
|
295
|
+
async useNeuralGeneration(state, desiredReturn, context) {
|
|
296
|
+
// Get history from context if available
|
|
297
|
+
const history = context?.history
|
|
298
|
+
? this.encodeHistory(context.history)
|
|
299
|
+
: new Array(768).fill(0);
|
|
300
|
+
// Generate action using decision layer
|
|
301
|
+
const actionEmbedding = this.decisionLayer.predict(state, desiredReturn, history);
|
|
302
|
+
return {
|
|
303
|
+
id: 'neural_generated',
|
|
304
|
+
embedding: actionEmbedding,
|
|
305
|
+
source: 'neural_network',
|
|
306
|
+
confidence: this.decisionLayer.getLastConfidence(),
|
|
307
|
+
metadata: { tier: 3 },
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Train the decision layer on stored experiences
|
|
312
|
+
*/
|
|
313
|
+
async train(options) {
|
|
314
|
+
this.checkInitialized();
|
|
315
|
+
const epochs = options?.epochs || this.config.training.epochs || 10;
|
|
316
|
+
const batchSize = options?.batchSize || this.config.training.batchSize;
|
|
317
|
+
const learningRate = options?.learningRate || this.config.algorithm.learningRate;
|
|
318
|
+
// Fetch all experiences (in production, batch this)
|
|
319
|
+
const allExperiences = await this.getAllExperiences();
|
|
320
|
+
if (allExperiences.length < this.config.training.minExperiences) {
|
|
321
|
+
throw new Error(`Not enough experiences to train. Need ${this.config.training.minExperiences}, have ${allExperiences.length}`);
|
|
322
|
+
}
|
|
323
|
+
let totalLoss = 0;
|
|
324
|
+
const gamma = this.config.algorithm.discountFactor || 0.99;
|
|
325
|
+
// Group by episode and compute returns
|
|
326
|
+
const episodes = this.groupByEpisode(allExperiences);
|
|
327
|
+
for (let epoch = 0; epoch < epochs; epoch++) {
|
|
328
|
+
let epochLoss = 0;
|
|
329
|
+
for (const episode of episodes) {
|
|
330
|
+
const rewards = episode.map(e => e.reward);
|
|
331
|
+
const returns = this.computeReturns(rewards, gamma);
|
|
332
|
+
// Train on each step
|
|
333
|
+
const states = episode.map(e => e.state);
|
|
334
|
+
const actions = episode.map(e => e.action);
|
|
335
|
+
epochLoss += this.decisionLayer.trainBatch(states, actions, returns, learningRate);
|
|
336
|
+
}
|
|
337
|
+
totalLoss = epochLoss / episodes.length;
|
|
338
|
+
if (options?.verbose) {
|
|
339
|
+
console.log(`Epoch ${epoch + 1}/${epochs}: Loss = ${totalLoss.toFixed(4)}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
loss: totalLoss,
|
|
344
|
+
episodesTrained: episodes.length,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Compute return-to-go from experience metadata
|
|
349
|
+
*/
|
|
350
|
+
computeReturnToGo(metadata) {
|
|
351
|
+
return metadata.returnToGo || metadata.reward || 0;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Encode history as average of recent states
|
|
355
|
+
*/
|
|
356
|
+
encodeHistory(history) {
|
|
357
|
+
if (history.length === 0) {
|
|
358
|
+
return new Array(768).fill(0);
|
|
359
|
+
}
|
|
360
|
+
const recent = history.slice(-5); // Last 5 experiences
|
|
361
|
+
const avg = new Float32Array(recent[0].state.length);
|
|
362
|
+
for (const exp of recent) {
|
|
363
|
+
for (let i = 0; i < exp.state.length; i++) {
|
|
364
|
+
avg[i] += exp.state[i];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
for (let i = 0; i < avg.length; i++) {
|
|
368
|
+
avg[i] /= recent.length;
|
|
369
|
+
}
|
|
370
|
+
return Array.from(avg);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get all experiences (helper method)
|
|
374
|
+
*/
|
|
375
|
+
async getAllExperiences() {
|
|
376
|
+
// This is a simplified version - in production, batch fetch
|
|
377
|
+
const stats = this.vectorDB.stats();
|
|
378
|
+
const experiences = [];
|
|
379
|
+
// For now, return empty - proper implementation would fetch from DB
|
|
380
|
+
// This would need backend support to efficiently fetch all vectors
|
|
381
|
+
return experiences;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Group experiences by episode
|
|
385
|
+
*/
|
|
386
|
+
groupByEpisode(experiences) {
|
|
387
|
+
const episodes = new Map();
|
|
388
|
+
for (const exp of experiences) {
|
|
389
|
+
const episodeId = exp.episodeId || 'default';
|
|
390
|
+
if (!episodes.has(episodeId)) {
|
|
391
|
+
episodes.set(episodeId, []);
|
|
392
|
+
}
|
|
393
|
+
episodes.get(episodeId).push(exp);
|
|
394
|
+
}
|
|
395
|
+
// Sort each episode by step index
|
|
396
|
+
for (const episode of episodes.values()) {
|
|
397
|
+
episode.sort((a, b) => (a.stepIndex || 0) - (b.stepIndex || 0));
|
|
398
|
+
}
|
|
399
|
+
return Array.from(episodes.values());
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Save model weights
|
|
403
|
+
*/
|
|
404
|
+
async onSave(path) {
|
|
405
|
+
// Save decision layer weights
|
|
406
|
+
// In production, serialize weights to file
|
|
407
|
+
console.log(`Saving Decision Transformer model to ${path}`);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Load model weights
|
|
411
|
+
*/
|
|
412
|
+
async onLoad(path) {
|
|
413
|
+
// Load decision layer weights
|
|
414
|
+
// In production, deserialize weights from file
|
|
415
|
+
console.log(`Loading Decision Transformer model from ${path}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Federated Learning Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements privacy-preserving distributed learning where multiple
|
|
5
|
+
* agents learn collaboratively without sharing raw data.
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
* - Client-side model updates
|
|
9
|
+
* - Secure aggregation of gradients
|
|
10
|
+
* - Differential privacy
|
|
11
|
+
* - Byzantine fault tolerance
|
|
12
|
+
* - Personalized federated learning
|
|
13
|
+
*/
|
|
14
|
+
import { BasePlugin } from '../base-plugin';
|
|
15
|
+
import { Action, Context, Experience, TrainOptions, TrainingMetrics, Vector } from '../learning-plugin.interface';
|
|
16
|
+
/**
|
|
17
|
+
* Federated Learning Plugin Implementation
|
|
18
|
+
*/
|
|
19
|
+
export declare class FederatedLearningPlugin extends BasePlugin {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
private experiences;
|
|
23
|
+
private clients;
|
|
24
|
+
private globalWeights;
|
|
25
|
+
private roundNumber;
|
|
26
|
+
private aggregationStrategy;
|
|
27
|
+
private privacyBudget;
|
|
28
|
+
private noisyScale;
|
|
29
|
+
private clippingNorm;
|
|
30
|
+
private byzantineFraction;
|
|
31
|
+
private useMedianAggregation;
|
|
32
|
+
constructor(config?: Partial<any>);
|
|
33
|
+
/**
|
|
34
|
+
* Override to skip initialization check for in-memory operation
|
|
35
|
+
*/
|
|
36
|
+
protected checkInitialized(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Override to store experiences in-memory without vectorDB
|
|
39
|
+
*/
|
|
40
|
+
storeExperience(experience: Experience): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Override to retrieve from local experiences
|
|
43
|
+
*/
|
|
44
|
+
retrieveSimilar(state: number[], k: number): Promise<import('../..').SearchResult<Experience>[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Initialize global model weights
|
|
47
|
+
*/
|
|
48
|
+
private initializeGlobalModel;
|
|
49
|
+
/**
|
|
50
|
+
* Register a new federated client
|
|
51
|
+
*/
|
|
52
|
+
registerClient(clientId: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Client performs local training
|
|
55
|
+
*/
|
|
56
|
+
trainLocalModel(clientId: string, experiences: Experience[], epochs?: number): Promise<Map<string, Vector>>;
|
|
57
|
+
/**
|
|
58
|
+
* Compute gradients for experience
|
|
59
|
+
*/
|
|
60
|
+
private computeGradients;
|
|
61
|
+
/**
|
|
62
|
+
* Add differential privacy noise to gradients
|
|
63
|
+
*/
|
|
64
|
+
private addDifferentialPrivacy;
|
|
65
|
+
/**
|
|
66
|
+
* Clip gradients for privacy
|
|
67
|
+
*/
|
|
68
|
+
private clipGradients;
|
|
69
|
+
/**
|
|
70
|
+
* Aggregate client updates into global model
|
|
71
|
+
*/
|
|
72
|
+
aggregateUpdates(clientIds: string[]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* FedAvg: Weighted average by data count
|
|
75
|
+
*/
|
|
76
|
+
private aggregateFedAvg;
|
|
77
|
+
/**
|
|
78
|
+
* FedProx: Proximal term to handle heterogeneity
|
|
79
|
+
*/
|
|
80
|
+
private aggregateFedProx;
|
|
81
|
+
/**
|
|
82
|
+
* FedOpt: Server-side adaptive optimization
|
|
83
|
+
*/
|
|
84
|
+
private aggregateFedOpt;
|
|
85
|
+
/**
|
|
86
|
+
* SCAFFOLD: Control variates to reduce client drift
|
|
87
|
+
*/
|
|
88
|
+
private aggregateScaffold;
|
|
89
|
+
/**
|
|
90
|
+
* Detect and filter Byzantine clients
|
|
91
|
+
*/
|
|
92
|
+
private filterByzantineClients;
|
|
93
|
+
/**
|
|
94
|
+
* Broadcast updated global model to all clients
|
|
95
|
+
*/
|
|
96
|
+
private broadcastGlobalModel;
|
|
97
|
+
/**
|
|
98
|
+
* Encode state vector for transmission
|
|
99
|
+
*/
|
|
100
|
+
private encodeState;
|
|
101
|
+
/**
|
|
102
|
+
* Select action using current global model
|
|
103
|
+
*/
|
|
104
|
+
selectAction(state: Vector, context?: Context): Promise<Action>;
|
|
105
|
+
/**
|
|
106
|
+
* Forward pass through layer
|
|
107
|
+
*/
|
|
108
|
+
private forward;
|
|
109
|
+
/**
|
|
110
|
+
* Train using federated learning rounds
|
|
111
|
+
*/
|
|
112
|
+
train(options?: TrainOptions): Promise<TrainingMetrics>;
|
|
113
|
+
/**
|
|
114
|
+
* Get global model weights
|
|
115
|
+
*/
|
|
116
|
+
getGlobalWeights(): Map<string, Vector>;
|
|
117
|
+
/**
|
|
118
|
+
* Get client statistics
|
|
119
|
+
*/
|
|
120
|
+
getClientStats(): Array<{
|
|
121
|
+
id: string;
|
|
122
|
+
dataCount: number;
|
|
123
|
+
reputation: number;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=federated-learning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"federated-learning.d.ts","sourceRoot":"","sources":["../../../src/plugins/implementations/federated-learning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,MAAM,EACN,OAAO,EACP,UAAU,EACV,YAAY,EACZ,eAAe,EACf,MAAM,EACP,MAAM,8BAA8B,CAAC;AAkBtC;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,UAAU;IACrD,IAAI,SAAwB;IAC5B,OAAO,SAAW;IAElB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,OAAO,CAA2C;IAC1D,OAAO,CAAC,aAAa,CAAkC;IACvD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,mBAAmB,CAAiC;IAG5D,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,YAAY,CAAe;IAGnC,OAAO,CAAC,iBAAiB,CAAe;IACxC,OAAO,CAAC,oBAAoB,CAAkB;gBAElC,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC;IAgBjC;;OAEG;IACH,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAIlC;;OAEG;IACG,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;IAStG;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAS7B;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBrD;;OAEG;IACG,eAAe,CACnB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,GAAE,MAAU,GACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAgC/B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAqBxB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B1D;;OAEG;IACH,OAAO,CAAC,eAAe;IAwBvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAwBxB;;OAEG;IACH,OAAO,CAAC,eAAe;IA0BvB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA2BzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoD9B;;OAEG;YACW,oBAAoB;IAQlC;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBrE;;OAEG;IACH,OAAO,CAAC,OAAO;IAWf;;OAEG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IAyC7D;;OAEG;IACH,gBAAgB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIvC;;OAEG;IACH,cAAc,IAAI,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAO/E"}
|