@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,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Neural Model Class
|
|
3
|
+
* Abstract base class for all neural network models
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class NeuralModel {
|
|
7
|
+
constructor(modelType) {
|
|
8
|
+
this.modelType = modelType;
|
|
9
|
+
this.isInitialized = false;
|
|
10
|
+
this.trainingHistory = [];
|
|
11
|
+
this.metrics = {
|
|
12
|
+
accuracy: 0,
|
|
13
|
+
loss: 1.0,
|
|
14
|
+
epochsTrained: 0,
|
|
15
|
+
totalSamples: 0,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Abstract methods to be implemented by subclasses
|
|
20
|
+
async forward(input, _training = false) {
|
|
21
|
+
throw new Error('forward() must be implemented by subclass');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async train(trainingData, _options = {}) {
|
|
25
|
+
throw new Error('train() must be implemented by subclass');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async backward(loss, _learningRate) {
|
|
29
|
+
// Default backward pass - can be overridden
|
|
30
|
+
console.log(`Backward pass for ${this.modelType} with loss: ${loss}`);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async validate(validationData) {
|
|
35
|
+
let totalLoss = 0;
|
|
36
|
+
let batchCount = 0;
|
|
37
|
+
|
|
38
|
+
for (const batch of validationData) {
|
|
39
|
+
const predictions = await this.forward(batch.inputs, false);
|
|
40
|
+
const loss = this.crossEntropyLoss(predictions, batch.targets);
|
|
41
|
+
totalLoss += loss;
|
|
42
|
+
batchCount++;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return totalLoss / batchCount;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Common utility methods
|
|
49
|
+
matmul(a, b) {
|
|
50
|
+
// Matrix multiplication helper
|
|
51
|
+
// Assumes a is [m, n] and b is [n, p]
|
|
52
|
+
if (!a.shape || !b.shape || a.shape.length < 2 || b.shape.length < 2) {
|
|
53
|
+
throw new Error('Invalid matrix dimensions for multiplication');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const m = a.shape[0];
|
|
57
|
+
const n = a.shape[1];
|
|
58
|
+
const p = b.shape[b.shape.length - 1];
|
|
59
|
+
|
|
60
|
+
const result = new Float32Array(m * p);
|
|
61
|
+
|
|
62
|
+
for (let i = 0; i < m; i++) {
|
|
63
|
+
for (let j = 0; j < p; j++) {
|
|
64
|
+
let sum = 0;
|
|
65
|
+
for (let k = 0; k < n; k++) {
|
|
66
|
+
sum += a[i * n + k] * b[k * p + j];
|
|
67
|
+
}
|
|
68
|
+
result[i * p + j] = sum;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
result.shape = [m, p];
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
add(a, b) {
|
|
77
|
+
// Element-wise addition
|
|
78
|
+
if (a.length !== b.length) {
|
|
79
|
+
throw new Error('Tensors must have same length for addition');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const result = new Float32Array(a.length);
|
|
83
|
+
for (let i = 0; i < a.length; i++) {
|
|
84
|
+
result[i] = a[i] + b[i];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
result.shape = a.shape;
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
addBias(input, bias) {
|
|
92
|
+
// Add bias to last dimension
|
|
93
|
+
const result = new Float32Array(input.length);
|
|
94
|
+
const lastDim = bias.length;
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < input.length; i++) {
|
|
97
|
+
result[i] = input[i] + bias[i % lastDim];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
result.shape = input.shape;
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
relu(input) {
|
|
105
|
+
// ReLU activation
|
|
106
|
+
const result = new Float32Array(input.length);
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < input.length; i++) {
|
|
109
|
+
result[i] = Math.max(0, input[i]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
result.shape = input.shape;
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
sigmoid(input) {
|
|
117
|
+
// Sigmoid activation
|
|
118
|
+
const result = new Float32Array(input.length);
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < input.length; i++) {
|
|
121
|
+
result[i] = 1 / (1 + Math.exp(-input[i]));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
result.shape = input.shape;
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
tanh(input) {
|
|
129
|
+
// Tanh activation
|
|
130
|
+
const result = new Float32Array(input.length);
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < input.length; i++) {
|
|
133
|
+
result[i] = Math.tanh(input[i]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
result.shape = input.shape;
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
dropout(input, rate) {
|
|
141
|
+
// Apply dropout during training
|
|
142
|
+
if (rate <= 0) {
|
|
143
|
+
return input;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const result = new Float32Array(input.length);
|
|
147
|
+
const scale = 1 / (1 - rate);
|
|
148
|
+
|
|
149
|
+
for (let i = 0; i < input.length; i++) {
|
|
150
|
+
if (Math.random() > rate) {
|
|
151
|
+
result[i] = input[i] * scale;
|
|
152
|
+
} else {
|
|
153
|
+
result[i] = 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
result.shape = input.shape;
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
crossEntropyLoss(predictions, targets) {
|
|
162
|
+
// Cross-entropy loss for classification
|
|
163
|
+
let loss = 0;
|
|
164
|
+
const epsilon = 1e-7; // For numerical stability
|
|
165
|
+
|
|
166
|
+
for (let i = 0; i < predictions.length; i++) {
|
|
167
|
+
const pred = Math.max(epsilon, Math.min(1 - epsilon, predictions[i]));
|
|
168
|
+
if (targets[i] === 1) {
|
|
169
|
+
loss -= Math.log(pred);
|
|
170
|
+
} else {
|
|
171
|
+
loss -= Math.log(1 - pred);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return loss / predictions.length;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
meanSquaredError(predictions, targets) {
|
|
179
|
+
// MSE loss for regression
|
|
180
|
+
let loss = 0;
|
|
181
|
+
|
|
182
|
+
for (let i = 0; i < predictions.length; i++) {
|
|
183
|
+
const diff = predictions[i] - targets[i];
|
|
184
|
+
loss += diff * diff;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return loss / predictions.length;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
shuffle(array) {
|
|
191
|
+
// Fisher-Yates shuffle
|
|
192
|
+
const shuffled = [...array];
|
|
193
|
+
|
|
194
|
+
for (let i = shuffled.length - 1; i > 0; i--) {
|
|
195
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
196
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return shuffled;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Model persistence methods
|
|
203
|
+
async save(filePath) {
|
|
204
|
+
const modelData = {
|
|
205
|
+
modelType: this.modelType,
|
|
206
|
+
config: this.getConfig(),
|
|
207
|
+
weights: this.getWeights(),
|
|
208
|
+
metrics: this.metrics,
|
|
209
|
+
trainingHistory: this.trainingHistory,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// In a real implementation, save to file
|
|
213
|
+
console.log(`Saving ${this.modelType} model to ${filePath}`);
|
|
214
|
+
return modelData;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async load(filePath) {
|
|
218
|
+
// In a real implementation, load from file
|
|
219
|
+
console.log(`Loading ${this.modelType} model from ${filePath}`);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
getWeights() {
|
|
224
|
+
// To be overridden by subclasses
|
|
225
|
+
return {};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
setWeights(_weights) {
|
|
229
|
+
// To be overridden by subclasses
|
|
230
|
+
console.log(`Setting weights for ${this.modelType}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
getConfig() {
|
|
234
|
+
// To be overridden by subclasses
|
|
235
|
+
return {
|
|
236
|
+
modelType: this.modelType,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
getMetrics() {
|
|
241
|
+
return {
|
|
242
|
+
...this.metrics,
|
|
243
|
+
modelType: this.modelType,
|
|
244
|
+
trainingHistory: this.trainingHistory,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
updateMetrics(loss, accuracy = null) {
|
|
249
|
+
this.metrics.loss = loss;
|
|
250
|
+
if (accuracy !== null) {
|
|
251
|
+
this.metrics.accuracy = accuracy;
|
|
252
|
+
}
|
|
253
|
+
this.metrics.epochsTrained++;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
reset() {
|
|
257
|
+
// Reset model to initial state
|
|
258
|
+
this.trainingHistory = [];
|
|
259
|
+
this.metrics = {
|
|
260
|
+
accuracy: 0,
|
|
261
|
+
loss: 1.0,
|
|
262
|
+
epochsTrained: 0,
|
|
263
|
+
totalSamples: 0,
|
|
264
|
+
};
|
|
265
|
+
this.initializeWeights();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { NeuralModel };
|