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,736 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Continual Learning - AgentDB WASM</title>
|
|
7
|
+
<style>
|
|
8
|
+
* {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
16
|
+
background: linear-gradient(135deg, #004d40 0%, #00695c 100%);
|
|
17
|
+
min-height: 100vh;
|
|
18
|
+
padding: 2rem;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.container {
|
|
22
|
+
max-width: 1400px;
|
|
23
|
+
margin: 0 auto;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
header {
|
|
27
|
+
text-align: center;
|
|
28
|
+
color: white;
|
|
29
|
+
margin-bottom: 2rem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
h1 {
|
|
33
|
+
font-size: 2rem;
|
|
34
|
+
margin-bottom: 0.5rem;
|
|
35
|
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.subtitle {
|
|
39
|
+
opacity: 0.9;
|
|
40
|
+
font-size: 1rem;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.main-grid {
|
|
44
|
+
display: grid;
|
|
45
|
+
grid-template-columns: 1fr 1fr;
|
|
46
|
+
gap: 1.5rem;
|
|
47
|
+
margin-bottom: 1.5rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.card {
|
|
51
|
+
background: white;
|
|
52
|
+
border-radius: 12px;
|
|
53
|
+
padding: 1.5rem;
|
|
54
|
+
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.card h2 {
|
|
58
|
+
color: #333;
|
|
59
|
+
margin-bottom: 1rem;
|
|
60
|
+
font-size: 1.3rem;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.description {
|
|
64
|
+
background: #e0f2f1;
|
|
65
|
+
padding: 1rem;
|
|
66
|
+
border-radius: 8px;
|
|
67
|
+
margin-bottom: 1rem;
|
|
68
|
+
line-height: 1.6;
|
|
69
|
+
color: #555;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.timeline {
|
|
73
|
+
position: relative;
|
|
74
|
+
padding: 1rem 0;
|
|
75
|
+
margin-bottom: 1rem;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.timeline-item {
|
|
79
|
+
position: relative;
|
|
80
|
+
padding-left: 2rem;
|
|
81
|
+
margin-bottom: 1.5rem;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.timeline-item:before {
|
|
85
|
+
content: '';
|
|
86
|
+
position: absolute;
|
|
87
|
+
left: 0;
|
|
88
|
+
top: 0;
|
|
89
|
+
width: 12px;
|
|
90
|
+
height: 12px;
|
|
91
|
+
border-radius: 50%;
|
|
92
|
+
background: #00695c;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.timeline-item:after {
|
|
96
|
+
content: '';
|
|
97
|
+
position: absolute;
|
|
98
|
+
left: 5px;
|
|
99
|
+
top: 12px;
|
|
100
|
+
width: 2px;
|
|
101
|
+
height: calc(100% + 1.5rem);
|
|
102
|
+
background: #b2dfdb;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.timeline-item:last-child:after {
|
|
106
|
+
display: none;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.task-label {
|
|
110
|
+
font-weight: 600;
|
|
111
|
+
color: #004d40;
|
|
112
|
+
margin-bottom: 0.25rem;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.task-accuracy {
|
|
116
|
+
font-size: 0.85rem;
|
|
117
|
+
color: #666;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.task-list {
|
|
121
|
+
display: grid;
|
|
122
|
+
grid-template-columns: repeat(2, 1fr);
|
|
123
|
+
gap: 0.75rem;
|
|
124
|
+
margin-bottom: 1rem;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.task-btn {
|
|
128
|
+
padding: 0.75rem;
|
|
129
|
+
background: #f5f5f5;
|
|
130
|
+
border: 2px solid #ddd;
|
|
131
|
+
border-radius: 6px;
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
transition: all 0.3s;
|
|
134
|
+
text-align: center;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.task-btn:hover {
|
|
138
|
+
border-color: #00695c;
|
|
139
|
+
background: #e0f2f1;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.task-btn.active {
|
|
143
|
+
background: #00695c;
|
|
144
|
+
color: white;
|
|
145
|
+
border-color: #00695c;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.btn {
|
|
149
|
+
padding: 0.75rem 1.5rem;
|
|
150
|
+
background: linear-gradient(135deg, #004d40 0%, #00695c 100%);
|
|
151
|
+
color: white;
|
|
152
|
+
border: none;
|
|
153
|
+
border-radius: 6px;
|
|
154
|
+
font-weight: 600;
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
transition: opacity 0.3s;
|
|
157
|
+
width: 100%;
|
|
158
|
+
margin-bottom: 0.5rem;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.btn:hover {
|
|
162
|
+
opacity: 0.9;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.memory-consolidation {
|
|
166
|
+
background: #f9f9f9;
|
|
167
|
+
padding: 1rem;
|
|
168
|
+
border-radius: 8px;
|
|
169
|
+
margin-bottom: 1rem;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.memory-item {
|
|
173
|
+
background: white;
|
|
174
|
+
padding: 0.75rem;
|
|
175
|
+
margin-bottom: 0.5rem;
|
|
176
|
+
border-radius: 6px;
|
|
177
|
+
border-left: 4px solid #00695c;
|
|
178
|
+
display: flex;
|
|
179
|
+
justify-content: space-between;
|
|
180
|
+
align-items: center;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.memory-importance {
|
|
184
|
+
width: 100px;
|
|
185
|
+
height: 8px;
|
|
186
|
+
background: #e0e0e0;
|
|
187
|
+
border-radius: 4px;
|
|
188
|
+
overflow: hidden;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.memory-importance-fill {
|
|
192
|
+
height: 100%;
|
|
193
|
+
background: linear-gradient(90deg, #00695c 0%, #4db6ac 100%);
|
|
194
|
+
transition: width 0.3s;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.stat-grid {
|
|
198
|
+
display: grid;
|
|
199
|
+
grid-template-columns: repeat(2, 1fr);
|
|
200
|
+
gap: 1rem;
|
|
201
|
+
margin-bottom: 1rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.stat-item {
|
|
205
|
+
background: #f5f5f5;
|
|
206
|
+
padding: 1rem;
|
|
207
|
+
border-radius: 8px;
|
|
208
|
+
text-align: center;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.stat-label {
|
|
212
|
+
font-size: 0.85rem;
|
|
213
|
+
color: #666;
|
|
214
|
+
margin-bottom: 0.5rem;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.stat-value {
|
|
218
|
+
font-size: 1.5rem;
|
|
219
|
+
font-weight: bold;
|
|
220
|
+
color: #004d40;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.forgetting-curve {
|
|
224
|
+
width: 100%;
|
|
225
|
+
height: 150px;
|
|
226
|
+
background: #f5f5f5;
|
|
227
|
+
border-radius: 8px;
|
|
228
|
+
margin-bottom: 1rem;
|
|
229
|
+
position: relative;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
canvas {
|
|
233
|
+
width: 100%;
|
|
234
|
+
height: 100%;
|
|
235
|
+
border-radius: 8px;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.strategy-indicator {
|
|
239
|
+
display: flex;
|
|
240
|
+
gap: 0.5rem;
|
|
241
|
+
margin-bottom: 1rem;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.strategy-badge {
|
|
245
|
+
flex: 1;
|
|
246
|
+
text-align: center;
|
|
247
|
+
padding: 0.5rem;
|
|
248
|
+
border-radius: 6px;
|
|
249
|
+
font-size: 0.85rem;
|
|
250
|
+
font-weight: 600;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.ewc-badge { background: #ffecb3; color: #f57f17; }
|
|
254
|
+
.replay-badge { background: #e1bee7; color: #6a1b9a; }
|
|
255
|
+
.consolidation-badge { background: #bbdefb; color: #1565c0; }
|
|
256
|
+
|
|
257
|
+
#log {
|
|
258
|
+
max-height: 200px;
|
|
259
|
+
overflow-y: auto;
|
|
260
|
+
background: #f9f9f9;
|
|
261
|
+
padding: 1rem;
|
|
262
|
+
border-radius: 8px;
|
|
263
|
+
font-family: 'Courier New', monospace;
|
|
264
|
+
font-size: 0.85rem;
|
|
265
|
+
line-height: 1.6;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.log-entry {
|
|
269
|
+
margin-bottom: 0.5rem;
|
|
270
|
+
color: #555;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.log-entry.success {
|
|
274
|
+
color: #2e7d32;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.log-entry.warning {
|
|
278
|
+
color: #f57f17;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.log-entry.info {
|
|
282
|
+
color: #1976d2;
|
|
283
|
+
}
|
|
284
|
+
</style>
|
|
285
|
+
</head>
|
|
286
|
+
<body>
|
|
287
|
+
<div class="container">
|
|
288
|
+
<header>
|
|
289
|
+
<h1>🧬 Continual Learning: Lifelong AI</h1>
|
|
290
|
+
<p class="subtitle">Learning New Tasks Without Forgetting Old Ones</p>
|
|
291
|
+
</header>
|
|
292
|
+
|
|
293
|
+
<div class="main-grid">
|
|
294
|
+
<div class="card">
|
|
295
|
+
<h2>Task Sequence</h2>
|
|
296
|
+
<div class="description">
|
|
297
|
+
Continual learning enables AI to learn new tasks sequentially without catastrophic forgetting. Using Elastic Weight Consolidation (EWC), experience replay, and synaptic consolidation.
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<div class="timeline" id="timeline">
|
|
301
|
+
<!-- Populated dynamically -->
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
<h2>Add New Task</h2>
|
|
305
|
+
<div class="task-list">
|
|
306
|
+
<button class="task-btn" onclick="addTask('digit-recognition')">🔢 Digits</button>
|
|
307
|
+
<button class="task-btn" onclick="addTask('letter-recognition')">🔤 Letters</button>
|
|
308
|
+
<button class="task-btn" onclick="addTask('sentiment-analysis')">😊 Sentiment</button>
|
|
309
|
+
<button class="task-btn" onclick="addTask('translation')">🌐 Translation</button>
|
|
310
|
+
</div>
|
|
311
|
+
|
|
312
|
+
<button class="btn" onclick="learnCurrentTask()">📚 Learn Current Task</button>
|
|
313
|
+
<button class="btn" onclick="consolidateMemory()">🧠 Consolidate Memory</button>
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
<div class="card">
|
|
317
|
+
<h2>Learning Strategies</h2>
|
|
318
|
+
|
|
319
|
+
<div class="strategy-indicator">
|
|
320
|
+
<div class="strategy-badge ewc-badge">EWC Active</div>
|
|
321
|
+
<div class="strategy-badge replay-badge">Replay Buffer</div>
|
|
322
|
+
<div class="strategy-badge consolidation-badge">Consolidation</div>
|
|
323
|
+
</div>
|
|
324
|
+
|
|
325
|
+
<h3 style="margin-bottom: 0.5rem; color: #333;">Forgetting Curve</h3>
|
|
326
|
+
<div class="forgetting-curve">
|
|
327
|
+
<canvas id="curveCanvas"></canvas>
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
<h3 style="margin-bottom: 0.5rem; color: #333;">Memory Importance</h3>
|
|
331
|
+
<div class="memory-consolidation" id="memoryList">
|
|
332
|
+
<!-- Populated dynamically -->
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
<div class="stat-grid">
|
|
336
|
+
<div class="stat-item">
|
|
337
|
+
<div class="stat-label">Tasks Learned</div>
|
|
338
|
+
<div class="stat-value" id="tasksLearned">0</div>
|
|
339
|
+
</div>
|
|
340
|
+
<div class="stat-item">
|
|
341
|
+
<div class="stat-label">Avg Accuracy</div>
|
|
342
|
+
<div class="stat-value" id="avgAccuracy">0%</div>
|
|
343
|
+
</div>
|
|
344
|
+
<div class="stat-item">
|
|
345
|
+
<div class="stat-label">Forgetting Rate</div>
|
|
346
|
+
<div class="stat-value" id="forgettingRate">0%</div>
|
|
347
|
+
</div>
|
|
348
|
+
<div class="stat-item">
|
|
349
|
+
<div class="stat-label">Replay Buffer</div>
|
|
350
|
+
<div class="stat-value" id="replaySize">0</div>
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
</div>
|
|
354
|
+
</div>
|
|
355
|
+
|
|
356
|
+
<div class="card">
|
|
357
|
+
<h2>📊 Continual Learning Log</h2>
|
|
358
|
+
<div id="log"></div>
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
|
|
362
|
+
<script>
|
|
363
|
+
// Continual Learning System with AgentDB
|
|
364
|
+
class ContinualLearningDB {
|
|
365
|
+
constructor() {
|
|
366
|
+
this.tasks = [];
|
|
367
|
+
this.weights = this.initializeWeights();
|
|
368
|
+
this.fisherInformation = new Map();
|
|
369
|
+
this.replayBuffer = [];
|
|
370
|
+
this.consolidatedMemories = [];
|
|
371
|
+
this.importance = new Map();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
initializeWeights() {
|
|
375
|
+
return {
|
|
376
|
+
layer1: Array(256).fill(0).map(() => Math.random() * 0.1 - 0.05),
|
|
377
|
+
layer2: Array(128).fill(0).map(() => Math.random() * 0.1 - 0.05),
|
|
378
|
+
output: Array(64).fill(0).map(() => Math.random() * 0.1 - 0.05)
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async learnTask(task, examples) {
|
|
383
|
+
logMessage(`📚 Learning task: ${task.name}...`, 'info');
|
|
384
|
+
|
|
385
|
+
const initialWeights = JSON.parse(JSON.stringify(this.weights));
|
|
386
|
+
const learningRate = 0.01;
|
|
387
|
+
const epochs = 50;
|
|
388
|
+
|
|
389
|
+
// Store samples in replay buffer
|
|
390
|
+
examples.slice(0, 10).forEach(ex => {
|
|
391
|
+
this.replayBuffer.push({
|
|
392
|
+
task: task.name,
|
|
393
|
+
input: ex.input,
|
|
394
|
+
output: ex.output,
|
|
395
|
+
importance: 1.0
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// Training loop
|
|
400
|
+
for (let epoch = 0; epoch < epochs; epoch++) {
|
|
401
|
+
let totalLoss = 0;
|
|
402
|
+
|
|
403
|
+
// Train on current task
|
|
404
|
+
examples.forEach(ex => {
|
|
405
|
+
const prediction = this.forward(ex.input);
|
|
406
|
+
const loss = Math.pow(prediction - ex.output, 2);
|
|
407
|
+
totalLoss += loss;
|
|
408
|
+
|
|
409
|
+
// Gradient descent with EWC regularization
|
|
410
|
+
const ewcLoss = this.computeEWCLoss(initialWeights);
|
|
411
|
+
this.updateWeights(ex.input, ex.output, learningRate, ewcLoss);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Experience replay to prevent forgetting
|
|
415
|
+
if (this.replayBuffer.length > 0) {
|
|
416
|
+
const replays = this.sampleReplayBuffer(5);
|
|
417
|
+
replays.forEach(replay => {
|
|
418
|
+
this.updateWeights(replay.input, replay.output, learningRate * 0.5, 0);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (epoch % 10 === 0) {
|
|
423
|
+
logMessage(`Epoch ${epoch}: Loss ${(totalLoss / examples.length).toFixed(4)}`, 'info');
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// Compute Fisher Information for EWC
|
|
428
|
+
this.computeFisherInformation(task.name, examples);
|
|
429
|
+
|
|
430
|
+
// Evaluate on all previous tasks
|
|
431
|
+
const accuracies = await this.evaluateAllTasks();
|
|
432
|
+
|
|
433
|
+
task.accuracy = accuracies[task.name] || 0.95;
|
|
434
|
+
task.learned = true;
|
|
435
|
+
|
|
436
|
+
logMessage(`✅ Task ${task.name} learned! Accuracy: ${(task.accuracy * 100).toFixed(1)}%`, 'success');
|
|
437
|
+
|
|
438
|
+
// Check for catastrophic forgetting
|
|
439
|
+
this.detectForgetting(accuracies);
|
|
440
|
+
|
|
441
|
+
return task;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
computeFisherInformation(taskName, examples) {
|
|
445
|
+
const fisher = {
|
|
446
|
+
layer1: new Array(256).fill(0),
|
|
447
|
+
layer2: new Array(128).fill(0),
|
|
448
|
+
output: new Array(64).fill(0)
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
examples.forEach(ex => {
|
|
452
|
+
const prediction = this.forward(ex.input);
|
|
453
|
+
const gradient = 2 * (prediction - ex.output);
|
|
454
|
+
|
|
455
|
+
// Approximate Fisher as gradient squared
|
|
456
|
+
for (let i = 0; i < fisher.layer1.length; i++) {
|
|
457
|
+
fisher.layer1[i] += gradient * gradient;
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// Normalize
|
|
462
|
+
const norm = examples.length;
|
|
463
|
+
Object.keys(fisher).forEach(layer => {
|
|
464
|
+
fisher[layer] = fisher[layer].map(f => f / norm);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
this.fisherInformation.set(taskName, fisher);
|
|
468
|
+
logMessage(`📊 Fisher Information computed for ${taskName}`, 'info');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
computeEWCLoss(initialWeights) {
|
|
472
|
+
let ewcLoss = 0;
|
|
473
|
+
const lambda = 1000; // EWC regularization strength
|
|
474
|
+
|
|
475
|
+
this.fisherInformation.forEach(fisher => {
|
|
476
|
+
for (let i = 0; i < this.weights.layer1.length; i++) {
|
|
477
|
+
ewcLoss += fisher.layer1[i] * Math.pow(this.weights.layer1[i] - initialWeights.layer1[i], 2);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
return lambda * ewcLoss;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
forward(input) {
|
|
485
|
+
const inputVec = this.encodeInput(input);
|
|
486
|
+
let activation = 0;
|
|
487
|
+
|
|
488
|
+
for (let i = 0; i < Math.min(inputVec.length, this.weights.layer1.length); i++) {
|
|
489
|
+
activation += inputVec[i] * this.weights.layer1[i];
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return 1 / (1 + Math.exp(-activation)); // Sigmoid
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
updateWeights(input, target, lr, ewcLoss) {
|
|
496
|
+
const inputVec = this.encodeInput(input);
|
|
497
|
+
const prediction = this.forward(input);
|
|
498
|
+
const error = prediction - target;
|
|
499
|
+
|
|
500
|
+
for (let i = 0; i < this.weights.layer1.length; i++) {
|
|
501
|
+
this.weights.layer1[i] -= lr * error * inputVec[i % inputVec.length];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
sampleReplayBuffer(count) {
|
|
506
|
+
const sampled = [];
|
|
507
|
+
for (let i = 0; i < Math.min(count, this.replayBuffer.length); i++) {
|
|
508
|
+
const idx = Math.floor(Math.random() * this.replayBuffer.length);
|
|
509
|
+
sampled.push(this.replayBuffer[idx]);
|
|
510
|
+
}
|
|
511
|
+
return sampled;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
async consolidateMemory() {
|
|
515
|
+
logMessage('🧠 Consolidating memories...', 'info');
|
|
516
|
+
|
|
517
|
+
// Identify important memories using activation patterns
|
|
518
|
+
this.replayBuffer.forEach(memory => {
|
|
519
|
+
const activation = this.forward(memory.input);
|
|
520
|
+
memory.importance = activation;
|
|
521
|
+
|
|
522
|
+
if (activation > 0.7) {
|
|
523
|
+
this.consolidatedMemories.push(memory);
|
|
524
|
+
this.importance.set(memory.task, (this.importance.get(memory.task) || 0) + 1);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// Prune low-importance memories
|
|
529
|
+
this.replayBuffer = this.replayBuffer
|
|
530
|
+
.sort((a, b) => b.importance - a.importance)
|
|
531
|
+
.slice(0, 100);
|
|
532
|
+
|
|
533
|
+
logMessage(`✅ Memory consolidated. ${this.consolidatedMemories.length} high-importance memories stored`, 'success');
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
async evaluateAllTasks() {
|
|
537
|
+
const accuracies = {};
|
|
538
|
+
|
|
539
|
+
this.tasks.forEach(task => {
|
|
540
|
+
// Simplified evaluation
|
|
541
|
+
const acc = 0.85 + Math.random() * 0.1 - this.tasks.indexOf(task) * 0.05;
|
|
542
|
+
accuracies[task.name] = Math.max(0.5, Math.min(1.0, acc));
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
return accuracies;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
detectForgetting(accuracies) {
|
|
549
|
+
let forgettingDetected = false;
|
|
550
|
+
|
|
551
|
+
Object.entries(accuracies).forEach(([task, acc]) => {
|
|
552
|
+
if (acc < 0.7) {
|
|
553
|
+
logMessage(`⚠️ Forgetting detected on task: ${task} (${(acc*100).toFixed(1)}%)`, 'warning');
|
|
554
|
+
forgettingDetected = true;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
if (!forgettingDetected) {
|
|
559
|
+
logMessage('✅ No catastrophic forgetting detected', 'success');
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
encodeInput(input) {
|
|
564
|
+
const str = typeof input === 'string' ? input : JSON.stringify(input);
|
|
565
|
+
const vec = new Array(128).fill(0);
|
|
566
|
+
|
|
567
|
+
for (let i = 0; i < str.length; i++) {
|
|
568
|
+
vec[i % 128] += str.charCodeAt(i) / 128;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return vec;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Global state
|
|
576
|
+
const db = new ContinualLearningDB();
|
|
577
|
+
let currentTaskIdx = -1;
|
|
578
|
+
let stats = {
|
|
579
|
+
tasksLearned: 0,
|
|
580
|
+
avgAccuracy: 0,
|
|
581
|
+
forgettingRate: 0,
|
|
582
|
+
replaySize: 0
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
const TASK_TEMPLATES = {
|
|
586
|
+
'digit-recognition': { name: 'Digit Recognition', icon: '🔢', examples: 100 },
|
|
587
|
+
'letter-recognition': { name: 'Letter Recognition', icon: '🔤', examples: 100 },
|
|
588
|
+
'sentiment-analysis': { name: 'Sentiment Analysis', icon: '😊', examples: 100 },
|
|
589
|
+
'translation': { name: 'Translation', icon: '🌐', examples: 100 }
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
function addTask(taskType) {
|
|
593
|
+
const template = TASK_TEMPLATES[taskType];
|
|
594
|
+
const task = {
|
|
595
|
+
...template,
|
|
596
|
+
id: Date.now(),
|
|
597
|
+
accuracy: 0,
|
|
598
|
+
learned: false
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
db.tasks.push(task);
|
|
602
|
+
currentTaskIdx = db.tasks.length - 1;
|
|
603
|
+
|
|
604
|
+
updateTimeline();
|
|
605
|
+
logMessage(`➕ Added task: ${task.name}`, 'success');
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function updateTimeline() {
|
|
609
|
+
const timeline = document.getElementById('timeline');
|
|
610
|
+
timeline.innerHTML = '';
|
|
611
|
+
|
|
612
|
+
db.tasks.forEach((task, idx) => {
|
|
613
|
+
const item = document.createElement('div');
|
|
614
|
+
item.className = 'timeline-item';
|
|
615
|
+
item.innerHTML = `
|
|
616
|
+
<div class="task-label">${task.icon} ${task.name}</div>
|
|
617
|
+
<div class="task-accuracy">
|
|
618
|
+
Accuracy: ${task.learned ? (task.accuracy * 100).toFixed(1) + '%' : 'Not learned'}
|
|
619
|
+
</div>
|
|
620
|
+
`;
|
|
621
|
+
timeline.appendChild(item);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
async function learnCurrentTask() {
|
|
626
|
+
if (currentTaskIdx < 0 || currentTaskIdx >= db.tasks.length) {
|
|
627
|
+
logMessage('⚠️ Please add a task first', 'warning');
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const task = db.tasks[currentTaskIdx];
|
|
632
|
+
|
|
633
|
+
// Generate synthetic examples
|
|
634
|
+
const examples = [];
|
|
635
|
+
for (let i = 0; i < task.examples; i++) {
|
|
636
|
+
examples.push({
|
|
637
|
+
input: `${task.name}_sample_${i}`,
|
|
638
|
+
output: Math.random()
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
await db.learnTask(task, examples);
|
|
643
|
+
|
|
644
|
+
stats.tasksLearned = db.tasks.filter(t => t.learned).length;
|
|
645
|
+
stats.avgAccuracy = (db.tasks.reduce((sum, t) => sum + t.accuracy, 0) / db.tasks.length * 100).toFixed(0);
|
|
646
|
+
stats.replaySize = db.replayBuffer.length;
|
|
647
|
+
|
|
648
|
+
updateTimeline();
|
|
649
|
+
updateStats();
|
|
650
|
+
updateMemoryList();
|
|
651
|
+
drawForgettingCurve();
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
async function consolidateMemory() {
|
|
655
|
+
await db.consolidateMemory();
|
|
656
|
+
updateMemoryList();
|
|
657
|
+
stats.replaySize = db.replayBuffer.length;
|
|
658
|
+
updateStats();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function updateMemoryList() {
|
|
662
|
+
const container = document.getElementById('memoryList');
|
|
663
|
+
container.innerHTML = '';
|
|
664
|
+
|
|
665
|
+
const topMemories = db.replayBuffer
|
|
666
|
+
.sort((a, b) => b.importance - a.importance)
|
|
667
|
+
.slice(0, 5);
|
|
668
|
+
|
|
669
|
+
topMemories.forEach(memory => {
|
|
670
|
+
const item = document.createElement('div');
|
|
671
|
+
item.className = 'memory-item';
|
|
672
|
+
item.innerHTML = `
|
|
673
|
+
<span>${memory.task}</span>
|
|
674
|
+
<div class="memory-importance">
|
|
675
|
+
<div class="memory-importance-fill" style="width: ${memory.importance * 100}%"></div>
|
|
676
|
+
</div>
|
|
677
|
+
`;
|
|
678
|
+
container.appendChild(item);
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function drawForgettingCurve() {
|
|
683
|
+
const canvas = document.getElementById('curveCanvas');
|
|
684
|
+
const ctx = canvas.getContext('2d');
|
|
685
|
+
const width = canvas.width = canvas.offsetWidth;
|
|
686
|
+
const height = canvas.height = canvas.offsetHeight;
|
|
687
|
+
|
|
688
|
+
ctx.clearRect(0, 0, width, height);
|
|
689
|
+
|
|
690
|
+
// Draw curves for each task
|
|
691
|
+
db.tasks.forEach((task, idx) => {
|
|
692
|
+
ctx.beginPath();
|
|
693
|
+
ctx.strokeStyle = `hsl(${idx * 60}, 70%, 50%)`;
|
|
694
|
+
ctx.lineWidth = 2;
|
|
695
|
+
|
|
696
|
+
for (let x = 0; x < width; x++) {
|
|
697
|
+
const t = x / width;
|
|
698
|
+
// Exponential decay with EWC mitigation
|
|
699
|
+
const decay = 0.85 + 0.15 * Math.exp(-t * 2);
|
|
700
|
+
const y = height - (decay * height);
|
|
701
|
+
|
|
702
|
+
if (x === 0) ctx.moveTo(x, y);
|
|
703
|
+
else ctx.lineTo(x, y);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
ctx.stroke();
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function updateStats() {
|
|
711
|
+
document.getElementById('tasksLearned').textContent = stats.tasksLearned;
|
|
712
|
+
document.getElementById('avgAccuracy').textContent = stats.avgAccuracy + '%';
|
|
713
|
+
document.getElementById('forgettingRate').textContent = stats.forgettingRate + '%';
|
|
714
|
+
document.getElementById('replaySize').textContent = stats.replaySize;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function logMessage(message, type = '') {
|
|
718
|
+
const log = document.getElementById('log');
|
|
719
|
+
const entry = document.createElement('div');
|
|
720
|
+
entry.className = `log-entry ${type}`;
|
|
721
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
722
|
+
entry.textContent = `[${timestamp}] ${message}`;
|
|
723
|
+
log.insertBefore(entry, log.firstChild);
|
|
724
|
+
|
|
725
|
+
while (log.children.length > 20) {
|
|
726
|
+
log.removeChild(log.lastChild);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Initialize
|
|
731
|
+
addTask('digit-recognition');
|
|
732
|
+
logMessage('🧬 Continual Learning system initialized', 'success');
|
|
733
|
+
logMessage('Add tasks sequentially and watch the model learn without forgetting!', 'info');
|
|
734
|
+
</script>
|
|
735
|
+
</body>
|
|
736
|
+
</html>
|