@aleph-ai/tinyaleph 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 +21 -0
- package/README.md +278 -0
- package/backends/cryptographic/index.js +196 -0
- package/backends/index.js +15 -0
- package/backends/interface.js +89 -0
- package/backends/scientific/index.js +272 -0
- package/backends/semantic/index.js +527 -0
- package/backends/semantic/surface.js +393 -0
- package/backends/semantic/two-layer.js +375 -0
- package/core/fano.js +127 -0
- package/core/hilbert.js +564 -0
- package/core/hypercomplex.js +141 -0
- package/core/index.js +133 -0
- package/core/llm.js +132 -0
- package/core/prime.js +184 -0
- package/core/resonance.js +695 -0
- package/core/rformer-tf.js +1086 -0
- package/core/rformer.js +806 -0
- package/core/sieve.js +350 -0
- package/data.json +8163 -0
- package/docs/EXAMPLES_PLAN.md +293 -0
- package/docs/README.md +159 -0
- package/docs/design/ALEPH_CHAT_ARCHITECTURE.md +499 -0
- package/docs/guide/01-quickstart.md +298 -0
- package/docs/guide/02-semantic-computing.md +409 -0
- package/docs/guide/03-cryptographic.md +420 -0
- package/docs/guide/04-scientific.md +494 -0
- package/docs/guide/05-llm-integration.md +568 -0
- package/docs/guide/06-advanced.md +996 -0
- package/docs/guide/README.md +188 -0
- package/docs/reference/01-core.md +695 -0
- package/docs/reference/02-physics.md +601 -0
- package/docs/reference/03-backends.md +892 -0
- package/docs/reference/04-engine.md +632 -0
- package/docs/reference/README.md +252 -0
- package/docs/theory/01-prime-semantics.md +327 -0
- package/docs/theory/02-hypercomplex-algebra.md +421 -0
- package/docs/theory/03-phase-synchronization.md +364 -0
- package/docs/theory/04-entropy-reasoning.md +348 -0
- package/docs/theory/05-non-commutativity.md +402 -0
- package/docs/theory/06-two-layer-meaning.md +414 -0
- package/docs/theory/07-resonant-field-interface.md +419 -0
- package/docs/theory/08-semantic-sieve.md +520 -0
- package/docs/theory/09-temporal-emergence.md +298 -0
- package/docs/theory/10-quaternionic-memory.md +415 -0
- package/docs/theory/README.md +162 -0
- package/engine/aleph.js +418 -0
- package/engine/index.js +7 -0
- package/index.js +23 -0
- package/modular.js +254 -0
- package/package.json +99 -0
- package/physics/collapse.js +95 -0
- package/physics/entropy.js +88 -0
- package/physics/index.js +65 -0
- package/physics/kuramoto.js +91 -0
- package/physics/lyapunov.js +80 -0
- package/physics/oscillator.js +95 -0
- package/types/index.d.ts +575 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
# Engine Module Reference
|
|
2
|
+
|
|
3
|
+
The engine module provides high-level orchestration for Aleph computations.
|
|
4
|
+
|
|
5
|
+
## AlephEngine (`engine/aleph.js`)
|
|
6
|
+
|
|
7
|
+
The unified computation engine that coordinates backends, oscillators, and transforms.
|
|
8
|
+
|
|
9
|
+
### Constructor
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
new AlephEngine(backend, config)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Parameters:**
|
|
16
|
+
- `backend` (BackendInterface): Backend instance
|
|
17
|
+
- `config` (Object):
|
|
18
|
+
- `oscillatorCount` (number): Number of oscillators (default 16)
|
|
19
|
+
- `coupling` (number): Kuramoto coupling strength (default 0.1)
|
|
20
|
+
- `entropyThreshold` (number): Target entropy (default 0.1)
|
|
21
|
+
- `maxIterations` (number): Max transform iterations (default 100)
|
|
22
|
+
- `collapseStrength` (number): State collapse strength (default 0.8)
|
|
23
|
+
- `dt` (number): Time step for dynamics (default 0.01)
|
|
24
|
+
|
|
25
|
+
**Example:**
|
|
26
|
+
```javascript
|
|
27
|
+
const { AlephEngine, SemanticBackend } = require('./modular');
|
|
28
|
+
|
|
29
|
+
const backend = new SemanticBackend(config);
|
|
30
|
+
const engine = new AlephEngine(backend, {
|
|
31
|
+
oscillatorCount: 16,
|
|
32
|
+
coupling: 0.2,
|
|
33
|
+
entropyThreshold: 0.05
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
### Properties
|
|
40
|
+
|
|
41
|
+
| Property | Type | Description |
|
|
42
|
+
|----------|------|-------------|
|
|
43
|
+
| `backend` | BackendInterface | Associated backend |
|
|
44
|
+
| `oscillators` | Array<Oscillator> | Field oscillator array |
|
|
45
|
+
| `field` | SedenionState | Current field state |
|
|
46
|
+
| `config` | Object | Engine configuration |
|
|
47
|
+
| `metrics` | Object | Performance metrics |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### Core Methods
|
|
52
|
+
|
|
53
|
+
#### run(input)
|
|
54
|
+
|
|
55
|
+
Execute full computation pipeline.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
engine.run(input)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Parameters:**
|
|
62
|
+
- `input` (any): Backend-specific input
|
|
63
|
+
|
|
64
|
+
**Returns:** EngineResult
|
|
65
|
+
```javascript
|
|
66
|
+
{
|
|
67
|
+
input: any, // Original input
|
|
68
|
+
output: any, // Decoded output
|
|
69
|
+
primes: number[], // Final prime encoding
|
|
70
|
+
state: SedenionState, // Final hypercomplex state
|
|
71
|
+
entropy: number, // Final entropy
|
|
72
|
+
steps: TransformStep[], // Applied transforms
|
|
73
|
+
oscillators: { // Oscillator final state
|
|
74
|
+
orderParameter: number,
|
|
75
|
+
phases: number[]
|
|
76
|
+
},
|
|
77
|
+
metrics: { // Performance data
|
|
78
|
+
totalTime: number,
|
|
79
|
+
encodeTime: number,
|
|
80
|
+
transformTime: number,
|
|
81
|
+
decodeTime: number
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Example:**
|
|
87
|
+
```javascript
|
|
88
|
+
const result = engine.run('What is wisdom?');
|
|
89
|
+
console.log('Answer:', result.output);
|
|
90
|
+
console.log('Final entropy:', result.entropy);
|
|
91
|
+
console.log('Steps taken:', result.steps.length);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
#### runBatch(inputs)
|
|
97
|
+
|
|
98
|
+
Process multiple inputs in sequence.
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
engine.runBatch(inputs)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Parameters:**
|
|
105
|
+
- `inputs` (Array): Array of inputs
|
|
106
|
+
|
|
107
|
+
**Returns:** Array<EngineResult>
|
|
108
|
+
|
|
109
|
+
**Notes:**
|
|
110
|
+
- Oscillators carry state between items
|
|
111
|
+
- Can show emergence of patterns across batch
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
#### step(state)
|
|
116
|
+
|
|
117
|
+
Perform single computation step.
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
engine.step(state)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Parameters:**
|
|
124
|
+
- `state` (SedenionState): Current state
|
|
125
|
+
|
|
126
|
+
**Returns:** Object - `{ state, entropy, transform }`
|
|
127
|
+
|
|
128
|
+
**Notes:**
|
|
129
|
+
- Applies best available transform
|
|
130
|
+
- Updates oscillator phases
|
|
131
|
+
- Returns new state
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### Field Operations
|
|
136
|
+
|
|
137
|
+
#### initializeField(primes)
|
|
138
|
+
|
|
139
|
+
Initialize field from prime encoding.
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
engine.initializeField(primes)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Parameters:**
|
|
146
|
+
- `primes` (Array<number>): Prime encoding
|
|
147
|
+
|
|
148
|
+
**Returns:** void
|
|
149
|
+
|
|
150
|
+
**Notes:**
|
|
151
|
+
- Converts primes to hypercomplex state
|
|
152
|
+
- Excites oscillators based on prime distribution
|
|
153
|
+
- Sets initial field state
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
#### exciteField(primes)
|
|
158
|
+
|
|
159
|
+
Add excitation to existing field.
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
engine.exciteField(primes)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
- `primes` (Array<number>): Additional primes
|
|
167
|
+
|
|
168
|
+
**Returns:** void
|
|
169
|
+
|
|
170
|
+
**Notes:**
|
|
171
|
+
- Adds to current field state
|
|
172
|
+
- Increases oscillator energy
|
|
173
|
+
- Does not reset existing state
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
#### collapseField(target)
|
|
178
|
+
|
|
179
|
+
Collapse field toward target state.
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
engine.collapseField(target)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Parameters:**
|
|
186
|
+
- `target` (SedenionState): Target attractor
|
|
187
|
+
|
|
188
|
+
**Returns:** SedenionState - Collapsed field state
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
#### getFieldState()
|
|
193
|
+
|
|
194
|
+
Get current field state.
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
engine.getFieldState()
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Returns:** SedenionState
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
#### getFieldEntropy()
|
|
205
|
+
|
|
206
|
+
Get current field entropy.
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
engine.getFieldEntropy()
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Returns:** number
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### Oscillator Control
|
|
217
|
+
|
|
218
|
+
#### stepOscillators()
|
|
219
|
+
|
|
220
|
+
Advance oscillator dynamics by one time step.
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
engine.stepOscillators()
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Returns:** void
|
|
227
|
+
|
|
228
|
+
**Notes:**
|
|
229
|
+
- Applies Kuramoto coupling
|
|
230
|
+
- Updates all oscillator phases
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
#### synchronizeOscillators(target)
|
|
235
|
+
|
|
236
|
+
Force synchronization toward target phase.
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
engine.synchronizeOscillators(target)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Parameters:**
|
|
243
|
+
- `target` (number): Target phase in radians
|
|
244
|
+
|
|
245
|
+
**Returns:** void
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
#### getOrderParameter()
|
|
250
|
+
|
|
251
|
+
Get Kuramoto order parameter.
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
engine.getOrderParameter()
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Returns:** number - Synchronization measure [0, 1]
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
#### exciteOscillator(index, energy)
|
|
262
|
+
|
|
263
|
+
Add energy to specific oscillator.
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
engine.exciteOscillator(index, energy)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Parameters:**
|
|
270
|
+
- `index` (number): Oscillator index (0-15)
|
|
271
|
+
- `energy` (number): Energy to add
|
|
272
|
+
|
|
273
|
+
**Returns:** void
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
### Transform Management
|
|
278
|
+
|
|
279
|
+
#### selectTransform(primes, state)
|
|
280
|
+
|
|
281
|
+
Choose best transform to apply.
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
engine.selectTransform(primes, state)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Parameters:**
|
|
288
|
+
- `primes` (Array<number>): Current primes
|
|
289
|
+
- `state` (SedenionState): Current state
|
|
290
|
+
|
|
291
|
+
**Returns:** Transform | null
|
|
292
|
+
|
|
293
|
+
**Notes:**
|
|
294
|
+
- Selection based on entropy reduction potential
|
|
295
|
+
- Considers transform priorities and conditions
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
#### applyTransform(primes, transform)
|
|
300
|
+
|
|
301
|
+
Apply a transform to primes.
|
|
302
|
+
|
|
303
|
+
```javascript
|
|
304
|
+
engine.applyTransform(primes, transform)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**Parameters:**
|
|
308
|
+
- `primes` (Array<number>): Current primes
|
|
309
|
+
- `transform` (Transform): Transform to apply
|
|
310
|
+
|
|
311
|
+
**Returns:** Array<number> - Transformed primes
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
#### addTransform(transform)
|
|
316
|
+
|
|
317
|
+
Add transform to engine.
|
|
318
|
+
|
|
319
|
+
```javascript
|
|
320
|
+
engine.addTransform(transform)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Parameters:**
|
|
324
|
+
- `transform` (Transform): New transform
|
|
325
|
+
|
|
326
|
+
**Returns:** void
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
#### removeTransform(name)
|
|
331
|
+
|
|
332
|
+
Remove transform by name.
|
|
333
|
+
|
|
334
|
+
```javascript
|
|
335
|
+
engine.removeTransform(name)
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Parameters:**
|
|
339
|
+
- `name` (string): Transform name
|
|
340
|
+
|
|
341
|
+
**Returns:** boolean - True if removed
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### Metrics
|
|
346
|
+
|
|
347
|
+
#### getMetrics()
|
|
348
|
+
|
|
349
|
+
Get performance metrics.
|
|
350
|
+
|
|
351
|
+
```javascript
|
|
352
|
+
engine.getMetrics()
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Returns:** Object
|
|
356
|
+
```javascript
|
|
357
|
+
{
|
|
358
|
+
runs: number, // Total runs
|
|
359
|
+
totalTime: number, // Total processing time
|
|
360
|
+
avgTime: number, // Average per run
|
|
361
|
+
avgEntropy: number, // Average final entropy
|
|
362
|
+
avgSteps: number, // Average steps per run
|
|
363
|
+
transformCounts: {}, // Usage per transform
|
|
364
|
+
cacheHits: number, // Cache hit count
|
|
365
|
+
cacheMisses: number // Cache miss count
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
#### resetMetrics()
|
|
372
|
+
|
|
373
|
+
Reset all metrics.
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
engine.resetMetrics()
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Returns:** void
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
## Factory Functions
|
|
384
|
+
|
|
385
|
+
### createEngine(type, config)
|
|
386
|
+
|
|
387
|
+
Create engine with specified backend.
|
|
388
|
+
|
|
389
|
+
```javascript
|
|
390
|
+
const { createEngine } = require('./modular');
|
|
391
|
+
|
|
392
|
+
const engine = createEngine(type, config);
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**Parameters:**
|
|
396
|
+
- `type` (string): Backend type ('semantic', 'cryptographic', 'scientific')
|
|
397
|
+
- `config` (Object): Configuration object
|
|
398
|
+
|
|
399
|
+
**Returns:** AlephEngine
|
|
400
|
+
|
|
401
|
+
**Example:**
|
|
402
|
+
```javascript
|
|
403
|
+
const semanticEngine = createEngine('semantic', {
|
|
404
|
+
vocabulary: { ... },
|
|
405
|
+
ontology: { ... },
|
|
406
|
+
oscillatorCount: 16
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
const cryptoEngine = createEngine('cryptographic', {
|
|
410
|
+
hashRounds: 1000
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const scienceEngine = createEngine('scientific', {
|
|
414
|
+
dimension: 16
|
|
415
|
+
});
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
### createEngineWithBackend(backend, config)
|
|
421
|
+
|
|
422
|
+
Create engine with pre-built backend.
|
|
423
|
+
|
|
424
|
+
```javascript
|
|
425
|
+
const { createEngineWithBackend, SemanticBackend } = require('./modular');
|
|
426
|
+
|
|
427
|
+
const backend = new SemanticBackend(fullConfig);
|
|
428
|
+
const engine = createEngineWithBackend(backend, {
|
|
429
|
+
coupling: 0.2
|
|
430
|
+
});
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
**Parameters:**
|
|
434
|
+
- `backend` (BackendInterface): Backend instance
|
|
435
|
+
- `config` (Object): Engine configuration
|
|
436
|
+
|
|
437
|
+
**Returns:** AlephEngine
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## Configuration Reference
|
|
442
|
+
|
|
443
|
+
### Full Configuration Object
|
|
444
|
+
|
|
445
|
+
```javascript
|
|
446
|
+
const fullConfig = {
|
|
447
|
+
// Backend selection
|
|
448
|
+
backend: 'semantic', // or 'cryptographic', 'scientific'
|
|
449
|
+
|
|
450
|
+
// State dimension
|
|
451
|
+
dimension: 16,
|
|
452
|
+
|
|
453
|
+
// Semantic backend options
|
|
454
|
+
vocabulary: {
|
|
455
|
+
'love': [2, 3, 5],
|
|
456
|
+
'truth': [7, 11, 13]
|
|
457
|
+
// ...
|
|
458
|
+
},
|
|
459
|
+
ontology: {
|
|
460
|
+
2: 'existence',
|
|
461
|
+
3: 'unity',
|
|
462
|
+
5: 'life',
|
|
463
|
+
7: 'logos'
|
|
464
|
+
// ...
|
|
465
|
+
},
|
|
466
|
+
stopWords: ['the', 'a', 'an', 'is', 'are'],
|
|
467
|
+
|
|
468
|
+
// Transform configuration
|
|
469
|
+
transforms: [
|
|
470
|
+
{
|
|
471
|
+
n: 'simplify',
|
|
472
|
+
q: [2, 3],
|
|
473
|
+
r: [5],
|
|
474
|
+
priority: 10
|
|
475
|
+
}
|
|
476
|
+
],
|
|
477
|
+
|
|
478
|
+
// Engine dynamics
|
|
479
|
+
oscillatorCount: 16,
|
|
480
|
+
coupling: 0.1,
|
|
481
|
+
dt: 0.01,
|
|
482
|
+
|
|
483
|
+
// Convergence control
|
|
484
|
+
entropyThreshold: 0.1,
|
|
485
|
+
maxIterations: 100,
|
|
486
|
+
|
|
487
|
+
// Collapse behavior
|
|
488
|
+
collapseStrength: 0.8,
|
|
489
|
+
collapseOnConvergence: true,
|
|
490
|
+
|
|
491
|
+
// Caching
|
|
492
|
+
enableCache: true,
|
|
493
|
+
cacheSize: 1000,
|
|
494
|
+
|
|
495
|
+
// Debugging
|
|
496
|
+
debug: false,
|
|
497
|
+
trackMetrics: true
|
|
498
|
+
};
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
### Environment Variables
|
|
504
|
+
|
|
505
|
+
| Variable | Description | Default |
|
|
506
|
+
|----------|-------------|---------|
|
|
507
|
+
| `ALEPH_DIMENSION` | State dimension | 16 |
|
|
508
|
+
| `ALEPH_COUPLING` | Kuramoto coupling | 0.1 |
|
|
509
|
+
| `ALEPH_ENTROPY_THRESHOLD` | Target entropy | 0.1 |
|
|
510
|
+
| `ALEPH_DEBUG` | Enable debug output | false |
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
## Events
|
|
515
|
+
|
|
516
|
+
The engine emits events during processing (when configured with EventEmitter):
|
|
517
|
+
|
|
518
|
+
| Event | Data | Description |
|
|
519
|
+
|-------|------|-------------|
|
|
520
|
+
| `start` | `{ input }` | Processing started |
|
|
521
|
+
| `encoded` | `{ primes, state }` | Input encoded |
|
|
522
|
+
| `step` | `{ step, transform, entropy }` | Transform applied |
|
|
523
|
+
| `converged` | `{ steps, entropy }` | Entropy threshold reached |
|
|
524
|
+
| `complete` | `{ output, entropy, steps }` | Processing complete |
|
|
525
|
+
| `error` | `{ error }` | Error occurred |
|
|
526
|
+
|
|
527
|
+
**Example:**
|
|
528
|
+
```javascript
|
|
529
|
+
engine.on('step', (data) => {
|
|
530
|
+
console.log(`Step ${data.step}: ${data.transform} → entropy ${data.entropy}`);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
engine.on('converged', (data) => {
|
|
534
|
+
console.log(`Converged after ${data.steps} steps`);
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
## Error Handling
|
|
541
|
+
|
|
542
|
+
### Common Errors
|
|
543
|
+
|
|
544
|
+
| Error | Cause | Solution |
|
|
545
|
+
|-------|-------|----------|
|
|
546
|
+
| `UnknownBackendError` | Invalid backend type | Use registered backend |
|
|
547
|
+
| `EncodingError` | Input cannot be encoded | Check input format |
|
|
548
|
+
| `ConvergenceError` | Max iterations reached | Increase maxIterations |
|
|
549
|
+
| `DimensionMismatchError` | State dimensions differ | Ensure consistent dimension |
|
|
550
|
+
|
|
551
|
+
**Example:**
|
|
552
|
+
```javascript
|
|
553
|
+
try {
|
|
554
|
+
const result = engine.run(input);
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (error.name === 'ConvergenceError') {
|
|
557
|
+
console.log('Failed to converge, trying with more iterations');
|
|
558
|
+
engine.config.maxIterations *= 2;
|
|
559
|
+
const result = engine.run(input);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
---
|
|
565
|
+
|
|
566
|
+
## Integration Patterns
|
|
567
|
+
|
|
568
|
+
### Streaming Processing
|
|
569
|
+
|
|
570
|
+
```javascript
|
|
571
|
+
async function* streamProcess(inputs, engine) {
|
|
572
|
+
for (const input of inputs) {
|
|
573
|
+
const result = engine.run(input);
|
|
574
|
+
yield result;
|
|
575
|
+
|
|
576
|
+
// Allow oscillators to influence next input
|
|
577
|
+
await new Promise(r => setTimeout(r, 10));
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Usage
|
|
582
|
+
for await (const result of streamProcess(inputs, engine)) {
|
|
583
|
+
console.log(result.output);
|
|
584
|
+
}
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
### Parallel Engines
|
|
588
|
+
|
|
589
|
+
```javascript
|
|
590
|
+
const engines = [
|
|
591
|
+
createEngine('semantic', config),
|
|
592
|
+
createEngine('semantic', config),
|
|
593
|
+
createEngine('semantic', config)
|
|
594
|
+
];
|
|
595
|
+
|
|
596
|
+
async function parallelProcess(inputs) {
|
|
597
|
+
const chunks = chunkArray(inputs, engines.length);
|
|
598
|
+
|
|
599
|
+
const results = await Promise.all(
|
|
600
|
+
chunks.map((chunk, i) =>
|
|
601
|
+
Promise.resolve(engines[i].runBatch(chunk))
|
|
602
|
+
)
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
return results.flat();
|
|
606
|
+
}
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
### Persistent State
|
|
610
|
+
|
|
611
|
+
```javascript
|
|
612
|
+
// Save engine state
|
|
613
|
+
function saveState(engine) {
|
|
614
|
+
return {
|
|
615
|
+
field: engine.getFieldState().components,
|
|
616
|
+
oscillators: engine.oscillators.map(o => ({
|
|
617
|
+
phase: o.phase,
|
|
618
|
+
amplitude: o.amplitude,
|
|
619
|
+
frequency: o.frequency
|
|
620
|
+
}))
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// Restore engine state
|
|
625
|
+
function restoreState(engine, saved) {
|
|
626
|
+
engine.field = new SedenionState(saved.field);
|
|
627
|
+
saved.oscillators.forEach((o, i) => {
|
|
628
|
+
engine.oscillators[i].phase = o.phase;
|
|
629
|
+
engine.oscillators[i].amplitude = o.amplitude;
|
|
630
|
+
engine.oscillators[i].frequency = o.frequency;
|
|
631
|
+
});
|
|
632
|
+
}
|