@openfluke/welvet 0.1.6 → 0.1.8
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 +59 -57
- package/dist/main.wasm +0 -0
- package/dist/types.d.ts +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -201,54 +201,56 @@ for (let step = 0; step < 100000; step++) {
|
|
|
201
201
|
|
|
202
202
|
See `example/step_train_v3.ts` for a complete example achieving 100% accuracy.
|
|
203
203
|
|
|
204
|
+
### 🧠 Neural Tweening API - Gradient-Free Learning
|
|
204
205
|
|
|
205
|
-
|
|
206
|
-
type: "parallel",
|
|
207
|
-
combine_mode: "add",
|
|
208
|
-
branches: [
|
|
209
|
-
{
|
|
210
|
-
type: "dense",
|
|
211
|
-
input_size: 16,
|
|
212
|
-
output_size: 8,
|
|
213
|
-
activation: "relu",
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
type: "dense",
|
|
217
|
-
input_size: 16,
|
|
218
|
-
output_size: 8,
|
|
219
|
-
activation: "gelu",
|
|
220
|
-
},
|
|
221
|
-
],
|
|
222
|
-
},
|
|
223
|
-
{ type: "lstm", input_size: 16, hidden_size: 8, seq_length: 1 },
|
|
224
|
-
{ type: "rnn", input_size: 16, hidden_size: 8, seq_length: 1 },
|
|
225
|
-
],
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
type: "dense",
|
|
229
|
-
input_size: 24,
|
|
230
|
-
output_size: 2,
|
|
231
|
-
activation: "sigmoid",
|
|
232
|
-
},
|
|
233
|
-
],
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// Train multi-agent network
|
|
237
|
-
const batches: TrainingBatch[] = [
|
|
238
|
-
{ Input: [0.2, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8, 0.8], Target: [1.0, 0.0] },
|
|
239
|
-
{ Input: [0.9, 0.9, 0.9, 0.9, 0.1, 0.1, 0.1, 0.1], Target: [0.0, 1.0] },
|
|
240
|
-
];
|
|
206
|
+
**NEW:** Direct weight adjustment without backpropagation:
|
|
241
207
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
LearningRate: 0.15,
|
|
245
|
-
LossType: "mse",
|
|
246
|
-
Verbose: false,
|
|
247
|
-
};
|
|
208
|
+
```typescript
|
|
209
|
+
import { init, createNetwork, TweenState } from "@openfluke/welvet";
|
|
248
210
|
|
|
249
|
-
|
|
211
|
+
await init();
|
|
250
212
|
|
|
251
|
-
|
|
213
|
+
const network = createNetwork(config);
|
|
214
|
+
|
|
215
|
+
// Create tween state (with optional chain rule)
|
|
216
|
+
const tweenState: TweenState = network.createTweenState(true); // useChainRule=true
|
|
217
|
+
|
|
218
|
+
// Training loop - direct weight updates
|
|
219
|
+
for (let step = 0; step < 10000; step++) {
|
|
220
|
+
const input = new Float32Array([0.1, 0.2, 0.3, 0.4]);
|
|
221
|
+
const targetClass = 1; // Target output class
|
|
222
|
+
|
|
223
|
+
// Single-step tween learning
|
|
224
|
+
const loss = tweenState.TweenStep(input, targetClass, 4, 0.02);
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Tweening API:**
|
|
229
|
+
- `network.createTweenState(useChainRule)` - Initialize tween state
|
|
230
|
+
- `tweenState.TweenStep(input, targetClass, outputSize, lr)` - Train step
|
|
231
|
+
- `tweenState.setChainRule(enabled)` - Toggle chain rule
|
|
232
|
+
- `tweenState.getChainRule()` - Get chain rule status
|
|
233
|
+
- `tweenState.getTweenSteps()` - Get total steps performed
|
|
234
|
+
|
|
235
|
+
### 📊 Adaptation Benchmark - Multi-Architecture Testing
|
|
236
|
+
|
|
237
|
+
**NEW:** Run the full Test 18 Multi-Architecture Adaptation Benchmark:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
cd example
|
|
241
|
+
bun run test18_adaptation.ts
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Tests 5 architectures × 3 depths × 5 training modes (75 tests total):
|
|
245
|
+
- **Architectures:** Dense, Conv2D, RNN, LSTM, Attention
|
|
246
|
+
- **Depths:** 3, 5, 9 layers
|
|
247
|
+
- **Modes:** NormalBP, StepBP, Tween, TweenChain, StepTweenChain
|
|
248
|
+
|
|
249
|
+
Measures adaptation speed when tasks change mid-stream (chase→avoid→chase).
|
|
250
|
+
|
|
251
|
+
See `example/test18_adaptation.ts` for the full implementation.
|
|
252
|
+
|
|
253
|
+
```
|
|
252
254
|
|
|
253
255
|
## API Reference
|
|
254
256
|
|
|
@@ -374,9 +376,9 @@ interface TrainingConfig {
|
|
|
374
376
|
}
|
|
375
377
|
```
|
|
376
378
|
|
|
377
|
-
##
|
|
379
|
+
## Examples
|
|
378
380
|
|
|
379
|
-
|
|
381
|
+
### Grid Scatter Multi-Agent
|
|
380
382
|
|
|
381
383
|
```bash
|
|
382
384
|
cd example
|
|
@@ -384,20 +386,20 @@ bun install
|
|
|
384
386
|
bun run grid-scatter.ts
|
|
385
387
|
```
|
|
386
388
|
|
|
387
|
-
|
|
389
|
+
### Stepping Training (LSTM)
|
|
388
390
|
|
|
391
|
+
```bash
|
|
392
|
+
bun run step_train_v3.ts
|
|
389
393
|
```
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
Initial Loss: 0.252249
|
|
396
|
-
Final Loss: 0.001374
|
|
397
|
-
Improvement: 99.46%
|
|
398
|
-
Total Epochs: 800
|
|
394
|
+
|
|
395
|
+
### Adaptation Benchmark (75 tests)
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
bun run test18_adaptation.ts
|
|
399
399
|
```
|
|
400
400
|
|
|
401
|
+
> **Note:** Full benchmark takes ~12.5 minutes (10 seconds per test)
|
|
402
|
+
|
|
401
403
|
## Layer Types
|
|
402
404
|
|
|
403
405
|
- `dense` - Fully connected layer
|
|
@@ -417,7 +419,7 @@ Total Epochs: 800
|
|
|
417
419
|
|
|
418
420
|
## License
|
|
419
421
|
|
|
420
|
-
|
|
422
|
+
APACHE2
|
|
421
423
|
|
|
422
424
|
## Links
|
|
423
425
|
|
package/dist/main.wasm
CHANGED
|
Binary file
|
package/dist/types.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ export interface Network {
|
|
|
100
100
|
ApplyGradientsRMSprop(paramsJSON: string): string;
|
|
101
101
|
ApplyGradientsSGDMomentum(paramsJSON: string): string;
|
|
102
102
|
createStepState(inputSize: number): StepState;
|
|
103
|
+
createTweenState(useChainRule?: boolean): TweenState;
|
|
103
104
|
}
|
|
104
105
|
/**
|
|
105
106
|
* StepState interface for stepping execution
|
|
@@ -110,10 +111,42 @@ export interface StepState {
|
|
|
110
111
|
getOutput(): Float32Array;
|
|
111
112
|
stepBackward(gradients: Float32Array | number[]): Float32Array;
|
|
112
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* TweenState interface for neural tweening execution
|
|
116
|
+
*/
|
|
117
|
+
export interface TweenState {
|
|
118
|
+
/**
|
|
119
|
+
* Perform a tween training step
|
|
120
|
+
* @param input - Input data
|
|
121
|
+
* @param targetClass - Target class index
|
|
122
|
+
* @param outputSize - Size of output layer
|
|
123
|
+
* @param learningRate - Learning rate for this step
|
|
124
|
+
* @returns Loss value
|
|
125
|
+
*/
|
|
126
|
+
TweenStep(input: Float32Array | number[], targetClass: number, outputSize: number, learningRate: number): number;
|
|
127
|
+
/** Enable/disable chain rule mode */
|
|
128
|
+
setChainRule(enabled: boolean): void;
|
|
129
|
+
/** Get current chain rule setting */
|
|
130
|
+
getChainRule(): boolean;
|
|
131
|
+
/** Get number of tween steps performed */
|
|
132
|
+
getTweenSteps(): number;
|
|
133
|
+
}
|
|
113
134
|
/**
|
|
114
135
|
* Global WASM functions exposed by main.go
|
|
115
136
|
* Only createLoomNetwork is exposed - use network.SaveModelToString() for saving
|
|
116
137
|
*/
|
|
117
138
|
declare global {
|
|
118
139
|
function createLoomNetwork(jsonConfig: string): Network;
|
|
140
|
+
function createAdaptationTracker(windowMs: number, totalMs: number): AdaptationTracker;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* AdaptationTracker interface for tracking accuracy during task changes
|
|
144
|
+
*/
|
|
145
|
+
export interface AdaptationTracker {
|
|
146
|
+
setModelInfo(modelName: string, modeName: string): void;
|
|
147
|
+
scheduleTaskChange(atOffsetMs: number, taskID: number, taskName: string): void;
|
|
148
|
+
start(initialTask: string, initialTaskID: number): void;
|
|
149
|
+
recordOutput(isCorrect: boolean): void;
|
|
150
|
+
getCurrentTask(): number;
|
|
151
|
+
finalize(): string;
|
|
119
152
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfluke/welvet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "TypeScript/JavaScript bindings for LOOM neural network framework with WebAssembly support - GPU-accelerated machine learning in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|