@aleph-ai/tinyaleph 1.1.0 → 1.2.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 +230 -2
- package/core/entanglement.js +712 -0
- package/core/events.js +907 -0
- package/core/hypercomplex.js +500 -0
- package/core/index.js +46 -0
- package/core/rformer-layers.js +811 -0
- package/docs/reference/01-core.md +515 -1
- package/docs/reference/02-physics.md +186 -1
- package/package.json +1 -1
- package/physics/index.js +62 -0
- package/physics/kuramoto-coupled-ladder.js +603 -0
- package/physics/primeon_z_ladder_multi.js +669 -0
- package/physics/primeon_z_ladder_u.js +493 -0
- package/physics/stochastic-kuramoto.js +566 -0
|
@@ -692,4 +692,518 @@ const QUATERNION_DIMENSION = 4;
|
|
|
692
692
|
### EPSILON
|
|
693
693
|
|
|
694
694
|
```javascript
|
|
695
|
-
const EPSILON = 1e-10; // Floating point comparison threshold
|
|
695
|
+
const EPSILON = 1e-10; // Floating point comparison threshold
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
---
|
|
699
|
+
|
|
700
|
+
## Hypercomplex Extensions
|
|
701
|
+
|
|
702
|
+
Additional methods added to the Hypercomplex class for advanced algebra.
|
|
703
|
+
|
|
704
|
+
### Exponential and Logarithm
|
|
705
|
+
|
|
706
|
+
#### exp()
|
|
707
|
+
|
|
708
|
+
Compute the hypercomplex exponential.
|
|
709
|
+
|
|
710
|
+
```javascript
|
|
711
|
+
state.exp()
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
**Returns:** Hypercomplex - e^q
|
|
715
|
+
|
|
716
|
+
**Notes:**
|
|
717
|
+
- Uses generalized Euler formula: e^q = e^a(cos|v| + v̂·sin|v|)
|
|
718
|
+
- Where a is scalar part, v is vector part
|
|
719
|
+
|
|
720
|
+
**Example:**
|
|
721
|
+
```javascript
|
|
722
|
+
const q = Hypercomplex.fromArray([1, 0.5, 0, 0]);
|
|
723
|
+
const expQ = q.exp();
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
#### log()
|
|
727
|
+
|
|
728
|
+
Compute the hypercomplex logarithm.
|
|
729
|
+
|
|
730
|
+
```javascript
|
|
731
|
+
state.log()
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
**Returns:** Hypercomplex - log(q)
|
|
735
|
+
|
|
736
|
+
**Notes:**
|
|
737
|
+
- log(q) = log|q| + v̂·arccos(a/|q|)
|
|
738
|
+
- Inverse of exp()
|
|
739
|
+
|
|
740
|
+
---
|
|
741
|
+
|
|
742
|
+
### Power Operations
|
|
743
|
+
|
|
744
|
+
#### pow(n)
|
|
745
|
+
|
|
746
|
+
Raise to a power using exp/log.
|
|
747
|
+
|
|
748
|
+
```javascript
|
|
749
|
+
state.pow(n)
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
**Parameters:**
|
|
753
|
+
- `n` (number): Exponent (integer or fractional)
|
|
754
|
+
|
|
755
|
+
**Returns:** Hypercomplex - q^n
|
|
756
|
+
|
|
757
|
+
#### powInt(n)
|
|
758
|
+
|
|
759
|
+
Efficient integer power by repeated multiplication.
|
|
760
|
+
|
|
761
|
+
```javascript
|
|
762
|
+
state.powInt(n)
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
**Parameters:**
|
|
766
|
+
- `n` (number): Integer exponent
|
|
767
|
+
|
|
768
|
+
**Returns:** Hypercomplex - q^n
|
|
769
|
+
|
|
770
|
+
---
|
|
771
|
+
|
|
772
|
+
### Interpolation
|
|
773
|
+
|
|
774
|
+
#### slerp(other, t)
|
|
775
|
+
|
|
776
|
+
Spherical linear interpolation.
|
|
777
|
+
|
|
778
|
+
```javascript
|
|
779
|
+
state.slerp(other, t)
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
**Parameters:**
|
|
783
|
+
- `other` (Hypercomplex): Target state
|
|
784
|
+
- `t` (number): Parameter in [0, 1]
|
|
785
|
+
|
|
786
|
+
**Returns:** Hypercomplex - Interpolated state
|
|
787
|
+
|
|
788
|
+
**Example:**
|
|
789
|
+
```javascript
|
|
790
|
+
const q1 = Hypercomplex.fromAxisAngle(4, [1,0,0], 0);
|
|
791
|
+
const q2 = Hypercomplex.fromAxisAngle(4, [0,0,1], Math.PI/2);
|
|
792
|
+
|
|
793
|
+
for (let t = 0; t <= 1; t += 0.1) {
|
|
794
|
+
const interpolated = q1.slerp(q2, t);
|
|
795
|
+
}
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
#### squad(q1, q2, q3, t)
|
|
799
|
+
|
|
800
|
+
Spherical cubic interpolation for smooth paths.
|
|
801
|
+
|
|
802
|
+
```javascript
|
|
803
|
+
state.squad(q1, q2, q3, t)
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
**Parameters:**
|
|
807
|
+
- `q1, q2, q3` (Hypercomplex): Control points
|
|
808
|
+
- `t` (number): Parameter in [0, 1]
|
|
809
|
+
|
|
810
|
+
**Returns:** Hypercomplex - Smoothly interpolated state
|
|
811
|
+
|
|
812
|
+
---
|
|
813
|
+
|
|
814
|
+
### Rotation Operations
|
|
815
|
+
|
|
816
|
+
#### sandwich(v)
|
|
817
|
+
|
|
818
|
+
Apply rotation to a vector: q·v·q*
|
|
819
|
+
|
|
820
|
+
```javascript
|
|
821
|
+
state.sandwich(v)
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
**Parameters:**
|
|
825
|
+
- `v` (Hypercomplex): Vector to rotate
|
|
826
|
+
|
|
827
|
+
**Returns:** Hypercomplex - Rotated vector
|
|
828
|
+
|
|
829
|
+
#### rotateVector(v)
|
|
830
|
+
|
|
831
|
+
Rotate a 3D vector using quaternion.
|
|
832
|
+
|
|
833
|
+
```javascript
|
|
834
|
+
state.rotateVector(v)
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
**Parameters:**
|
|
838
|
+
- `v` (Array<number>): 3D vector [x, y, z]
|
|
839
|
+
|
|
840
|
+
**Returns:** Array<number> - Rotated vector
|
|
841
|
+
|
|
842
|
+
#### fromAxisAngle(dim, axis, angle)
|
|
843
|
+
|
|
844
|
+
Create rotation from axis and angle.
|
|
845
|
+
|
|
846
|
+
```javascript
|
|
847
|
+
Hypercomplex.fromAxisAngle(dim, axis, angle)
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
**Parameters:**
|
|
851
|
+
- `dim` (number): Dimension (4 for quaternion)
|
|
852
|
+
- `axis` (Array<number>): Rotation axis [x, y, z]
|
|
853
|
+
- `angle` (number): Rotation angle in radians
|
|
854
|
+
|
|
855
|
+
**Returns:** Hypercomplex - Unit quaternion
|
|
856
|
+
|
|
857
|
+
#### toAxisAngle()
|
|
858
|
+
|
|
859
|
+
Extract axis and angle from rotation.
|
|
860
|
+
|
|
861
|
+
```javascript
|
|
862
|
+
state.toAxisAngle()
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
**Returns:** Object - `{ axis: [x,y,z], angle: number }`
|
|
866
|
+
|
|
867
|
+
---
|
|
868
|
+
|
|
869
|
+
### Helper Methods
|
|
870
|
+
|
|
871
|
+
#### scalar()
|
|
872
|
+
|
|
873
|
+
Get scalar (real) part.
|
|
874
|
+
|
|
875
|
+
```javascript
|
|
876
|
+
state.scalar()
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
**Returns:** number - c[0]
|
|
880
|
+
|
|
881
|
+
#### vector()
|
|
882
|
+
|
|
883
|
+
Get vector (imaginary) part.
|
|
884
|
+
|
|
885
|
+
```javascript
|
|
886
|
+
state.vector()
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
**Returns:** Hypercomplex - State with c[0] = 0
|
|
890
|
+
|
|
891
|
+
#### isUnit(epsilon)
|
|
892
|
+
|
|
893
|
+
Check if unit norm.
|
|
894
|
+
|
|
895
|
+
```javascript
|
|
896
|
+
state.isUnit(epsilon)
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
**Returns:** boolean - |norm - 1| < epsilon
|
|
900
|
+
|
|
901
|
+
---
|
|
902
|
+
|
|
903
|
+
## Prime Entanglement Graph (`core/entanglement.js`)
|
|
904
|
+
|
|
905
|
+
Track prime relationships from co-occurrence and resonance.
|
|
906
|
+
|
|
907
|
+
### PrimeEntanglementGraph
|
|
908
|
+
|
|
909
|
+
```javascript
|
|
910
|
+
new PrimeEntanglementGraph(primes, options)
|
|
911
|
+
```
|
|
912
|
+
|
|
913
|
+
**Parameters:**
|
|
914
|
+
- `primes` (number | Array): Number of primes or explicit list
|
|
915
|
+
- `options` (Object):
|
|
916
|
+
- `decayRate` (number): Edge weight decay (default 0.01)
|
|
917
|
+
- `learningRate` (number): Weight update rate (default 0.1)
|
|
918
|
+
- `pruneThreshold` (number): Minimum edge weight (default 0.01)
|
|
919
|
+
|
|
920
|
+
**Example:**
|
|
921
|
+
```javascript
|
|
922
|
+
const graph = new PrimeEntanglementGraph([2, 3, 5, 7, 11]);
|
|
923
|
+
|
|
924
|
+
// Record co-occurrence
|
|
925
|
+
graph.observe([2, 3], [5, 7], 0.8);
|
|
926
|
+
|
|
927
|
+
// Query relationships
|
|
928
|
+
const neighbors = graph.neighbors(7, 2);
|
|
929
|
+
const path = graph.shortestPath(2, 11);
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
#### Methods
|
|
933
|
+
|
|
934
|
+
| Method | Description |
|
|
935
|
+
|--------|-------------|
|
|
936
|
+
| `observe(from, to, strength)` | Record co-occurrence |
|
|
937
|
+
| `neighbors(prime, depth)` | Get k-hop neighborhood |
|
|
938
|
+
| `shortestPath(from, to)` | Find shortest path |
|
|
939
|
+
| `clusteringCoefficient(prime)` | Get local clustering |
|
|
940
|
+
| `decay(factor)` | Apply decay to all edges |
|
|
941
|
+
| `prune(threshold)` | Remove weak edges |
|
|
942
|
+
| `toAdjacencyMatrix(primeList)` | Convert to matrix |
|
|
943
|
+
| `toNetworkKuramoto(options)` | Create Kuramoto model |
|
|
944
|
+
| `stats()` | Get graph statistics |
|
|
945
|
+
|
|
946
|
+
---
|
|
947
|
+
|
|
948
|
+
## Event System (`core/events.js`)
|
|
949
|
+
|
|
950
|
+
Event-driven monitoring for real-time applications.
|
|
951
|
+
|
|
952
|
+
### AlephEventEmitter
|
|
953
|
+
|
|
954
|
+
EventEmitter compatible with Node.js pattern.
|
|
955
|
+
|
|
956
|
+
```javascript
|
|
957
|
+
new AlephEventEmitter(options)
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
**Parameters:**
|
|
961
|
+
- `options` (Object):
|
|
962
|
+
- `maxHistory` (number): Event history size (default 1000)
|
|
963
|
+
|
|
964
|
+
**Methods:**
|
|
965
|
+
|
|
966
|
+
| Method | Description |
|
|
967
|
+
|--------|-------------|
|
|
968
|
+
| `on(event, callback)` | Add listener |
|
|
969
|
+
| `once(event, callback)` | Add one-time listener |
|
|
970
|
+
| `off(event, callback)` | Remove listener |
|
|
971
|
+
| `emit(event, data)` | Emit event |
|
|
972
|
+
| `throttle(event, interval)` | Throttle event |
|
|
973
|
+
| `pause()` / `resume()` | Pause/resume emissions |
|
|
974
|
+
| `waitFor(event, timeout)` | Promise for next event |
|
|
975
|
+
| `getHistory(event, limit)` | Get event history |
|
|
976
|
+
|
|
977
|
+
**Example:**
|
|
978
|
+
```javascript
|
|
979
|
+
const emitter = new AlephEventEmitter();
|
|
980
|
+
|
|
981
|
+
emitter.throttle('tick', 100); // Max 10/sec
|
|
982
|
+
|
|
983
|
+
emitter.on('collapse', ({ from, to }) => {
|
|
984
|
+
console.log(`Collapsed: ${from} → ${to}`);
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
const data = await emitter.waitFor('ready', 5000);
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
---
|
|
991
|
+
|
|
992
|
+
### AlephMonitor
|
|
993
|
+
|
|
994
|
+
High-level monitoring wrapper for AlephEngine.
|
|
995
|
+
|
|
996
|
+
```javascript
|
|
997
|
+
new AlephMonitor(engine, options)
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
**Parameters:**
|
|
1001
|
+
- `engine` (AlephEngine): Engine to monitor
|
|
1002
|
+
- `options` (Object):
|
|
1003
|
+
- `entropyLow` (number): Low entropy threshold
|
|
1004
|
+
- `entropyHigh` (number): High entropy threshold
|
|
1005
|
+
- `syncThreshold` (number): Sync detection threshold
|
|
1006
|
+
|
|
1007
|
+
**Events emitted:**
|
|
1008
|
+
- `tick`: Each time step
|
|
1009
|
+
- `collapse`: State collapse
|
|
1010
|
+
- `entropy:low` / `entropy:high`: Threshold crossings
|
|
1011
|
+
- `sync`: Synchronization detected
|
|
1012
|
+
- `coherence:high`: High coherence detected
|
|
1013
|
+
|
|
1014
|
+
---
|
|
1015
|
+
|
|
1016
|
+
### EvolutionStream
|
|
1017
|
+
|
|
1018
|
+
Async iterator for engine evolution.
|
|
1019
|
+
|
|
1020
|
+
```javascript
|
|
1021
|
+
new EvolutionStream(engine, options)
|
|
1022
|
+
// or
|
|
1023
|
+
EvolutionStream.fromEvolvable(evolvable, options)
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
**Parameters:**
|
|
1027
|
+
- `engine` (Object): Engine or evolvable object
|
|
1028
|
+
- `options` (Object):
|
|
1029
|
+
- `dt` (number): Time step (default 0.01)
|
|
1030
|
+
- `maxSteps` (number): Maximum steps
|
|
1031
|
+
- `stopCondition` (Function): Stop predicate
|
|
1032
|
+
|
|
1033
|
+
**Methods:**
|
|
1034
|
+
|
|
1035
|
+
| Method | Description |
|
|
1036
|
+
|--------|-------------|
|
|
1037
|
+
| `take(n)` | Take first n items |
|
|
1038
|
+
| `filter(predicate)` | Filter stream |
|
|
1039
|
+
| `map(transform)` | Transform stream |
|
|
1040
|
+
| `batch(size)` | Group into batches |
|
|
1041
|
+
| `reduce(fn, init)` | Reduce to value |
|
|
1042
|
+
| `collect(max)` | Collect to array |
|
|
1043
|
+
|
|
1044
|
+
**Example:**
|
|
1045
|
+
```javascript
|
|
1046
|
+
const stream = EvolutionStream.fromEvolvable(kuramoto);
|
|
1047
|
+
|
|
1048
|
+
for await (const state of stream.take(100)) {
|
|
1049
|
+
console.log(state.orderParameter);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// With operators
|
|
1053
|
+
const result = await stream
|
|
1054
|
+
.filter(s => s.entropy < 2.0)
|
|
1055
|
+
.map(s => s.orderParameter)
|
|
1056
|
+
.take(50)
|
|
1057
|
+
.collect();
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
---
|
|
1061
|
+
|
|
1062
|
+
## ResoFormer Layers (`core/rformer-layers.js`)
|
|
1063
|
+
|
|
1064
|
+
Complete transformer architecture for prime-indexed states.
|
|
1065
|
+
|
|
1066
|
+
### ResonantMultiHeadAttention
|
|
1067
|
+
|
|
1068
|
+
Multi-head attention with different resonance weights per head.
|
|
1069
|
+
|
|
1070
|
+
```javascript
|
|
1071
|
+
new ResonantMultiHeadAttention(config)
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
**Parameters:**
|
|
1075
|
+
- `config` (Object):
|
|
1076
|
+
- `numHeads` (number): Number of heads (default 8)
|
|
1077
|
+
- `numPrimes` (number): Prime vocabulary size (default 4096)
|
|
1078
|
+
- `activeK` (number): Sparsity per state (default 32)
|
|
1079
|
+
- `temperature` (number): Softmax temperature (default 1.0)
|
|
1080
|
+
|
|
1081
|
+
**Example:**
|
|
1082
|
+
```javascript
|
|
1083
|
+
const attention = new ResonantMultiHeadAttention({ numHeads: 8 });
|
|
1084
|
+
|
|
1085
|
+
const result = attention.forward(query, keys, values);
|
|
1086
|
+
console.log(result.result); // Combined output
|
|
1087
|
+
console.log(result.headOutputs); // Per-head outputs
|
|
1088
|
+
console.log(result.attentionWeights); // Attention weights
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
---
|
|
1092
|
+
|
|
1093
|
+
### PrimeFFN
|
|
1094
|
+
|
|
1095
|
+
Prime-indexed feed-forward network.
|
|
1096
|
+
|
|
1097
|
+
```javascript
|
|
1098
|
+
new PrimeFFN(config)
|
|
1099
|
+
```
|
|
1100
|
+
|
|
1101
|
+
**Parameters:**
|
|
1102
|
+
- `config` (Object):
|
|
1103
|
+
- `hiddenDim` (number): Hidden dimension (default 256)
|
|
1104
|
+
- `activation` (string): 'relu', 'gelu', 'swish', 'tanh'
|
|
1105
|
+
- `dropout` (number): Dropout probability
|
|
1106
|
+
|
|
1107
|
+
---
|
|
1108
|
+
|
|
1109
|
+
### PrimeLayerNorm
|
|
1110
|
+
|
|
1111
|
+
Layer normalization preserving prime structure.
|
|
1112
|
+
|
|
1113
|
+
```javascript
|
|
1114
|
+
new PrimeLayerNorm(config)
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
**Parameters:**
|
|
1118
|
+
- `config` (Object):
|
|
1119
|
+
- `eps` (number): Epsilon for stability
|
|
1120
|
+
- `gamma` (number): Scale parameter
|
|
1121
|
+
- `beta` (number): Shift parameter
|
|
1122
|
+
|
|
1123
|
+
---
|
|
1124
|
+
|
|
1125
|
+
### PositionalPrimeEncoding
|
|
1126
|
+
|
|
1127
|
+
Position encoding using prime phases.
|
|
1128
|
+
|
|
1129
|
+
```javascript
|
|
1130
|
+
new PositionalPrimeEncoding(config)
|
|
1131
|
+
```
|
|
1132
|
+
|
|
1133
|
+
**Parameters:**
|
|
1134
|
+
- `config` (Object):
|
|
1135
|
+
- `maxLength` (number): Maximum sequence length
|
|
1136
|
+
- `type` (string): 'sinusoidal', 'prime', or 'golden'
|
|
1137
|
+
|
|
1138
|
+
**Methods:**
|
|
1139
|
+
- `getEncoding(pos)`: Get encoding for position
|
|
1140
|
+
- `encode(state, pos)`: Add encoding to state
|
|
1141
|
+
- `encodeSequence(states)`: Encode entire sequence
|
|
1142
|
+
|
|
1143
|
+
---
|
|
1144
|
+
|
|
1145
|
+
### ResoFormerBlock
|
|
1146
|
+
|
|
1147
|
+
Complete transformer block.
|
|
1148
|
+
|
|
1149
|
+
```javascript
|
|
1150
|
+
new ResoFormerBlock(config)
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
**Parameters:**
|
|
1154
|
+
- `config` (Object):
|
|
1155
|
+
- `numHeads` (number): Attention heads
|
|
1156
|
+
- `hiddenDim` (number): FFN dimension
|
|
1157
|
+
- `preNorm` (boolean): Pre-norm style (default true)
|
|
1158
|
+
- `dropout` (number): Dropout rate
|
|
1159
|
+
|
|
1160
|
+
**Example:**
|
|
1161
|
+
```javascript
|
|
1162
|
+
const block = new ResoFormerBlock({
|
|
1163
|
+
numHeads: 8,
|
|
1164
|
+
hiddenDim: 256
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
const result = block.forward(input, context);
|
|
1168
|
+
```
|
|
1169
|
+
|
|
1170
|
+
---
|
|
1171
|
+
|
|
1172
|
+
### ResoFormer
|
|
1173
|
+
|
|
1174
|
+
Full multi-layer transformer model.
|
|
1175
|
+
|
|
1176
|
+
```javascript
|
|
1177
|
+
new ResoFormer(config)
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
**Parameters:**
|
|
1181
|
+
- `config` (Object):
|
|
1182
|
+
- `numLayers` (number): Number of blocks (default 6)
|
|
1183
|
+
- `numHeads` (number): Heads per block (default 8)
|
|
1184
|
+
- `hiddenDim` (number): FFN dimension (default 256)
|
|
1185
|
+
- `numPrimes` (number): Prime vocabulary (default 4096)
|
|
1186
|
+
- `activeK` (number): Sparsity parameter (default 32)
|
|
1187
|
+
- `usePositionalEncoding` (boolean): Add position (default true)
|
|
1188
|
+
|
|
1189
|
+
**Methods:**
|
|
1190
|
+
- `forward(input)`: Process input state(s)
|
|
1191
|
+
- `train(mode)` / `eval()`: Set training mode
|
|
1192
|
+
- `getParameterCount()`: Get parameter count
|
|
1193
|
+
|
|
1194
|
+
**Example:**
|
|
1195
|
+
```javascript
|
|
1196
|
+
const model = new ResoFormer({
|
|
1197
|
+
numLayers: 6,
|
|
1198
|
+
numHeads: 8,
|
|
1199
|
+
hiddenDim: 256
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
const sequence = [
|
|
1203
|
+
SparsePrimeState.fromPrimes([2, 3, 5]),
|
|
1204
|
+
SparsePrimeState.fromPrimes([7, 11, 13])
|
|
1205
|
+
];
|
|
1206
|
+
|
|
1207
|
+
const outputs = model.forward(sequence);
|
|
1208
|
+
console.log(outputs.output); // Final outputs
|
|
1209
|
+
console.log(outputs.layerOutputs); // Per-layer outputs
|
|
@@ -598,4 +598,189 @@ adaptiveStep(state, derivative, dt, tolerance)
|
|
|
598
598
|
**Returns:** Object - `{ state, dt, error }`
|
|
599
599
|
|
|
600
600
|
**Notes:**
|
|
601
|
-
- Automatically adjusts dt to maintain error below tolerance
|
|
601
|
+
- Automatically adjusts dt to maintain error below tolerance
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
## Stochastic Kuramoto (`physics/stochastic-kuramoto.js`)
|
|
606
|
+
|
|
607
|
+
Noise-robust synchronization models with Langevin dynamics.
|
|
608
|
+
|
|
609
|
+
### StochasticKuramoto
|
|
610
|
+
|
|
611
|
+
White noise Kuramoto model with Langevin dynamics.
|
|
612
|
+
|
|
613
|
+
```javascript
|
|
614
|
+
new StochasticKuramoto(frequencies, options)
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
**Parameters:**
|
|
618
|
+
- `frequencies` (Array<number>): Natural frequencies for oscillators
|
|
619
|
+
- `options` (Object):
|
|
620
|
+
- `coupling` (number): Coupling strength K (default 0.3)
|
|
621
|
+
- `noiseIntensity` (number): Noise intensity σ (default 0.1)
|
|
622
|
+
- `noiseType` (string): 'white' or 'colored' (default 'white')
|
|
623
|
+
|
|
624
|
+
**Example:**
|
|
625
|
+
```javascript
|
|
626
|
+
const model = new StochasticKuramoto([1.0, 1.1, 0.9], {
|
|
627
|
+
coupling: 0.5,
|
|
628
|
+
noiseIntensity: 0.1
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
model.evolve(100, 0.01);
|
|
632
|
+
console.log(model.orderParameter());
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
#### Methods
|
|
636
|
+
|
|
637
|
+
| Method | Description |
|
|
638
|
+
|--------|-------------|
|
|
639
|
+
| `evolve(steps, dt)` | Evolve system for specified steps |
|
|
640
|
+
| `orderParameter()` | Get current order parameter |
|
|
641
|
+
| `orderParameterWithUncertainty(samples, dt)` | Get order parameter with statistics |
|
|
642
|
+
| `detectNoiseInducedSync()` | Check for noise-induced synchronization |
|
|
643
|
+
|
|
644
|
+
---
|
|
645
|
+
|
|
646
|
+
### ColoredNoiseKuramoto
|
|
647
|
+
|
|
648
|
+
Ornstein-Uhlenbeck colored noise model.
|
|
649
|
+
|
|
650
|
+
```javascript
|
|
651
|
+
new ColoredNoiseKuramoto(frequencies, options)
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
**Parameters:**
|
|
655
|
+
- `frequencies` (Array<number>): Natural frequencies
|
|
656
|
+
- `options` (Object):
|
|
657
|
+
- `correlationTime` (number): Noise correlation time τ (default 1.0)
|
|
658
|
+
- `noiseIntensity` (number): Noise intensity σ (default 0.1)
|
|
659
|
+
- `coupling` (number): Coupling strength K (default 0.3)
|
|
660
|
+
|
|
661
|
+
**Example:**
|
|
662
|
+
```javascript
|
|
663
|
+
const colored = new ColoredNoiseKuramoto([1.0, 1.1], {
|
|
664
|
+
correlationTime: 2.0,
|
|
665
|
+
noiseIntensity: 0.1
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
console.log('Stationary variance:', colored.getStationaryVariance());
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
---
|
|
672
|
+
|
|
673
|
+
### ThermalKuramoto
|
|
674
|
+
|
|
675
|
+
Temperature-dependent coupling model.
|
|
676
|
+
|
|
677
|
+
```javascript
|
|
678
|
+
new ThermalKuramoto(frequencies, options)
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
**Parameters:**
|
|
682
|
+
- `frequencies` (Array<number>): Natural frequencies
|
|
683
|
+
- `options` (Object):
|
|
684
|
+
- `temperature` (number): Initial temperature T (default 1.0)
|
|
685
|
+
- `coupling` (number): Base coupling strength K (default 0.3)
|
|
686
|
+
|
|
687
|
+
**Methods:**
|
|
688
|
+
|
|
689
|
+
| Method | Description |
|
|
690
|
+
|--------|-------------|
|
|
691
|
+
| `setTemperature(T)` | Update temperature and noise |
|
|
692
|
+
| `temperatureSweep(Tmin, Tmax, steps)` | Sweep temperature range |
|
|
693
|
+
| `estimateCriticalTemperature()` | Estimate phase transition temperature |
|
|
694
|
+
|
|
695
|
+
**Example:**
|
|
696
|
+
```javascript
|
|
697
|
+
const thermal = new ThermalKuramoto([1.0, 1.1, 0.9], { temperature: 2.0 });
|
|
698
|
+
thermal.setTemperature(4.0);
|
|
699
|
+
const Tc = thermal.estimateCriticalTemperature();
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
## Multi-Z Primeon Ladder (`physics/primeon_z_ladder_multi.js`)
|
|
705
|
+
|
|
706
|
+
Hierarchical memory with multiple Z channels.
|
|
707
|
+
|
|
708
|
+
### PrimeonZLadderMulti
|
|
709
|
+
|
|
710
|
+
Multi-channel Z-sector ladder for hierarchical memory.
|
|
711
|
+
|
|
712
|
+
```javascript
|
|
713
|
+
new PrimeonZLadderMulti(config)
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
**Parameters:**
|
|
717
|
+
- `config` (Object):
|
|
718
|
+
- `N` (number): Number of rungs
|
|
719
|
+
- `zChannels` (Array): Channel configurations
|
|
720
|
+
- `name` (string): Channel name
|
|
721
|
+
- `dz` (number): Z sector size (default 1)
|
|
722
|
+
- `leak` (number): Leak rate (default 0.1)
|
|
723
|
+
- `decay` (number): Decay rate (default 0.01)
|
|
724
|
+
- `J` (number): Hopping amplitude (default 0.25)
|
|
725
|
+
- `Jt` (Function): Time-dependent J function (optional)
|
|
726
|
+
- `crossCoupling` (number): Cross-channel coupling (default 0.01)
|
|
727
|
+
|
|
728
|
+
**Default Channels:**
|
|
729
|
+
- `fast`: High leak (0.2), working memory
|
|
730
|
+
- `slow`: Low leak (0.01), long-term memory
|
|
731
|
+
- `permanent`: No leak (0.0), persistent storage
|
|
732
|
+
|
|
733
|
+
**Example:**
|
|
734
|
+
```javascript
|
|
735
|
+
const ladder = new PrimeonZLadderMulti({
|
|
736
|
+
N: 32,
|
|
737
|
+
zChannels: [
|
|
738
|
+
{ name: 'fast', leak: 0.2, decay: 0.1 },
|
|
739
|
+
{ name: 'slow', leak: 0.01, decay: 0.001 },
|
|
740
|
+
{ name: 'permanent', leak: 0.0, decay: 0.0 }
|
|
741
|
+
]
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
ladder.exciteRung(0);
|
|
745
|
+
ladder.run(100, 0.01);
|
|
746
|
+
|
|
747
|
+
const metrics = ladder.channelMetrics();
|
|
748
|
+
console.log('Fast entropy:', metrics.fast.entropy);
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
#### Methods
|
|
752
|
+
|
|
753
|
+
| Method | Description |
|
|
754
|
+
|--------|-------------|
|
|
755
|
+
| `exciteRung(n, amplitude)` | Excite rung n |
|
|
756
|
+
| `exciteRungs(rungs, amplitude)` | Excite multiple rungs |
|
|
757
|
+
| `step(t)` | Advance by one time step |
|
|
758
|
+
| `run(steps, dt)` | Run for multiple steps |
|
|
759
|
+
| `rungProbabilities()` | Get probability distribution |
|
|
760
|
+
| `channelMetrics()` | Get per-channel metrics |
|
|
761
|
+
| `entanglementEntropy()` | Compute entanglement entropy |
|
|
762
|
+
| `measure()` | Perform measurement/collapse |
|
|
763
|
+
| `gaussianPulse(center, width, amp)` | Apply Gaussian pulse |
|
|
764
|
+
| `piPulse(target)` | Apply π-pulse to target rung |
|
|
765
|
+
|
|
766
|
+
### createAdiabaticSchedule
|
|
767
|
+
|
|
768
|
+
Create time-dependent parameter schedules.
|
|
769
|
+
|
|
770
|
+
```javascript
|
|
771
|
+
createAdiabaticSchedule(startValue, endValue, duration, type)
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
**Parameters:**
|
|
775
|
+
- `startValue` (number): Initial value
|
|
776
|
+
- `endValue` (number): Final value
|
|
777
|
+
- `duration` (number): Schedule duration
|
|
778
|
+
- `type` (string): 'linear' or 'sinusoidal' (default 'linear')
|
|
779
|
+
|
|
780
|
+
**Returns:** Function - `t => value`
|
|
781
|
+
|
|
782
|
+
**Example:**
|
|
783
|
+
```javascript
|
|
784
|
+
const Jt = createAdiabaticSchedule(0.1, 0.5, 100, 'sinusoidal');
|
|
785
|
+
const ladder = new PrimeonZLadderMulti({ N: 16, Jt });
|
|
786
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-ai/tinyaleph",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Prime-resonant semantic computing framework - hypercomplex algebra, oscillator dynamics, and entropy-minimizing reasoning",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|